0

I have created a VIEW by joining some number of tables. I used a SP to call that VIEW and in the SP I'm filtering the data set of the view using an ID. Now I need to pass this ID to VIEW and do the filtering inside the VIEW itself. What is the way of passing this ID as a parameter to view in Oracle 10g?

Current View  

CREATE OR REPLACE FORCE VIEW "MY_VIEW" 
//SELECT statements goes here

FROM MY_TABLE_1, MY_TABLE_2
//TABLE JOINS

where 
//FILTERS

Current Stored Procedure

CREATE OR REPLACE PROCEDURE MY_SP
(
  REQUESTACCOUNTID IN NUMBER  
, p_cursor out SYS_REFCURSOR
) AS 
internal_flag NUMBER;
BEGIN

open p_cursor for
  SELECT //SELECT THE COLUMNS

from MY_VIEW my

WHERE my.account_id = REQUESTACCOUNTID;

END MY_SP;

What I need to do is, parse the parameter REQUESTACCOUNTID to the view while selecting

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
Shanaka
  • 1,670
  • 3
  • 21
  • 42
  • 1
    I'm not sure I follow... are you taling about [this sort of approach](http://stackoverflow.com/q/9024696/266304)? – Alex Poole Apr 08 '14 at 06:51
  • Sorry. I didn't understand that. What I need is to parse a parameter to the VIEW which is used in the SP to select the data. – Shanaka Apr 08 '14 at 06:56
  • I have added the current code and explained what I need to do – Shanaka Apr 08 '14 at 07:06
  • You can parameterise a view as shown in the question I linked to before. Or you could make your procedure a function which would be a bit simpler. Though not as simple as just including the `requestedaccountid` in the query against the view. How do you envisage your query looking - are you trying to do something like `select * from my_view(1234)` rather than `select * from my_view where account_id = 1234`? And why - is the `account_id` not supposed to be one of the selected columns? – Alex Poole Apr 08 '14 at 09:48

1 Answers1

0

this is sorted out using a package variable. More explanation can be found using this URL

Shanaka
  • 1,670
  • 3
  • 21
  • 42