Solved

Passing a variable in oracle select query

Posted on 2014-12-08
4
310 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

760 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

22 Experts available now in Live!

Get 1:1 Help Now