如何 return 来自具有 RETURNING 子句的动态 SQL 的集合
How to return a collection from dynamic SQL having RETURNING clause
我有一个这样的 PL/SQL 块:
CREATE OR REPLACE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER;
DECLARE
updatedEmp NUMBER_TABLE_TYPE;
sqlstr VARCHAR2(1000);
tableName VARCHAR2(30) := 'EMPLOYEE';
deptId NUMBER := 12;
BEGIN
sqlstr := 'UPDATE '||tableName||' SET SALARY = SALARY * 2 WHERE DEPT_ID = :deptId '||
'RETURNING EMP_ID BULK COLLECT INTO :res';
EXECUTE IMMEDIATE sqlstr BULK COLLECT INTO updatedEmp USING deptId;
END;
RETURNING BULK COLLECT INTO
子句对于静态 DML 来说很简单,但在我的应用程序中它是动态的。我尝试了几种方法,但都没有成功。知道如何实现吗?
CREATE OR REPLACE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER;
DECLARE
updatedEmp NUMBER_TABLE_TYPE;
sqlstr VARCHAR2(1000);
tableName VARCHAR2(30) := 'EMPLOYEE';
deptId NUMBER := 12;
BEGIN
sqlstr := 'UPDATE '||tableName||' SET SALARY = SALARY * 2 WHERE DEPT_ID = :deptId '||
'RETURNING EMP_ID INTO :res';
EXECUTE IMMEDIATE sqlstr
USING deptId RETURNING BULK COLLECT INTO updatedEmp ;
END;
我有一个这样的 PL/SQL 块:
CREATE OR REPLACE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER;
DECLARE
updatedEmp NUMBER_TABLE_TYPE;
sqlstr VARCHAR2(1000);
tableName VARCHAR2(30) := 'EMPLOYEE';
deptId NUMBER := 12;
BEGIN
sqlstr := 'UPDATE '||tableName||' SET SALARY = SALARY * 2 WHERE DEPT_ID = :deptId '||
'RETURNING EMP_ID BULK COLLECT INTO :res';
EXECUTE IMMEDIATE sqlstr BULK COLLECT INTO updatedEmp USING deptId;
END;
RETURNING BULK COLLECT INTO
子句对于静态 DML 来说很简单,但在我的应用程序中它是动态的。我尝试了几种方法,但都没有成功。知道如何实现吗?
CREATE OR REPLACE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER;
DECLARE
updatedEmp NUMBER_TABLE_TYPE;
sqlstr VARCHAR2(1000);
tableName VARCHAR2(30) := 'EMPLOYEE';
deptId NUMBER := 12;
BEGIN
sqlstr := 'UPDATE '||tableName||' SET SALARY = SALARY * 2 WHERE DEPT_ID = :deptId '||
'RETURNING EMP_ID INTO :res';
EXECUTE IMMEDIATE sqlstr
USING deptId RETURNING BULK COLLECT INTO updatedEmp ;
END;