我必须使用clob中的数据在循环中执行查询,并将每个查询的结果存储在游标中。但是我不确定如何/在哪里打开游标。如果我在循环中这样做,那么我假设只有最后一个查询的数据将存在。
在这种情况下,有什么办法。
这就是我想要实现的目标:
https://www.mkyong.com/jdbc/jdbc-callablestatement-stored-procedure-cursor-example/
PROCEDURE PRC(
P_DATE IN VARCHAR,
P_CLOB IN CLOB,
P_CUR OUT SYS_REFCURSOR
) IS
V_DATE DATE;
V_STR VARCHAR;
BEGIN
V_DATE := TO_DATE(P_DATE, 'DD/MM/YYYY');
V_CLOB_LENGTH := DBMS_LOB.getlength(P_CLOB);
V_START_CHAR := 1;
V_LEN := 5;
WHILE (V_START_CHAR + V_LEN) <= V_CLOB_LENGTH
LOOP
V_STR := SUBSTR(
P_CLOB,
V_START_CHAR,
V_LEN
);
V_START_CHAR := V_START_CHAR + V_LEN;
OPEN P_CUR FOR /* I know this is wrong */
SELECT A , B, C
FROM TAB
WHERE DATE = V_DATE
AND COL = V_STR;
END LOOP;
END PRC;
答案 0 :(得分:0)
如果我是你,我会在查询中对clob进行分块,然后您就可以将其加入到您的桌子中 - 例如:
PROCEDURE PRC(P_DATE IN VARCHAR,
P_CLOB IN CLOB,
P_CUR OUT SYS_REFCURSOR)
IS
v_length constant number := 5;
BEGIN
OPEN p_cur FOR
SELECT tab.a,
tab.b,
tab.c
FROM tab
INNER JOIN (SELECT to_char(p_date, 'dd/mm/yyyy') dt,
dbms_lob.SUBSTR(p_clob, v_length, (LEVEL - 1)*v_length + 1) substring
FROM dual
CONNECT BY dbms_lob.SUBSTR(p_clob, v_length, (LEVEL - 1)*v_length + 1) IS NOT NULL) str
ON tab.dt = str.dt
AND tab.col = str.substring;
END prc;