?
Solved

Passing a variable in oracle select query

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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