Solved

Passing a variable in oracle select query

Posted on 2014-12-08
4
312 Views
Last Modified: 2014-12-08
I'm new to oracle 11g, I'm having hard time on oracle syntax.


I have to pass year variable to select query and retrieve the data to a cursor.

DECLARE YR_NR NUMBER;
        P_GET_CURRENCY  OUTSYS_REFCURSOR;
 
BEGIN
YR_NR := '2014'
 
OPEN P_GET_CURRENCY_TEST
 
SELECT  DCD.CCY_CD ID,
        DCD.CCY_CD_DSC_TE DSC
FROM   CCYDCD DCD,CCYEXC EXC
WHERE  DCD.CCY_CD = EXC.CCY_CD
AND    EXC.YEAR_NR  = YR_NR;
 RETURN P_GET_CURRENCY_TEST;
END;
0
Comment
Question by:chokka
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40487172
From the code stub you posted it looks like you want to create a procedure that accepts parameters and has a cursor as an OUT parameter:

create or replace procedure my_procedure(YR_NR IN NUMBER, P_GET_CURRENCY OUT YS_REFCURSOR)
is

 OPEN P_GET_CURRENCY_TEST for
   SELECT  DCD.CCY_CD ID, 
         DCD.CCY_CD_DSC_TE DSC
 FROM   CCYDCD DCD,CCYEXC EXC
 WHERE  DCD.CCY_CD = EXC.CCY_CD
 AND    EXC.YEAR_NR  = YR_NR;
   END; 

Open in new window

0
 

Author Comment

by:chokka
ID: 40487254
Throwing syntax error on For clause
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40487271
That was just typed in.  It was supposed to give you the basics.

Try this one:
create or replace procedure my_procedure(YR_NR IN NUMBER, P_GET_CURRENCY OUT SYS_REFCURSOR)
is
begin

 OPEN P_GET_CURRENCY for
   SELECT  DCD.CCY_CD ID, 
         DCD.CCY_CD_DSC_TE DSC
 FROM   CCYDCD DCD,CCYEXC EXC
 WHERE  DCD.CCY_CD = EXC.CCY_CD
 AND    EXC.YEAR_NR  = YR_NR;
   END; 
/

Open in new window

0
 

Author Closing Comment

by:chokka
ID: 40487984
Thank you for your help !!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle 12c database link between pdb not working 20 72
Need a starter for ETL protocol? 4 55
SSRS troubles 4 46
Deleting Rows from an Oracle Database - Performance 19 45
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

813 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now