Parameters in SubQuery

Hi,
I am new to discoverer and i have a doubt. I have a query and within it is a subquery. I want to use a parameter in subquery. The query i want to achive is
select distinct pap.full_name ,papf.payroll_name , pap.employee_number, pap.national_identifier, pap.original_date_of_hire, paf.effective_start_date
from per_all_people_f pap,
per_all_assignments_f paf,
     pay_all_payrolls_f papf
where pap.person_id = paf.person_id
and paf.payroll_id = papf.payroll_id
and papf.payroll_name like '%'
and paf.effective_start_date between '01-JAN-2000' and '31-DEC-4712'
and not exists (select paf2.effective_start_date from per_all_assignments_f paf2
where paf2.assignment_id = paf.assignment_id
     and paf2.effective_start_date < '01-JAN-2000'
and paf2.payroll_id = paf.payroll_id)
How can i map the paf2.effective_date in the desktop version.
papf.payroll_name and paf.effective_start_date can be mapped using parameters since they are in outer select. how do i do the same for paf2.effective_date
TIA

Hi,
How does this differ then from setting the USERENV in discoEvery database session has a USERENV context that you could use. Defining your own context enables you to have multiple parameters. Also many applications use the USERENV context and setting your own values could overwrite values set by the application.
So why does the setting context has to be set beforehand and cannot be done in the same sheetWhen you run a worksheet in Discoverer a single SQL SELECT statement is run in the database. In an SQL SELECT statement you can use a PLSQL function call to set a context and a call to SYS_CONTEXT to check a context value. If you try and set and check a context in the same SQL statement you will find that usually the PLSQL function call is made after calls to SYS_CONTEXT so that the value you retrieve from SYS_CONTEXT is not the value you set with the function. However, there is no rules about when or how often PLSQL functions are called within an SQL statement, so trying to set and get a context in the same SQL statement will always be unreliable, and you will get different results depending on how the SQL execution plan is processed. Therefore you should always set and get a context in separate SQL SELECT statements. This means that in Discoverer you need a separate worksheet to set the parameters. Of course, the worksheet you use to set the parmaeters could be in the same workbook as the worksheet you use to run the report.
Rod West

Similar Messages

  • How to pass context based parameters to subquery?

    Hello to All!
    How to pass context based parameters to subquery of custom folder when I schedule workbook?
    Thanks, Oleg

    Hi Russ
    Yes, I've done this too. Basic SQL though will not allow the updating of a table inside a function, so we have to get clever. The trick is to use the PRAGMA AUTONOMOUS TRANSACTION command. Here's an example:
    FUNCTION UPDATE_MYTABLE(P_VALUE IN NUMBER)
    RETURN VARCHAR2 IS
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    UPDATE SCHEMA_OWNER.MY_TABLE SET MY_VALUE = P_VALUE;
    COMMIT;
    RETURN('Done');
    END UPDATE_TABLE;
    When the update has been completed the Discoverer worksheet will respond with 'Done'.
    Everyone: don't forget to grant EXECUTE on this function to all of the necessary users, including the EUL owner, and also don't forget to import the function using the Admin edition so that it is available for the users. You will also need to make sure that all necessary users have been granted the UPDATE privilege on the table.
    I hope this helps
    Regards
    Michael

  • Ho wto Dynamically Pass Parameters to a Query in Discoverer

    Hi All,
    I have a Query where I would to like to pass the Parameters Dynamically.In my query I have three selects and two UNION ALL's.In the three selects I have to pass Period & Year Parameters.In Each Select the Period Calculation is Different.Say in first & second select from the passed period parameter I calculate the previous Months.Whereas in the last select I do the the calculation with the Passed Period.How is it Possible with Discoverer..
    Thnx in Advance
    Rgds,
    Sai Srivatshav

    Hi,
    Well there is no straight forward way to do that.
    There is a work around to get that functionality by using outer tables or context.
    Take a look at the following posts:
    Re: Parameters in SubQuery
    Re: Parameters in Discoverer Administration
    Re: Passing multiple parameters into Custom Folder...

  • Use parameters in the folder

    I am new to Discoverer, so please excuse me if this is a dumb question.
    Right now, we have a table that is populated through a load procedure that runs at night. This is a kill-and-fill process which just runs a SELECT statement and inserts the results into a table. Many rows are created from this.
    The Discoverer report I am looking at just queries the table for the data using parameters. Simple and easy.
    However, I would really like to eliminate the load procedure all together and just use a pipeline function which gets the same information... and faster.
    I would like to change the SQL statement being used now to the one using the pipeline function. In order to do this, I would need to pass in the parameters from the report into the SQL statement (date range and other things).
    Is this possible?
    I appreciate everyones time to read this.

    Hi,
    There are two techniques you can use to pass parameters through to the table function that is referenced in a view mapped into the EUL.
    1. Join your table function to a table. For example, if you want to pass EMPNO into your table function then you can create your view like this:
    CREATE OR REPLACE VIEW pipedview AS
    SELECT e.empno, t.*
    FROM emp e, TABLE(your_function(e.empno)) tThen you can create a empno parameter based on the empno column in the view. This method only works if you have a tightly controlled list of values for your parameters.
    2. Use database contexts. Define a database context namespace and use a separate worksheet to set the database contexts. Check out some of these threads on how to use contexts with Discoverer:
    Re: Implementing HR report in Discoverer
    Re: Passing multiple parameters into Custom Folder...
    Re: Parameters in SubQuery
    Re: Passing Parameters to a discoverer folder using Note 282249.1
    Then create your view like this:
    CREATE OR REPLACE VIEW pipedview AS
    SELECT * FROM TABLE(your_function(SYS_CONTEXT('DISCO_CONTEXT','EMPNO'))) tYour users will have to ensure that the context has been set before the reporting worksheet is run.
    Rod West

  • Before Trigger in Discoverer 10.1.2

    Hi,
    Can any one help me how to build before trigger report in Discoverer. there is a function which internally calling a procedure which has parameters like process_id,organization_name,Gre,start_date,end_date. This process_id will be generated based on a sequence. So, how to pass value for the process_id parameter from Desktop Edition.
    example:-
    function a(process_id ,start_date,end_date..etc)
    procedure(process_id ,start_date,end_date..etc)
    insert into temp_table values(process_id,start_date,end_date,etc);
    end function a;
    In Desktop we created a workbook worksheet we called this function in calculation tab.It has to insert some rows into temp_table and we will create second sheet on this temp_table.
    The problem we are facing is we are not able to pass sequence.nextvalue as default value for a parameter. Please suggest.
    Thanks inadvance,
    Ch.Hanuman Prasad

    Hi,
    There is no before report trigger. You may be able to use a logon trigger.
    It sounds as though you may want to investigate using database contexts as session parameters which can be set by a workbook or at logon and remain for the duration of the DIscoverer session. Look at these posts for more details:
    Re: Passing multiple parameters into Custom Folder...
    Re: Parameters in SubQuery
    Re: Passing Parameters to a discoverer folder using Note 282249.1
    Rod West

  • Passing parameter to a query in Discoverer Admiin custome folder.

    I am developing a report in which I need to paa in the request Id as parameter to display the user the data corresponding to that request Id. However the query is very complex and If I am enetering the request Id in Discoverer Desktop se as Condition for the workbook created the report takes a lot of time to generate. Is there any mechanism through which I can pass the parameter directly to the Custome folder query. As this will reduce my computation time since all the joins will be done only for the rows with that given request Id rather than for all the rows which is happenning correctly.
    Thanks.

    Hi,
    Well there is no straight forward way to do that.
    There is a work around to get that functionality by using outer tables or context.
    Take a look at the following posts:
    Re: Parameters in SubQuery
    Re: Parameters in Discoverer Administration
    Re: Passing multiple parameters into Custom Folder...

  • How to pass parameter in Discoverer inner query  PLZ give solution-URGENT

    Hi All,
    My need is I have a query in Disco Admin which has inner query as mention below:
    select Net_Drawn_Amount,Undrawn_Amount,Business_Date from
    (select * from t_FacilityExtract) A,
    We are creating a workbook using Diso Plus and creating a parameter on Business_date which is date partitioned, but issue is in inner query(select * from t_FacilityExtract) is picking whole data which has millions of rows.
    Plz help me how to filter inner query.
    It is just a sample query.
    Plz help me as soon as possible.
    Thanks in advance
    Amit

    Hi,
    Generally, using database contexts is the best way to pass parameters to folders defined in Disco Admin. You can look at this posts or download a article on using contexts with Discoverer from my website (www.cabotconsulting.co.uk).
    Re: Implementing HR report in Discoverer
    Re: Passing multiple parameters into Custom Folder...
    Re: Parameters in SubQuery
    Re: Passing Parameters to a discoverer folder using Note 282249.1
    Rod West

  • How to create a UNION between two custom folders

    Hi all, I have two different dataset based respectively on two custom folders: CF1 and CF2
    The first custom folder (CF1) is joined with a custom folder called Groups and retrieve the amount of tickets_id which are owned by the groups.
    The second custom folder (CF2) is joined with another custom folder called User and retrieve the amount of tickets_id which have been created by the users.
    This two sets, as you have understood are independents and not correlated, because the two different amount of tickets_id follow two different logics....
    However, now I need to have a single field called TICKET_ID which is the UNION (not UNION ALL) of all tickets_id retrieved by CF1 and CF2
    I tried to use a complex folder...but it showed always two distinct fields...instead I want to merge the two dataset into a single field called TICKET_ID
    Is there a way or a workaround to resolve this problem ???
    Thanks a lot in advance
    Alex

    Hi Rod, just an explanation...
    I red and follow the threads you mentioned in your previous mails and I'm using the context.
    I summarized what I did
    1) I created the context and the package (with the 2 functions inside)
    2) I created on the Administrator a custom folder with the following sql:
    select vl.user_id,g.group_id
    from apps.jtf_rs_emp_dtls_vl vl,
    apps.jtf_rs_group_members_vl g
    where g.resource_id = vl.resource_id
    and (g.delete_flag = 'N' AND vl.end_date_active IS NULL)
    and g.group_id = COMPLAINTS_GET_GROUP_ID(SYS_CONTEXT('DISCO_CONTEXT','GROUP'))
    where COMPLAINTS_GET_GROUP_ID is the package name which contains the 2 function SET_CONTEXT and SHOW_CONTEXT, even if I use directly the SYS_CONTEXT function....
    3) Inside my workbook I have 2 sheets and one parameter (called GROUP):
    a. inside the first sheet I created the calculated field which set the parameter value with the following code : SET_CONTEXT('GROUP',:GROUP)
    b. inside the second sheet I show the list of user_id retrieved from the select above
    This mechanism works perfectly, even if the refresh of the parameters on the first sheet is mandatory to see the right data on the second one. But this works ONLY if my parameter GROUP has ONLY one value....
    Now I have the necessity to pass to the select a LOV of groups !
    Reading the previous threads I saw that there are two ways to solve this problem: (Re: Parameters in SubQuery
    a. - join your subquery to you list of values folder. If you have a parameter that is based on a LOV then there will be a folder that defines the LOV. You should be able to join the subquery folder to the LOV folder either in the EUL or in a custom folder and use the parameter to select from the LOV folder.
    I can't use this option because inside the same custom folder I need to have a UNION of 2 different select with their separated joins
    b. use multiple parameters, so you define a fixed number of optional parameters, say, PARAM1,PARAM2,PARAM3,PARAM4 and PARAM5. Then set them in a separate workbook and then use a condition col IN (SYS_CONTEXT('NAMESPACE','PARAM1'), SYS_CONTEXT('NAMESPACE','PARAM2'), SYS_CONTEXT('NAMESPACE','PARAM3'), SYS_CONTEXT('NAMESPACE','PARAM4'), SYS_CONTEXT('NAMESPACE','PARAM5'))
    This solution is very interesting but I didn't understand how to implement it (remember that I have only one parameter "GROUP" with more than on value).
    How can I modify the calculation and the condition inside the select ?
    Thanks a lot

  • Can I pass parameters to a subquery to return a narrow result set?

    Hi-
    HERE'S WHAT I'M TRYING TO DO:
    Create a worksheet to aggregate the data that's returned from a subquery result set based on the user's specified date ranges.
    HERE'S MY PROBLEM:
    Discoverer is aggregating the data FOR EACH PARTICULAR DATE that shows up (ie-6/1, 6/2, 6/3) instead of across the entire specified date range (ie- 6/1-6/3) because the date parameters can only be applied to the main query instead of the subquery.
    In essence, I need to:
    SELECT location1, task1, sum(product1), max(product2)
    FROM
    (SELECT * FROM table1 WHERE date1 >= userSpecifiedDate1 and date1 <= userSpecifiedDate2)
    GROUP BY location1, task1
    ...but using Discoverer's "Parameters" and "Totals" tool, so far I can only get Discoverer to do this :
    SELECT location1, task1, sum(product1), max(product2), sum(product3)
    FROM
    (SELECT * FROM table1)
    WHERE date >= userSpecifiedDate1 and date <= userSpecifiedDate2
    GROUP BY location1, task1
    Is there any way to apply date parameters to the subquery first so I'm aggregating across the range and not on each date?
    Hope this makes sense. Any suggestions would be appreciated!

    Hi,
    Yes.
    You can pass parameter from search criteria to procedure.
    First u need write a method in the AmImpl java class to call the procedure.
    Like
    public void callingProcWithinParams(String sreachCriterParam)
    //pass the parameter to proc
    Then shuttle this method to client interface.

  • Bad execution plans when using parameters, subquery and partition by

    We have an issue with the following...
    We have this table:
    CREATE TABLE dbo.Test (
    Dt date NOT NULL,
    Nm int NOT NULL,
    CONSTRAINT PK_Test PRIMARY KEY CLUSTERED (Dt)
    This table can have data but it will not matter for this topic.
    Consider this query (thanks Tom Phillips for simplifying my question):
    declare @date as date = '2013-01-01'
    select *
    from (
    select Dt,
    row_number() over (partition by Dt order by Nm desc) a
    from Test
    where Dt = @date
    ) x
    go
    This query generates an execution plan with a clustered seek.
    Our queries however needs the parameter outside of the sub-query:
    declare @date as date = '2013-01-01'
    select *
    from (
    select Dt,
    row_number() over (partition by Dt order by Nm desc) a
    from Test
    ) x
    where Dt = @date
    go
    The query plan now does a scan followed by a filter on the date.
    This is extremely inefficient.
    This query plan is the same if you change the subquery into a CTE or a view (which is what we use).
    We have this kind of setup all over the place and the only way to generate a good plan is if we use dynamic sql to select data from our views.
    Is there any kind of solution for this?
    We have tested this (with the same result) on SQL 2008R2, 2012 SP1, 2014 CU1.
    Any help is appreciated.

    Hi Tom,
    Parameter sniffing is a different problem. A query plan is made based on the value which may be really off in the data distribution. We do have this problem as well e.g. when searching for today's data when the statistics think the table only has yesterday's
    data (a problem we have a lot involves the lack of sufficient amount of buckets in statistics objects).
    This problem is different.
    - It doesn't matter what the parameter value is.
    - You can reproduce this example with a fresh table. I.e. without statistics.
    - No matter what the distribution of data (or even if the statistics are correct), there is absolutely no case possible (in my example) where doing a scan followed by a filter should have better results than doing a seek.
    - You can't change the behavior with hints like "option(recompile)" or "optimize for".
    This problem has to do with the specific combination of "partition by" and the filter being done outside of the immediate query. Try it out, play with the code, e.g. move the where clause inside the subquery. You'll see what I mean.
    Thanks for responding.
    Michel

  • Creating Subquery Depend on user parameters at discoverer

    Below is An Example
    I have atable that contains history data of a Receipt, I'll assume the table contains only two columns
    Status_Date Status
    01-jan-12 Open
    15-jan-12 Modified
    20-jan-12 Requier Approval
    25-jan-12 Approved
    31-jan-12 Closed
    The report need to display the status at specific date entered by the user
    if the user enter parameter 10-jan-12 the status is still open so the report display Open
    if user enter 26-jan-2012 the report should display "Approved" the last status before date parameters
    and so on .....
    is there any way in the discoverer to do this. if i create a condition on the date saygin date <= :p_date it'll retirve all the statues before this date not the last status
    and if i said date = :p_Date the user may enter a date that is not exists in the table so it'll not retrive any data

    Hi Rod West
    The calculation using LEAD Function will lead to data like below
    01-JAN-2012     OPEN     15-JAN-2012
    15-JAN-2012     MODIFIED     20-JAN-2012
    20-JAN-2012     REQUIRE APPROVAL     25-JAN-2012
    25-JAN-2012     APPROVED     31-JAN-2012
    31-JAN-2012     CLIOSED     
    so when using :p_date between status_date and status_end_date
    In case :p_date = '05-jan-2012' it'll return OPEN
    In case :p_date = '16-jan-2012' it'll return MODIFIED
    Good work BUT
    In case :p_Date = '15-JAN-2012' it'll return 2 records OPEN, Modified * can be fixed using >= and <
    BUT
    In case of 01-FEB-2012 it'll not return any result
    while the status starting from 31-jan-2012 till now is CLOSED.
    :(

  • Parameters issue in discoverer while writing a view...its urgent please

    Hi Everybody,
    I have written a view in which i have a where condition which says something like
    where abc IN ( Select xyz from table2).
    Now in my desktop, i want a parameter to pass for the subquery as
    select xyz from table2 where column1='bla bla bla'
    please tell me how is this possbile.
    thank you
    kumar

    Kumar.
    1. Are you trying to show a LOV at run time? If so, you can create a LOV directly in the EUL via Disco Admin which will present a list of the items a user can choose from at run time (and not have to worry about a sub-query).
    2. If it's an actual sub-query you need, then first of all, Disco v4 (maybe it was v9, but that was an ugly child anyway) is the last version that supported 'pseudo' sub-queries.
    3. It's been written up in the forum many times about how to pass run time parameters to a folder in the EUL. There's one method that's popular for actually passing the parm to the folder.
    4. Another method is to create a worksheet that only calls a function, to kick off a PL/SQL routine that builds a table using your parameter and then have the main worksheet call that new table.
    So, if it's a LOV you want - that's a whole lot easier.
    Russ

  • Lexical Parameter in subquery?

    Is it possible?
    select * from ( select a,b,c from t where &p_where ) where a>1
    It doesn't seem to like this construct - is there a proper way to do this? p_where will be built based on the parameters selected at runtime.
    Thanks,
    stephan

    Did you supply an initial value for "p_where"? If it is NULL, your sub-query will be invalid because Reports Builder will see it as (note the missing where condition):
    select * from ( select a,b,c from t where  ) where a>1You could supply an initial value such as "1=1", or, you could remove the key word "where" from the subquery and put it in the lexical parameter:
    select * from ( select a,b,c from t &p_where ) where a>1Ah, I see dmars beat me to the punch.
    Message was edited by:
    Brian Hill

  • Oracle db wrong result on subquery error

    Hi,
    I work with Oracle databases up to 10g and I found an error and couldn’t find any documentation about it yet. Perhaps you can help me.
    The error is quite easy to replicate. If you run the following query adapting the parameters you should get a result, the problem is that you should only get an error!
    select * from user_tab_columns
    where table_name in
    select table_name from <TABLE_B>
    Parameter: TABLE_B
    Description: This should be an existing table of the schema which doesn’t have any table_name field.
    As I said, the sub-query is wrong, so if you try to run it separately it fails. The problem is when you run both together because, if the link field has the same name, it returns all values of the table in the outer query.
    Do you know if this is solved in 11g or in a specific patch of 10g?
    Thanks in advance for your interest.
    Best regards,
    Leo ([email protected])

    user6396183 wrote:
    I don't think a query whose inner query evaluates to ORA-00904 'Invalid identifier' should return anything, it's not logic. To me this is a bug.
    If you execute the following query it will retrieve all records from the outer table when it should only return an exception as the inner query can not be evaluated at all.
    select * from user_tab_columns
    where table_name in (select table_name from user_role_privs);You still did not get it. Yes inner query by itself results in ORA-00904 'Invalid identifier' only if you execute it independently:
    select table_name from user_role_privsOracle parser tries to figure out what table_name is. It is not a literal, therefore it concludes it is an identifier. Now the only table in FROM list is user_role_privs and it has no such column. Then parser checks if such function exists and it does not, etc... At the end ORA-00904 'Invalid identifier' is raised. However, look what happens if you issue it as a sub_query:
    select * from user_tab_columns
    where table_name in (select table_name from user_role_privs);Again, Oracle parser tries to figure out what table_name is. It is not a literal, therefore it concludes it is an identifier. Now the only table in FROM list is user_role_privs and it has no such column. Now, parser realizes it is a subquery and table_name can be a correlated name. So it checks main query FROM clause list and guess what - table user_tab_columns has a column table_name. So what subquery means is select a row from table user_tab_columns, which will give as some column table_name value and then use that value in subquery, get results and compare it with same table_name value. Now, I hope, you can see that no error should be raised. And, if user_role_privs is not empty, query will return every row in user_tab_columns. If user_role_privs is empty, query will not return any rows. But again, error is neither raised nor should be raised.
    SY.

  • How to use subquery factoring ("with" clause) in OWB?

    Hi,
    Is it possible to use subquery factoring (popularly known as "with" clause) in OWB 10gR2? I have a mapping with a splitter and union-all, which generates a query that has repeated scans of the same table. Subquery Factoring would be very useful here. I think this is a very common situation, so, I hope there's a way to achieve this. (If not in this version, this would be my wishlist item for the next version.)
    Appreciate your help.
    Regards,
    Rahul

    Hi Rahul,
    I'm afraid you have to put this on your wishlist. You may put the query with the "with"-clause into a view (or table function if you need parameters) if performance is too bad. But that is somehow against the idea (and benefits) of owb.
    Another possibility is to use a temporary table and spilt the mappings into two parts: first fill the temp table, then the target table.
    Regards,
    Carsten.

Maybe you are looking for

  • Photoshop cs2 & intel-iMac

    Ive been having issues w/my iMac. I'm wondering if photoshop is causing system problems in my intel iMac. I've seen several discussions and articles that the program was not prepared for the intel switch and is the root of many iMac issues. Anyone kn

  • How SAP help me to rebuild career.

    Hello, I am a Diploma in PRINTING TECHNOLOGY working in Newspaper Production as Associate engineer. I send my resume to JKT SAP academy Kolkata they told me that I am suitable for SAP PP module. My qualification is just 10+2+Diploma. and working exp-

  • Where are my movies? Purchased movies have disappeared.

    Hi All, I have just discovered that some of my movies have disappeared from the cloud. No warning. Nothing. I had many of my movie backed up on a hard drive but it failed recently. No worries I thought. Rebuild from the cloud. Nope. It would seem tha

  • Photoshop CS4 stops loading beyond "Measuring Memory"

    Can anyone pls help as after a serious virus attack Photoshop CS4 stops loading at message "Measuring Memory". Any help appreciated. Thanks in advance!

  • How can I pause the task and resume it in some times?

    Hi all,   I have been using traditional DAQ for some times and I swtich to DAQmx recently. In traditional DAQ, I can start a task, pause it for a while and then resume the task. But in DAQmx, I didn't see the same function. Is that any way to do the