oracle常用sql

1,保留两位小数

 

(1)ROUND(A/B,2):将结果四舍五入

 

 

(2)TRUNC(A/B,2):结果不四舍五入

 

 

(3)TO_CHAR(A/B,‘FM99990.99’):控制展示格式

带0:

 

不带0:

2,按月份分组

select to_char(exportDate,'yyyy-mm'),sum(amount) from table1

group by to_char(exportDate,'yyyy-mm')

order by to_char(exportDate,'yyyy-mm');

链接:https://www.cnblogs.com/ymj126/p/4501061.html

 

3,分区排序 row_number() rank() dense_rank()

--for update 和 for update nowait 的区别

for update:一直等待commit

for update nowait:会抛出异常:ORA-00054 资源正忙

 

 to_char(100.00, 'FM999,990.00')

FM999 其9代表:如果存在数字则显示数字,不存在则显示空,其0代表:如果存在数字则显示数字,不存在则显示0,即占位符。其FM代表:删除如果是因9带来的空格,则删除之

 

row_number() over 的order by 后的东西必须和最下面order by后的一致,否则会导致row_num字段错误

SELECT T_PSXG_TZGG_GG.GGBT,
T_PSXG_TZGG_GG.GGDM,
T_PSXG_TZGG_GG.FBSJ,
CASE
WHEN T_PSXG_TZGG_GG.SFZD = '1' AND
T_PSXG_TZGG_GG.GGZT = '1' AND
to_date(T_PSXG_TZGG_GG.ZDSJZ,
'yyyy-mm-dd hh24:mi:ss') >= sysdate then
1
else
0
end ZDZT,
T_PSXG_TZGG_GG.NRLX,
T_PSXG_TZGG_GG.PCURL,
T_PSXG_TZGG_GG.YDURL,
row_number() OVER(order by 
CASE
WHEN T_PSXG_TZGG_GG.SFZD = '1' AND
T_PSXG_TZGG_GG.GGZT = '1' AND
to_date(T_PSXG_TZGG_GG.ZDSJZ,
'yyyy-mm-dd hh24:mi:ss') >= sysdate then
1
else
0
end ZDZT desc,
T_PSXG_TZGG_GG.px,
T_PSXG_TZGG_GG.FBSJ) as row_num
FROM T_PSXG_TZGG_GG
LEFT JOIN T_PSXG_TZGG_LM
ON T_PSXG_TZGG_LM.LMDM = T_PSXG_TZGG_GG.LMDM
ORDER BY ZDZT DESC,
T_PSXG_TZGG_GG.PX,
T_PSXG_TZGG_GG.FBSJ DESC

 

 FCNR:varchar2转clob 

1,先新增temp字段

2,fcnr值赋给temp

3,删除fcnr字段

4,新增fcnr字段,type=clob

5,temp的值赋给fcnr

6,删除temp

 

 

posted on 2020-01-06 16:24  噢嗯  阅读(363)  评论(0编辑  收藏  举报