Solved

Passing a variable in oracle select query

Posted on 2014-12-08
4
314 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
[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
  • 2
4 Comments
 
LVL 77

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 77

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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