【发布时间】:2018-12-04 19:31:58
【问题描述】:
是否可以在 pl/sql 中循环遍历需要进入 pl/sql 语句的 WHERE 子句的多个 id。 sql 语句本身非常简单,但我需要遍历多个 id:
SELECT x_name
FROM table_x
WHERE x_id = {array of 90 id's};
如何在此处插入 90 个 id 以便 sql 对其进行迭代?我尝试使用光标 For Loop,但我被卡住了。下面的代码是错误的,但它可能表明我试图在这里实现什么
DECLARE
TYPE x_id_array IS VARRAY(3) OF NUMBER;
CURSOR cur_x_id (x_ondz_id NUMBER) IS
SELECT x_name
FROM table_x
WHERE x_id = var_ondz_id;
loop_total integer;
x_id x_id_array;
name VARCHAR;
BEGIN
x_id_new := x_id_array(8779254, 8819930, 8819931); --3 for testing
loop_total := x_id_new.count;
FOR i in 1 .. loop_total LOOP
dbms_output.put_line('x_id: ' || x_id_new(i) || '= Name: ' || x_name );
END LOOP;
END;
/
预期的输出将是
x_id: 8779254= Name: Name_1
x_id: 8819930= Name: Name_2
x_id: 8819931= Name: Name_3
...
... etc for all 90 id's in the array
感谢任何帮助
【问题讨论】:
标签: oracle for-loop plsql iteration