We help IT Professionals succeed at work.

Dynamic sql using execute immediate

25 Views
Last Modified: 2020-06-15
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');
declare
*
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 13

declare
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';
begin
execute immediate sqlstmt
into l_emprec
using l_columnnames , l_tablename
;
end;
/


Any help is  really appreciated.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.