动态SQL:ORA-00925和ORA-06512

时间:2014-03-28 14:48:13

标签: sql oracle oracle11g

此代码没有任何意义,仅用于培训。但是这里有这样的错误,在调用它时:

EXEC ADD_ROW( 'fds', 'hgd', '243-650-215', 2);

1 ORA-00925:缺少INTO关键字 ORA-06512:at" MYDB.ADD_ROW",第8行 ORA-06512:第2行程序:MYDB.ADD_ROW(MyDB @ localhost:ORCL)8 1

CREATE OR REPLACE PROCEDURE MYDB.add_row(
  v1 IN CLIENT.FNAME%TYPE, v2 IN CLIENT.LNAME%TYPE, v3 IN CLIENT.DOC_ID%TYPE, v4 IN CLIENT.BENEFIT_ID%TYPE)
  IS
  sql_stmnt VARCHAR(200);
  tab_name VARCHAR2(20) := 'CLIENT';
  BEGIN
    sql_stmnt := 'INSERT INTO' || tab_name ||  'VALUES(100, :1,:2,:3,:4)';
    EXECUTE IMMEDIATE sql_stmnt USING  v1, v2, v3, v4;
  END;

2 个答案:

答案 0 :(得分:1)

我认为你只是错过了一个空格:' || tab_name || '

CREATE OR REPLACE PROCEDURE MYDB.add_row(
  v1 IN CLIENT.FNAME%TYPE, v2 IN CLIENT.LNAME%TYPE, v3 IN CLIENT.DOC_ID%TYPE, v4 IN CLIENT.BENEFIT_ID%TYPE)
  IS
  sql_stmnt VARCHAR(200);
  tab_name VARCHAR2(20) := 'CLIENT';
  BEGIN
    sql_stmnt := 'INSERT INTO ' || tab_name ||  ' VALUES(100, :1,:2,:3,:4)';
    EXECUTE IMMEDIATE sql_stmnt USING  v1, v2, v3, v4;
  END;

答案 1 :(得分:0)

您的表名周围缺少空格。此代码将生成INSERT INTOmy_tableVALUES(100, :1,:2,:3,:4)

形式的SQL

只需修改sql生成:

sql_stmnt := 'INSERT INTO ' || tab_name ||  ' VALUES(100, :1,:2,:3,:4)';