开发者

PLSQL error - ORA-00984: column not allowed here

I have written a PL-SQL block

DECLARE
    SchemaName  VARCHAR2(50) :='REQ_SUNIL_5750';
开发者_开发技巧    userpassword VARCHAR2(50) :='XYZ';  
    stmt VARCHAR2(5000);
BEGIN
   stmt :='INSERT INTO ' || SchemaName || '.USER_CREDS VALUES ('|| SchemaName ||', '|| userpassword ||' )';
   DBMS_OUTPUT.PUT_LINE(stmt) ;
   EXECUTE IMMEDIATE stmt;
   commit;
END;

When I execute above block I am getting below, ORA-00984: column not allowed here

I have created table with name 'REQ_SUNIL_5750.USER_CREDS and it has username and password columns Please help


You have to quote your string values properly:

stmt :='INSERT INTO ' || SchemaName || 
  '.USER_CREDS VALUES ('''|| SchemaName ||''', '''|| userpassword ||''' )';


Frank's answer is great, I would add one point though.

From the perspective of performance and reuseability, your execute immediate statement should use bind variables and the insert syntax should specify the columns that correspond to the values being entered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜