Oracle經常使用語法

1,case用法spa

SELECT 
CASE WHEN T.FLAG='0' THEN T.USERID WHEN T.FLAG='1' THEN T.ORGID ELSE NULL END AS '標識' FROM XTXMXX T

2,decode用法code

--若是FLAG等於1,則轉爲USERID,若是爲0,則轉爲ORGID,其餘的爲2 SELECT DECODE(T.FLAG,1,T.USERID,0,T.ORGID,2) FROM XTXMXX T ;

3,建立sequence blog

-- Create sequence 建立sequence create sequence T41_R_ITEM_FIELDKEY minvalue 1 maxvalue 99999999999999 start with 10220 increment by 1 cache 20;

4,三種鏈接排序

--右鏈接 反方向鏈接 SELECT * FROM SX02_PROGRAM T,SX03_GL_ACCASS L WHERE T.PROGRAMNO(+)=L.CITEM_ID; --左連接 SELECT * FROM SX02_PROGRAM T,SX03_GL_ACCASS L WHERE 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 L WHERE T.PROGRAMNO=L.CITEM_ID;

5,更新多列rem

--多列更新 UPDATE QJGL T SET (T.ZJQHZJRQ,T.ZJQHZJJE,T.LJQHZJJE)= ( --此處只能查詢單一值,故要關聯 SELECT TT.ZJZJZJRQ,TT.ZJZJZJJE,TT.LJZJZJJE FROM QJGL TT WHERE T.XTXMBH=TT.XTXMBH );

6,快速建立表字符串

--快速建立表語句 CREATE TABLE QJGL AS SELECT * FROM QJGLXX_ZQL T WHERE 1=0;

7,刪除表it

DROP TABLE TABLE_NAME;

8,刪除用戶class

drop user istaudit cascade;

9.ROW_NUMBER分組排序object

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.格式 select

--取兩位小數,且把數字轉換爲字符串仍保留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;

相關文章
相關標籤/搜索