passing parameters from PL/SQL [message #39521] |
Mon, 22 July 2002 06:29 |
Mike
Messages: 417 Registered: September 1998
|
Senior Member |
|
|
I have a SQL query: SELECT * FROM EmpTable WHERE EmpName = 'John';
Now if I open this as a cursor in a PL/SQL function where I execute the above query with a EmpName supplied by the user...then I need to store the query in a string variable (or VARCHAR2 variable) But how do I handle the single quotes around the value of EmpName???? Is there some escape sequence??
DECLARE
query VARCHAR2(100):= 'SELECT * FROM EmpTable WHERE EmpName = 'John''; -- This is obviously wrong!
refc package.refcursor;
BEGIN
OPEN refc FOR query;
END;
|
|
|
Re: passing parameters from PL/SQL [message #39531 is a reply to message #39521] |
Mon, 22 July 2002 10:05 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
Is the employee name supplied while running in SQL*Plus or is it a parameter passed into a procedure?
If it is a parameter, you don't need to use dynamic SQL, just:
open refc for
select * from emptable where empname = p_empname;
|
|
|