Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Concatination of String literal and nvarchar2 for dynamic Execute Immediate

472008Nov 26 2005 — edited Nov 28 2005
Hi,

I use Oracle 10g release2. I have following SP, which uses Execute Immediate. the problem is when I try to concatenate string literal and nvarchar2 type of variable in execute immediate. The SP compiles successfully. But give ORA-00900 error at runtime. I also tried to get generated query using dbms_output and that query runs successful. But SP is not running.

The procedure is....
CREATE OR REPLACE PROCEDURE rsp1
(
ItemID IN INT,
FieldName IN NVARCHAR2
)
AS
BEGIN
dbms_output.put_line('UPDATE Table1 SET ' || FieldName || '=null WHERE ItemID = '|| ItemID);
EXECUTE IMMEDIATE'UPDATE Table1 SET ' || FieldName || '=null WHERE ItemID = '|| ItemID;
RETURN;
END;
/

The running script is....

begin
rsp1(10,'CREATEDBY');
end;

And the output comes with error as ....
UPDATE Table1 SET CREATEDBY=null WHERE ItemID = 10
begin
*
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at "SCOTT.RSP1", line 9
ORA-06512: at line 2

This procedure works perfectly if I change the input param FieldName from nvarchar2 to varchar2 type.

Is it like Execute Immediate does not support concatenation or nvarchar2 type valriales?

Thanks,
Vivek
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2005
Added on Nov 26 2005
3 comments
728 views