2016年6月21日 星期二

String.IsNullOrEmpty in JavaScript

Starting with:
return (!value || value == undefined || value == "" || value.length == 0);
Looking at the last condition, if value == "", it's length MUST be 0. Therefore drop it:
return (!value || value == undefined || value == "");
But wait! In JS, an empty string is false. Therefore, drop value == "":
return (!value || value == undefined);
And !undefined is true, so that check isn't needed. So we have:
return (!value);
And we don't need parentheses:
return !value
Q.E.D.


http://codereview.stackexchange.com/questions/5572/string-isnullorempty-in-javascript

2016年6月2日 星期四

[jQuery]add dynamic rows



Ref:
http://stackoverflow.com/questions/2145012/adding-rows-dynamically-with-jquery

http://ssiddique.info/different-ways-to-add-row-to-a-table-using-jquery.html

http://stackoverflow.com/questions/16183231/jquery-append-and-remove-dynamic-table-row

2016年5月27日 星期五

[MS SQL] SPRING JDBC


 -- 使用JDBC連線
http://www.codedata.com.tw/java/java-tutorial-the-3rd-class-2-spring-jdbc/

JDBCDataSource dataSource = new JDBCDataSource();
dataSource.setUrl("jdbc:hsqldb:file:src/main/resources/db/dvd_library");
dataSource.setUser("codedata");
dataSource.setPassword("123456");


-- 呼叫 PROCEDURE
 http://stackoverflow.com/questions/9361538/spring-jdbc-template-for-calling-stored-procedures


SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
    .withSchemaName(schema)
    .withCatalogName(package)
    .withProcedureName(procedure)();
...
jdbcCall.addDeclaredParameter(new SqlParameter(paramName, OracleTypes.NUMBER));
...
jdbcCall.execute(callParams);




-- procedure 回傳 temp table

http://stackoverflow.com/questions/1443663/how-to-return-temporary-table-from-stored-procedure

 -- The "called" SP
  declare
      @returnAsSelect bit = 0;

  if object_id('tempdb..#GetValuesOutputTable') is null
  begin
      set @returnAsSelect = 1;
      create table #GetValuesOutputTable(
         ...   
      );
  end

  -- populate the table

  if @returnAsSelect = 1
      select * from #GetValuesOutputTable;

2016年5月16日 星期一

[JAVA8] truncate java 8 LocalDateTime



LocalDateTime now =  LocalDateTime.now();
LocalDateTime roundFloor =  now.truncatedTo(ChronoUnit.MINUTES);
LocalDateTime roundCeiling =  now.truncatedTo(ChronoUnit.MINUTES).plusMinutes(1);
http://stackoverflow.com/questions/25552023/round-minutes-to-ceiling-using-java-8

2015年12月30日 星期三

[SQL] IN CLAUSE OVER 1000 ITEMS


1.使用union all
select * from table1 where ID in (1,2,3,4,...,1000)
union all
select * from table1 where ID in (1001,1002,...)

2.使用or
select * from table1 where ID in (1,2,3,4,...,1000) or 
ID in (1001,1002,...,2000)

3.使用兩個欄位in
select ... where ('bla', colX ) in (
        ('bla', 1),
        ('bla', 2),
        ('bla', 3),
        ('bla', 4),
             ...
        ('bla', 9999)
    ) ...

4.開table
select ... 
where id in (select userId 
             from temptable_with_2000_ids ) 

Ref:http://stackoverflow.com/questions/400255/how-to-put-more-than-1000-values-into-an-oracle-in-clause

2015年12月27日 星期日

[EXCEL]比對兩欄,是否有相同值







VLOOKUP(B2, $A$2:$A$7, 1, FALSE)
 以B2儲存格查詢$A$2:$A$7範圍中完全符合的值(FALSE),並傳回其第1欄的值


Ref: http://mark0120.blogspot.tw/2013/12/excel.html

2015年11月5日 星期四

[SQL]Inserting values into a table with '&'

如果要insert&符號時,用SQL Plus執行會停下來
可以用以下的方式insert &

create table test (name varchar2(10));
insert into test values ('&123');


 1.方式1,將define關掉
 set define off;
 insert into test values ('&123');


2.用ascii 取代(chr(38))
insert into test values (chr(38)||'123');