Avatar of Swaminathan K
Swaminathan KFlag for India asked on

Dynamic sql using execute immediate

Hi Team,

Need an help on  the dynamic sql using execute immediate , iam trying to pass tablename and columnames as input
below is the code , its failing

Enter value for tabname: employees
old   2: l_tablename varchar2(40):=upper('&tabname');
new   2: l_tablename varchar2(40):=upper('employees');
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 13

l_tablename varchar2(40):=upper('&tabname');
l_columnnames varchar2(4000):='employee_id , first_name,last_name';
type t_emprec is record
employee_id employees.employee_id%type,
first_name employees.first_name%type,
last_name employees.last_name%type
l_emprec t_emprec;
sqlstmt varchar2(4000):='Select :1 from :2 where employee_id =103';
execute immediate sqlstmt
into l_emprec
using l_columnnames , l_tablename

Any help is  really appreciated.
Oracle Database* Oracle PL/SQLSQL

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon
slightwv (䄆 Netminder)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes