?
Solved

passing VARCHAR2 as parameter in stored procedure.

Posted on 2007-08-03
7
Medium Priority
?
1,581 Views
Last Modified: 2013-12-19
If I have a VARCHAR2 parameter that I need to use in a query in the stored procedure, how do I do it?
For e.g.
I have a query like:
pStrValue is of type VARCHAR2.
It works fine with SQLServer 2005 but not on Oracle 9i. It compiles, but no rows are returned.
SELECT * from test1
WHERE col1 = pStrValue;
I have tried with SELECT * from test1
WHERE col1 = ''' || pStrValue || ''' ;  -- this does not work too.
When I put in the actual value, it works fine.For e.g.
SELECT * from test1
WHERE col1 = 'user1';
0
Comment
Question by:Enid_JP
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19623634
SELECT * from test1
WHERE col1 = pStrValue;

that should work.

now, what is the data type of col1? if it is CHAR instead of VARCHAR2, that might explain...
0
 
LVL 14

Expert Comment

by:GGuzdziol
ID: 19623644
Maybe there is problem with case-sensitivity. Make sure that passed value is also user1 (not User1, USER1) - if not, You have to use upper/lower on both sides of comparision.
0
 
LVL 27

Expert Comment

by:sujith80
ID: 19623662
Print and see what value is being passed to pStrValue

try:
SELECT * from test1
WHERE col1 = trim(' ' from pStrValue);
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 19624445
This is related to: http://www.experts-exchange.com/Database/Oracle/9.x/Q_22732428.html

Please post a stand alone code example of what you are trying to do.  Like I mentioned in the other question, I'm not clear on exactly what you are after.

Is this what you are trying?
------------------------------------
drop table tab1;
create table tab1 ( col1 number, col2 varchar2(10) );

insert into tab1 values(1,'Hello');
insert into tab1 values(2,'World');
commit;

create or replace procedure junk ( inText in varchar2 )
is
      myResult number;
begin
      select col1 into myResult from tab1 where col2 = inText;
      dbms_output.put_line('Got: ' || to_char(myResult));
end;
/

exec junk('Hello');
exec junk('World');


0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22201819
PAQ ? ...
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22242213
PAQed with no points refunded (of 50)

Computer101
EE Admin
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to recover a database from a user managed backup
Suggested Courses

840 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