?
Solved

How to pass two input parameter to a query string in oracle

Posted on 2003-03-20
3
Medium Priority
?
793 Views
Last Modified: 2012-05-04
hi ,
I have two input parameters in my sql query. I placed the sql statement in a string. Now i have two compare two input parameter values with two columns. Please provide me a example to solve my problem. My input parameters are strings.

with rgds,
venkat

Eg: strsql := 'select empno, empname from emp where emp_no = '||strInputpar1||' and empname = '||strippar2||''and dept is not null;

Like above i written the query. It is not giving the values.
0
Comment
Question by:ponnuruv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:mona1974
ID: 8173049
The string should be between ' ' characters.

To have this in a string you should use twice the character ' (ex: '') + 'character for delimiting string
Example

select 'Scott' from dual has as result Scott
select '''Scott''' from dual has as result 'Scott'.

So:

strsql := 'select empno, empname from emp where emp_no = ''' ||strInputpar1|| ''' and empname = '''||strippar2||'''and dept is not null
0
 
LVL 1

Accepted Solution

by:
mona1974 earned 90 total points
ID: 8173056
sorry, for emp_no you don't need ''.
So:
strsql := 'select empno, empname from emp where emp_no = ' ||strInputpar1|| ' and empname = '''||strippar2||'''and dept is not null
0
 

Author Comment

by:ponnuruv
ID: 8179277
Thanks for ur timely help.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question