oracle 正在执行动态Sql以创建表

oxf4rvwz  于 2022-11-03  发布在  Oracle
关注(0)|答案(2)|浏览(167)

我正在尝试执行以下查询,但遇到无效标识符错误

EXECUTE IMMEDIATE 'create table temp parallel (degree 4) nologging as 
select e.* from employee e where e.emp_id between r0 and r1';
/

r0和r1作为数据类型为number的输入变量传递

uelo1irk

uelo1irk1#

如果要在PL/SQL块中使用动态SQL,请尝试以下操作:

DECLARE
  r0 number :=  100;
  r1 number := 1100;
BEGIN
  EXECUTE IMMEDIATE 'CREATE TABLE temp parallel (degree 4) nologging AS 
                     SELECT * 
                       FROM employee 
                      WHERE emp_id BETWEEN '||r0||' AND '||r1||' ';
END;
/
mf98qq94

mf98qq942#

r0和r1不是绑定变量:更改为:r0和:r1,并将USING子句添加到EXECUTE IMMEDIATE。(请阅读联机文档:(第10页)

相关问题