0

I send a parameter in my PLSQL function which is the name of the Table. In my code, I want to insert into the table that is being received in the parameter.

When I type the insert statement

insert into TABLE_VARIABLE_NAME 
VALUES (1, 2, 3);

It gives the error of Table Doesn't exist. How can I use Table's Name as the parameter of the function?

1
  • can elaborate it more for better answer with some example of code Commented Dec 5, 2014 at 4:25

2 Answers 2

2

Here is the full demo code you can try it and even the above hint is absolutely correct ,i just elaborated it more with insert values as varchar2 :-

create table td (valued varchar2(10));

create or replace procedure dhar_conn(tname varchar2)
 as
 begin
    execute immediate 'insert into '||tname||' values(''1'')';
 commit;
 end;/

 execute dhar_conn('td')
Sign up to request clarification or add additional context in comments.

1 Comment

is there any sql injection risk?
2

You'll need dynamic SQL with execute immediate.

execute immediate 'insert into ' || l_var_name || 'values (1,2,3)'

1 Comment

its correct and will work fine down you can see the full demo with values as varchar2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.