Changes between Initial Version and Version 1 of v6/pgsummary


Ignore:
Timestamp:
04/11/2012 04:35:54 PM (14 years ago)
Author:
chenchongqi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • v6/pgsummary

    v1 v1  
     1= Oracle 转 PG 汇总 = 
     2 
     3== 语法 == 
     4* rownum 转为 limit  
     5{{{ 
     6oracle: 
     7select title from sns_pclady.msg_message where rownum<=100; 
     8 
     9pg: 
     10select title from sns_pclady.msg_message limit 100; 
     11}}} 
     12* 别名要显式指定 
     13{{{ 
     14oracle: 
     15select count(*) from ( select * from  
     16(select * from sns_pclady.msg_message where receiver= 6499175  and  delbyreceiver=0  order by posttime desc) where rownum <=1000) where status=0; 
     17 
     18pg: 
     19select count(*) from ( select * from  
     20(select * from sns_pclady.msg_message where receiver= 6499175  and  delbyreceiver=0  order by posttime desc) a limit 1000) b where b.status=0; 
     21}}} 
     22* 外连接写法调整 
     23{{{ 
     24oracle: 
     25select a.field1, b.field2 from a, b where a.item_id = b.item_id(+) 
     26 
     27pg: 
     28select a.field1, b.field2 from a left outer join b on a.item_id = b.item_id 
     29}}} 
     30* sequence写法调整 
     31{{{ 
     32oracle: 
     33sequence_name.nextval 
     34 
     35pg: 
     36nextval('sequence_name')  
     37}}} 
     38* sysdate写法调整 
     39{{{ 
     40oracle: 
     41select sysdate from dual 
     42 
     43pg: 
     44select [db_sysdate] from dual 
     45}}} 
     46* decode写法调整 
     47{{{ 
     48oracle: 
     49decode(expr, search, expr[, search, expr...] [, default]) 
     50 
     51pg: 
     52CASE WHEN expr THEN expr [...] ELSE expr END 
     53CASE WHEN c1 = 1 THEN 'match' ELSE 'no match' END 
     54}}} 
     55* nvl写法调整 
     56{{{ 
     57oracle: 
     58NVL(hire_date, SYSDATE) 
     59 
     60pg: 
     61coalesce(expr1, expr2, expr3,....)  //这个是否可以代替decode? 
     62}}} 
     63* connect by 写法pg不支持 
     64{{{ 
     65oracle: 
     66pg: 
     67WITH RECURSIVE source (part_no) AS ( 
     68SELECT 2 
     69UNION ALL 
     70SELECT part.part_no 
     71FROM source JOIN part ON (source.part_no = part.parent_part_no) 
     72) 
     73SELECT * FROM source; 
     74}}} 
     75 
     76== 驱动 == 
     77* pg 里没有rollback 语句,不会自动rollback ,需要应用里触发异常。  
     78* 缺省返回的整型是Long 
     79{{{ 
     80oracle: 
     81BigDecimal count = (java.math.BigDecimal?)em.createNativeQuery("select count(*) from table").getSingleResult(); 
     82 
     83pg: 
     84Long count = (Long)em.createNativeQuery("select count(*) from table").getSingleResult(); 
     85}}}