回覆列表
  • 1 # 小馬哥

    (1)定義split_type型別:CREATE OR REPLACE TYPE split_type IS TABLE OF VARCHAR2 (4000) / (2)定義split函式:CREATE OR REPLACE FUNCTION split (p_str IN VARCHAR2, p_delimiter IN VARCHAR2) RETURN split_type IS j INT := 0; i INT := 1; len INT := 0; len1 INT := 0; str VARCHAR2 (4000); my_split split_type := split_type (); BEGIN len := LENGTH (p_str); len1 := LENGTH (p_delimiter); WHILE j < len LOOP j := INSTR (p_str, p_delimiter, i); IF j = 0 THEN j := len; str := SUBSTR (p_str, i); my_split.EXTEND; my_split (my_split.COUNT) := str; IF i >= len THEN EXIT; END IF; ELSE str := SUBSTR (p_str, i, j - i); i := j + len1; my_split.EXTEND; my_split (my_split.COUNT) := str; END IF; END LOOP; RETURN my_split; END split; / (3)儲存過程中,使用類似 For T In ( select a,b,c,d from table (split("1,2,3,4",",")) ) Loop --注意下面的inserti語句,varchar型別的值需要補充引號上去 Execute Immediate " insert into tableName set fieldName = "||T.a ; Execute Immediate "commit"; End Loop; 的查詢語句,把分開的結果拼成sql語句並寫入到表中。

  • 中秋節和大豐收的關聯?
  • 小時候看過張庭演神仙守護龍珠什麼電視劇?