將查詢結果進行拼接的方法sql
SELECT T.CASE_ID, LISTAGG(T.OWNER_NAME, ',') WITHIN GROUP(ORDER BY T.OWNER_NAME) FROM DZAJ_PERSON_INFO T GROUP BY T.CASE_ID
數字漢字與阿拉伯數字轉換數據庫
CREATE OR REPLACE PACKAGE czutil AS --將數字轉化爲漢字,支持千兆級數字的操做 FUNCTION num2chi (numvalue IN NUMBER) RETURN VARCHAR2; --將漢字轉化爲數字,支持千兆級數字的操做 FUNCTION chi2num (chivalue IN VARCHAR2) RETURN NUMBER; END; CREATE OR REPLACE PACKAGE BODY czutil AS FUNCTION num2chi (numvalue IN NUMBER) RETURN VARCHAR2 IS --漢字映射數字的映射表 TYPE MAP IS TABLE OF VARCHAR2 (10) INDEX BY BINARY_INTEGER; ling_jiu_map MAP; shibaiqian_map MAP; wanyizhao_map MAP; --臨時變量 i INT := 0; --'臨時變量 j INT := 0; --臨時變量 k INT := 0; --臨時變量 x INT := 0; --臨時變量 y INT := 0; --臨時變量 str VARCHAR2 (100) := ''; --臨時變量 tmp VARCHAR2 (100) := ''; --臨時變量 integer_part VARCHAR2 (100) := ''; --數字形式整數部分 float_part VARCHAR2 (100) := ''; --數字形式小數部分 returnvalue VARCHAR2 (100) := ''; --返回值 BEGIN --初始化數組 ling_jiu_map (0) := '零'; ling_jiu_map (1) := '一'; ling_jiu_map (2) := '二'; ling_jiu_map (3) := '三'; ling_jiu_map (4) := '四'; ling_jiu_map (5) := '五'; ling_jiu_map (6) := '六'; ling_jiu_map (7) := '七'; ling_jiu_map (8) := '八'; ling_jiu_map (9) := '九'; shibaiqian_map (0) := ''; shibaiqian_map (1) := '十'; shibaiqian_map (2) := '百'; shibaiqian_map (3) := '千'; wanyizhao_map (0) := ''; wanyizhao_map (1) := '萬'; wanyizhao_map (2) := '億'; wanyizhao_map (3) := '兆'; --將數字拆分爲整數與浮點數兩個數字數組 i := INSTR (numvalue, '.', 1); IF i = 0 THEN integer_part := SUBSTR (numvalue, 1); ELSE integer_part := FLOOR (numvalue); float_part := SUBSTR (numvalue, i + 1); END IF; --計算整數部分 i := LENGTH (integer_part); j := CEIL (i / 4); k := 0; --將整數部分每四個分爲一個組 FOR k IN 0 .. j - 1 LOOP IF k = 0 THEN str := SUBSTR (integer_part, 1, i - 4 * j + 4); ELSE str := SUBSTR (integer_part, i - 4 * j + 4 * k + 1, 4); END IF; x := LENGTH (str); y := 0; tmp := ''; --將每一個組中數據轉化爲漢字 FOR y IN 0 .. x - 1 LOOP tmp := tmp || ling_jiu_map (SUBSTR (str, y + 1, 1)) || shibaiqian_map (x - y - 1); END LOOP; --零處理 tmp := RTRIM (tmp, '零'); --去掉兆億萬前面個位上的零 tmp := REGEXP_REPLACE (tmp, '(零[千百十])', '零'); --千百十位上的零 tmp := REGEXP_REPLACE (tmp, '(零{2,})', '零'); --將千百十位上的零結合 returnvalue := returnvalue || tmp || wanyizhao_map (j - k - 1); END LOOP; --零處理 --去掉兆億萬上的零 returnvalue := REGEXP_REPLACE (returnvalue, '(零[兆億萬])', '零'); --將兆億萬位上的零結合 returnvalue := REGEXP_REPLACE (returnvalue, '(零{2,})', '零'); --簡稱十位上的一 returnvalue := REGEXP_REPLACE (returnvalue, '^一十', '十'); returnvalue := REGEXP_REPLACE (returnvalue, '零一十', '零十'); --放進返回結果 IF returnvalue IS NULL THEN returnvalue := '零'; END IF; IF float_part IS NOT NULL THEN --計算小數部分 k := 0; tmp := ''; FOR k IN 1 .. LENGTH (float_part) LOOP tmp := tmp || ling_jiu_map (SUBSTR (float_part, k, 1)); END LOOP; returnvalue := returnvalue || '點' || tmp; END IF; RETURN returnvalue; END; FUNCTION chi2num (chivalue IN VARCHAR2) RETURN NUMBER IS --漢字映射數字的映射表 TYPE MAP IS TABLE OF BINARY_INTEGER INDEX BY VARCHAR2 (10); ling_jiu_map MAP; shibaiqian_map MAP; wanyizhao_map MAP; --臨時變量 i INT := 0; --'臨時變量 j INT := 0; --臨時變量 k INT := 0; --臨時變量 x INT := 0; --臨時變量 y INT := 0; --臨時變量 str VARCHAR2 (100) := ''; --臨時變量 tmp INT := 0; --臨時變量 tmp2 INT := 0; --臨時變量 integer_part VARCHAR2 (100) := ''; --數字形式整數部分 float_part VARCHAR2 (100) := ''; --數字形式小數部分 returnvalue NUMBER := 0; --返回值 BEGIN --初始化數組 ling_jiu_map ('零') := 0; ling_jiu_map ('一') := 1; ling_jiu_map ('二') := 2; ling_jiu_map ('三') := 3; ling_jiu_map ('四') := 4; ling_jiu_map ('五') := 5; ling_jiu_map ('六') := 6; ling_jiu_map ('七') := 7; ling_jiu_map ('八') := 8; ling_jiu_map ('九') := 9; shibaiqian_map ('') := 0; shibaiqian_map ('十') := 1; shibaiqian_map ('百') := 2; shibaiqian_map ('千') := 3; wanyizhao_map ('') := 0; wanyizhao_map ('萬') := 1; wanyizhao_map ('億') := 2; wanyizhao_map ('兆') := 3; --將十位上的一補充完整 str := REGEXP_REPLACE (chivalue, '^十', '一十'); str := REGEXP_REPLACE (str, '零十', '零一十'); --將數字拆分爲整數與浮點數兩個數字數組 i := INSTR (str, '點', 1); IF i = 0 THEN integer_part := SUBSTR (str, 1); ELSE integer_part := SUBSTR (str, 1, i - 1); float_part := SUBSTR (str, i + 1); END IF; --整型部分 x := LENGTH (integer_part); str := ''; tmp := 0; tmp2 := 0; FOR k IN 1 .. x LOOP str := SUBSTR (integer_part, k, 1); IF str IN ('萬', '億', '兆') THEN --當碰到萬億兆時 tmp := tmp + tmp2; returnvalue := returnvalue + tmp * POWER (10000, wanyizhao_map (str)); tmp := 0; tmp2 := 0; ELSIF str IN ('十', '百', '千') THEN --當碰到十百千時 tmp := tmp + tmp2 * POWER (10, shibaiqian_map (str)); tmp2 := 0; ELSE --當碰到數字時 tmp2 := ling_jiu_map (str); END IF; END LOOP; --最後將沒有小於萬位數加到整數中去 tmp := tmp + tmp2; returnvalue := returnvalue + tmp; IF float_part IS NOT NULL THEN --計算小數部分 k := 0; tmp := ''; FOR k IN 1 .. LENGTH (float_part) LOOP tmp := tmp || ling_jiu_map (SUBSTR (float_part, k, 1)); END LOOP; returnvalue := returnvalue || '.' || tmp; END IF; RETURN returnvalue; END; END czutil;
使用方法:數組
一、先創建packagesspa
二、使用下列SQL便可查詢code
SELECT CZUTIL.NUM2CHI(T) FROM TABLE
查看數據庫版本:blog
1)select * from PRODUCT_COMPONENT_VERSION;io
2)select * from v$version;class
根據子節點查詢全部的父節點:登錄
SELECT X_LEVEL, X_ID FROM TAB_X START WITH X_ID = '子節點編號' CONNECT BY NOCYCLE PRIOR PARENTID = X_ID;
根據父節點查詢全部子節點:變量
SELECT X_LEVEL, X_ID FROM TAB_X START WITH X_ID = '父節點編號' CONNECT BY NOCYCLE PRIOR X_ID = PARENTID;
純Oracle實現的日曆
SELECT MONTH 年月,"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" FROM ( SELECT TO_CHAR(dt,'fmMonthfm YYYY') MONTH, decode(to_char(dt,'ww'),52,decode(TO_CHAR(dt+1,'iw'),1,53,52),53,decode(TO_CHAR(dt+1,'iw'),1,53,52),TO_CHAR(dt+1,'iw')) week, MAX(DECODE(TO_CHAR(dt,'d'),'1',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期日", MAX(DECODE(TO_CHAR(dt,'d'),'2',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期一", MAX(DECODE(TO_CHAR(dt,'d'),'3',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期二", MAX(DECODE(TO_CHAR(dt,'d'),'4',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期三", MAX(DECODE(TO_CHAR(dt,'d'),'5',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期四", MAX(DECODE(TO_CHAR(dt,'d'),'6',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期五", MAX(DECODE(TO_CHAR(dt,'d'),'7',LPAD(TO_CHAR(dt,'fmdd'),2))) "星期六" FROM (SELECT TRUNC(SYSDATE,'y')-1+ROWNUM dt FROM all_objects WHERE ROWNUM <= ADD_MONTHS(TRUNC(SYSDATE,'y'),12) - TRUNC(SYSDATE,'y')) GROUP BY TO_CHAR(dt,'fmMonthfm YYYY'), decode(to_char(dt,'ww'),52,decode(TO_CHAR(dt+1,'iw'),1,53,52),53,decode(TO_CHAR(dt+1,'iw'),1,53,52),TO_CHAR(dt+1,'iw')) ) ORDER BY TO_DATE( MONTH, 'Month YYYY'), TO_NUMBER(week)
如何分辨用戶是從哪臺機器登陸的用戶
SELECT * FROM V$SESSION T