Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing a variable in oracle select query

Posted on 2014-12-08
4
Medium Priority
?
324 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

618 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