標籤:des style blog http color io 2014 art
1,case用法
SELECT CASE WHEN T.FLAG=‘0‘ THEN T.USERID WHEN T.FLAG=‘1‘ THEN T.ORGID ELSE NULLEND AS ‘標識‘FROM XTXMXX T
2,decode用法
--如果FLAG等於1,則轉為USERID,如果為0,則轉為ORGID,其他的為2SELECT DECODE(T.FLAG,1,T.USERID,0,T.ORGID,2) FROM XTXMXX T ;
3,建立sequence
-- Create sequence 建立sequencecreate sequence T41_R_ITEM_FIELDKEYminvalue 1maxvalue 99999999999999start with 10220increment by 1cache 20;
4,三種串連
--右串連 反方向串連SELECT * FROM SX02_PROGRAM T,SX03_GL_ACCASS LWHERE T.PROGRAMNO(+)=L.CITEM_ID;--左連結SELECT * FROM SX02_PROGRAM T,SX03_GL_ACCASS LWHERE T.PROGRAMNO=L.CITEM_ID(+);--特殊串連SELECT T.PROGRAMNO,(SELECT P.BONDNO FROM SX05_CONTRACT P WHERE P.PROGRAMNO=T.PROGRAMNO) FROM SX02_PROGRAM T,SX03_GL_ACCASS LWHERE T.PROGRAMNO=L.CITEM_ID;
5,更新多列
--多列更新UPDATE QJGL T SET (T.ZJQHZJRQ,T.ZJQHZJJE,T.LJQHZJJE)=(--此處只能查詢單一值,故要關聯SELECT TT.ZJZJZJRQ,TT.ZJZJZJJE,TT.LJZJZJJE FROM QJGL TTWHERE T.XTXMBH=TT.XTXMBH);
6,快速建立表
--快速建立表語句CREATE TABLE QJGL AS SELECT * FROM QJGLXX_ZQL T WHERE 1=0;
7,刪除表
DROP TABLE TABLE_NAME;
8,刪除使用者
drop user istaudit cascade;
9.ROW_NUMBER分組排序
select cc.serialno, cc.objectno, cc.corpuspaysum, --PARTITION BY:分組 ORDER BY:排序 可正序倒序 ROW_NUMBER() OVER(PARTITION BY cc.objectno ORDER BY cc.corpuspaysum desc) as rn from sx01_contract_paysource cc;
10.把數字轉換為字串仍保留0.格式
--取兩位小數,且把數字轉換為字串仍保留0.格式 select to_char(round(0.326,2),90.99) || ‘%‘ as result from dual;
--不保留0.格式select to_char(round(0.326,2)) || ‘%‘ as result from dual;