我需要在cursor
条款中读取FROM
到另一个/* First Cursor to getTable Name*/
Cursor Get_Table_Nm IS
Select code_val1_nm from ref_table_detail where CODE_VAL2_NM=V_Table_Name
/*Second Cursor to update the id*/
CURSOR SEQ_UPDT IS
SELECT V_Table_Name_Intrl_Id, V_Table_Name_Seq_Id
FROM (<<<<<Here I Want to pass the value from Get_Table_Nm (first) Cursor>>>>);
的值。
以下是代码段。
public interface Foo {
static Foo get() {
...
}
}
答案 0 :(得分:0)
此处cursor_1
返回table name
需要在second cursor
dynamic cursor
您必须使用DECLARE
Cursor Get_Table_Nm IS
Select code_val1_nm
from ref_table_detail
where CODE_VAL2_NM = V_Table_Name;
SEQ_UPDT SYS_REFCURSOR;
v_code_val1_nm varchar2(50);
BEGIN
OPEN Get_Table_Nm;
LOOP
FETCH Get_Table_Nm INTO v_code_val1_nm;
EXIT WHEN Get_Table_Nm%NOTFOUND;
open SEQ_UPDT
for 'SELECT V_Table_Name_Intrl_Id, V_Table_Name_Seq_Id FROM ' || v_code_val1_nm;
LOOP
-- Fetch SEQ_UPDT into ....
-- Do with the data
END LOOP;
close SEQ_UPDT
END LOOP;
close Get_Table_Nm;
END;
{{1}}
答案 1 :(得分:0)
如果需要在不同的表上打开游标,根据查询结果,可以尝试使用动态SQL;例如以下内容(伪代码):
DECLARE
V_Table_Name varchar2(30);
V_Table_For_Second_Query varchar2(30);
...
BEGIN
...
Select code_val1_nm
into V_Table_For_Second_Query
from ref_table_detail
where CODE_VAL2_NM=V_Table_Name;
open cursor SEQ_UPDT for
'SELECT V_Table_Name_Intrl_Id, V_Table_Name_Seq_Id ' ||
'FROM ' ||
V_Table_For_Second_Query;
...