Dynamic Query in Report Builder

HI
I have a doubt:
I need to receive a parameter in my report and I need this parameter in the query, that means, I need to create a dynamic query depending on the value that I receive in one of the parameters that has my report.
I tried to use the resource of Searching by Reference Cursor tool, it is a blue circle in the Data Model View of Report Builder.
When I click this tool, I have an initial code, It is:
function QR_1RefCurDS return <RefCurType> is
begin
end;
In PL/SQL I tried to create to test and to play, this code:
Note: If you want to try only to test, it is simple and works:
create or replace package TEST_REFCURTYPE as
type refcurtype is ref cursor;
function TEST_REFCURTYPE (P_DATE_TO nvarchar2) return refcurtype;
end;
create or replace package body TEST_REFCURTYPE as
function TEST_REFCURTYPE (P_DATE_TO nvarchar2)
return refcurtype is
refcur refcurtype;
mysql varchar(1000);
begin
If P_DATE_TO is not null then
mysql := 'select '''|| P_DATE_TO ||''' from dual';
else
mysql := 'select sysdate from dual';
end if;
open refcur for mysql;
return refcur;
end;
end;
The problem is to pass this example of code to the function QR_1RefCurDS, I do not have a place to make reference to the type:
type refcurtype is ref cursor;
I tested the Unit Program in the Report Builder but it did not work, because all the code I try to write and create, for example in the Event BEFORE REPORT, it opens  Funcion( ) …., and I can not make reference to the type refcurtype inside a Function( ).
Would you help me please?
Or there is another way to make a dynamic query in the Report Builder?
Sorry for my English, I am a Brazilian living in Spain.

Hi,
you can use lexical parameters in your queries. Instead of a ":" use in the query before the parameter a "&". Then the parameter stands for a part of the query and not for a value (Bind parameter). In the before report trigger you can set this parameters. They can contain parts of SQL like order or where. Make sure that the default value for this lexical parameters are set to get a valid query.
SELECT ENAME, &p_column as COL2 FROM EMP &p_order
and in the trigger something like
IF :p_which_column = 1 THEN
:p_column := 'SAL'
ELSE
Saludos
Rainer

Similar Messages

  • Dynamic queries in report builder 6i ( ref cursor query )

    Hi everyone,
    My requirement is that I want to create a report where the query is dynamic. The dynamic part will be known at runtime as it is being passed via a parameter. My query looks like this :
    select * from emp where sal :p1 :p2
    Possible values for :p1 are - '>', '<', '>=', '<=', '=', '!='
    Possible values for :p2 are - any value entered by the user
    I tried creating a query in report builder based on a ref cursor. But it does not allow me to create the query for the ref cursor dynamically. That means I have to hardcode the query in the program.
    I tried using place holder columns without success.
    Can someone please help me ?
    Regards,
    Al

    Hi,
    You can use lexical paramters in the sql query
    x - char - parameter
    select * from emp &x
    you need to pass the value for x in the parameter as
    'where sal < 1234'.
    Note : Lexical variable should be of char datatype.
    This is an alternative to the ref cursors.
    This works. Hope this is clear.

  • User inputted letters with dynamic fields in Report Builder

    I'm proactively trying to get certain aspects off our hands in IT and more specifically, the way letters are generated through ColdFusion.  Right now we are using activeX controls (with some vbscript and asp pages) through IE to do Word mail merges for letter's for our students.  We would like the user to be able to change these letters by themselves through our web application and have them saved in our database so they can be stored as a future template.
    Now I'm new to Report Builder and have a few examples to show my colleagues, but I'm having troubles being able to dynamically insert the student's name (for example) into the report.
    So basically I have an empty template with a huge dynamic box for the text which reads #param.MessageBody# that comes from a textarea within the cfm page.  That works, but taking it one step further, I want to replace all instances of "%%StudentName%%" within that MessageBody with the actual student's name.
    Since I cannot loop over the report and do my usual ReplaceNoCase(lMessageBody, "%%StudentName%%", Trim(ReportQueryLetters.StudentName), "ALL")>, how can I put this into a built-in function into the report?
    I figured the function needs to be in <cffunction name="BeforeExport"> and while a simple display of the message works perfectly, I cannot get my replace line to work.  I am passing the query to Report Builder instead of having it built-in, is that my problem?!  I would prefer if it was external to save my stored procedures if I can.  Is there any way to call the query to get that line to work?!
    The code inside the cffunction (in report Builder):
    <cfargument name="lTextArea">
    <cfset lTextArea = #form.frmTextArea#>
    <cfset lTextArea = ReplaceNoCase(lTextArea, "%%StudentName%%", Trim(ReportQueryLetters.StudentName), "ALL")>
    <cfreturn lTextArea>
    The error:
    Element STUDENTNAME is undefined in REPORTQUERYLETTERS.           

    Sorry for the late reply, just got back from vacation.
    I don't think you use ReportQueryLetters for the query.  it should be
    query.StudentName
    Also, you can have an intermediate step on the page that receives the
    MessageBody and change the MessageBody before passing it as a parameter to the
    report.

  • Add subquery to main query in Report Builder 6i

    Usually, when you add a subquery to an existing query in a report, you'll see the query in data model marked by a paper clip icon with a forward slash across it (means "Subquery Inside"). All current field names in current query (except CF and CS) will have a '1' appended after it (CF and CS fields are not affected), but in your sql, the column names stay the same. So there is an out-of-sync situation with the column names.
    To fix this:
    1) before change anything, back up old report somewhere else
    2) copy the original query somewhere else as backup
    3) open the query in Report Builder
    4) wipe out the query, replace it by "select 1 from dual" to reset it and press ok.
    5) replace "select 1 from dual" with your new query with an embedded subquery.
    6) All field names will be without the '1' appendix.
    7) check all the CS fields, the source should be reset to null. Redefine the CS fields using backed up report as reference. CF fields are not affected.
    8) move the fields and restore the break orders according to backed up report.
    9) Recompile whole report.
    10) save report again and you're done.
    Maybe you don't need this in the latest version of Report Builder, but in 6i, this is what I do.

    If you use aliases for your item names in your original query you avoid this problem....
    eg
    Select field1 item1, field2 item2 from table.....
    item 1 and item2 will stay in your layout between query changes.
    D

  • How do i call a :cp_ or a :cf in a query in reports builder?

    Hi, i got a report.
    i included a function in 1 of my queries in reports builder but the report is running very long now.
    so i tryed to put the function in that query in a :cf (formula column) and call the :cf in my query but its not picking up the value.
    am i missing something?
    or is there another way?
    please help asap.
    thanks....

    in my data model in reports builder :
    i have a main query with about 5 other queries.
    in one of the 5 queries i am getting tax information, which contains unions, i have just pasted one of the unions.
    If you look in this query (in bold) you will see i tried inderting the database function, but it runs too slow.
    then i tried to insert the same function in a cf, and then tried to call the cf in my query, just to get the value (tax_start_date).
    the cf doesn't affect the performance and i can see the value in the xml but cant seem to call the value in my query.
    SELECT distinct decode(pbv.balance_name,'Asset Purchased at Reduced Value', 'General Fringe Benefit',pbv.balance_name) balance_name,
    '(' ||'YTD'||')',
    decode(pbv.effective_date,:effective_date,pbv.effective_date,:effective_date)effective_date,
    pbv.assignment_id,
    pbv.ASSIGNMENT_ACTION_ID,
    pbv.PAYROLL_ACTION_ID,
    sum(pbv.VALUE) value,
    FROM pay_balance_values_africa_v pbv
    WHERE (
    pbv.balance_name = 'Bonus Provision'
    OR pbv.balance_name = 'Non Taxable Subsistence'
    OR pbv.balance_name = 'Taxable Subsistence RFI'
    OR pbv.balance_name = 'Taxable Subsistence NRFI')
    AND pbv.database_item_suffix in ('_ASG_TYTD')
    and pbv.VALUE <> '0'
    and pbv.effective_date = (select max(pbva.effective_date) from pay_balance_values_africa_v pbva--, xxfrgpay_legis_tax_year_v lty
    WHERE --pbva.BUSINESS_GROUP_ID = lty.BUSINESS_GROUP_ID
    pbva.assignment_id = :assignment_id
    and pbva.balance_name = pbv.balance_name
    and pbva.database_item_suffix in ('_ASG_TYTD')
    --  and  pbva.effective_date between '01-MAR-10' and :effective_date-- '31-DEC-2010'
    and  pbva.effective_date between (apps.xxfrg_africa_tax_reg.get_tax_dates(0, null, null, null, pbva.effective_date) ) and :effective_date
    --and  pbva.effective_date between  :cf_tax_start_date and :effective_date*                         )
    and pbv.assignment_id = :assignment_id
    and pbv.business_group_id in (81,84,86,88)
    group by pbv.balance_name,pbv.effective_date,pbv.assignment_id,pbv.ASSIGNMENT_ACTION_ID, pbv.PAYROLL_ACTION_ID
    ORDER BY 2

  • Parameter in form for dynamic query in report

    Hello,
    I want to send parameters to report for replacing a dynamic query. I don't know how to make it...
    1.I want my select statement like
    select * from emp
    &p_where_clause
    2.I want to transfer parameters to report to replace the &p_where_clause.
    3.I know I should create a parameter list first, and then use add_parameter built-in to add the parameter, but what I don't know is the correct format of the add_parameter statement.
    4.I know the common format is add_parameter(paramlist,'TEXT_PARAMETER',value) , is it the same format if I want to transfer a select statement to report such as "where deptno in ('25','28','30')" for replacing &p_where_clause in report?
    Thanks in advance
    Joseph

    I appreciate your reply, but I am still a little confused...
    Actually, I want to pass the where clause to report by different condition. Such as when the user choose the deptment 1, then I can transfer the "where dept_no = '1' and empno > 500", or user choose the deptment 2, I can transfer "where dept_no = '2' and company = '0001'". What I want is to pass different where clause to report according to different condition.
    So is it right the statement should be like
    DECLARE
    vWhere1 varchar2 := 'where dept_no = "1" and empno > 500';
    vWhere2 varchar2 := 'where dept_no = "2" and company = "0001"';
    BEGIN
    IF choose = 1 THEN
    ADD_PARAMETER(&P_WHERE_CLAUSE, TEXT_PARAMETER, vWhere1);
    ELSIF choose = 2 THEN
    ADD_PARAMETER(&P_WHERE_CLAUSE, TEXT_PARAMETER, vWhere2);
    END IF;
    END;
    THANKS AGAIN!!
    Joseph

  • !!!urgent:pass whole query to reports builder

    i have a query in jsp(Java Server Pages) i.e
    var whereSession = "<%=session.getAttribute("whereClause")%>";
    the query is contained in the whereSession variable;
    select t1.document_id,
    t1.document_name,
    t2.file_nr,
    t.folder_owner,
    t.folder_name,
    (initcap(t4.firstname) || ' ' || initcap(t4.surname)) author,
    t7.name company,
    t8.fy_short_name fy
    from ai_library_folder t,
    ai_document t1,
    ai_document_type t2,
    sa_dba.sa_employee t3,
    sa_dba.sa_person t4,
    sa_dba.sa_user t5,
    ai_library_type t6,
    sa_dba.sa_company t7,
    sa_dba.sa_fiscal_year t8
    where t3.id = t5.employee_id and t4.id = t3.person_id and
    t5.id = t1.created_by and t1.folder_id = t.folder_id and
    t2.id = t1.doc_type_id and t6.id = t.library_type_id and
    t7.fy = t8.id and t7.id = 1 and t7.fy = 5 and t.folder_id = 7
    order by t1.document_id
    this query above only changes in the where clause as i append other links columns to it,so the problem i'm send the whole query as a session to reports builder,i'm using a lexical parameter for the 'where' statement..."my questions how i handle the whole query above to generate this report without altering it in the jsp as i have already design the report on the stardand that i do not append anything to it....hope this makes sense."

    i have a query in jsp(Java Server Pages) i.e
    var whereSession = "<%=session.getAttribute("whereClause")%>";
    the query is contained in the whereSession variable;
    select t1.document_id,
    t1.document_name,
    t2.file_nr,
    t.folder_owner,
    t.folder_name,
    (initcap(t4.firstname) || ' ' || initcap(t4.surname)) author,
    t7.name company,
    t8.fy_short_name fy
    from ai_library_folder t,
    ai_document t1,
    ai_document_type t2,
    sa_dba.sa_employee t3,
    sa_dba.sa_person t4,
    sa_dba.sa_user t5,
    ai_library_type t6,
    sa_dba.sa_company t7,
    sa_dba.sa_fiscal_year t8
    where t3.id = t5.employee_id and t4.id = t3.person_id and
    t5.id = t1.created_by and t1.folder_id = t.folder_id and
    t2.id = t1.doc_type_id and t6.id = t.library_type_id and
    t7.fy = t8.id and t7.id = 1 and t7.fy = 5 and t.folder_id = 7
    order by t1.document_id
    this query above only changes in the where clause as i append other links columns to it,so the problem i'm send the whole query as a session to reports builder,i'm using a lexical parameter for the 'where' statement..."my questions how i handle the whole query above to generate this report without altering it in the jsp as i have already design the report on the stardand that i do not append anything to it....hope this makes sense."

  • How do you call dynamic fields in Report Builder

    I have some fields that they were filled in a dynamic way,
    and I want to make some calculations using the information that was
    populated in this field. When I put the name of the field in my
    calculation control, it did not see find the field control.
    Does anyone know how can I call the field control? The
    information is not part of any particular column of the
    query.

    check out the Oracle Portal Tutorial White Paper (http://technet.oracle.com/docs/products/iportal/listing.htm#tutcase), there is a section where they build a report with repeating fields

  • Retrieve All records and display in Report using CAML query in Report Builder if Parameter value is blank

    Hello Experts,
    i have created a report where i have one parameter field where user will pass parameter(e.g. EmpId). As per parameter record will fetched to report if no parameter is passed then it will display all records. I have done it by taking SqlServer Database as datasource.
    by using Following method
    Now i would like to do it by taking Sharepoint List as Datasource. For that what would be the CAML Query.
    Here is my existing CAML query.
    <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ListName>Employees</ListName>
      <ViewFields>
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />
        <FieldRef Name="LastName" />
        <FieldRef Name="FullName" />
        <FieldRef Name="UserName" />
        <FieldRef Name="Company" />
      </ViewFields>
      <Query>
        <Where>  
    <Eq> 
        <FieldRef Name="Title" />
      <Value Type="Text">    
       <Parameter Name="EmployeeId"/>    
    </Value>
    </Eq>                  
        </Where>
      </Query>
    </RSSharePointList>
    The above code is working if i am passing an employeeId to Parameter. If nothing is passed, it is Not retrieving any record.
    Please suggest
    Thank you
    saroj
    saroj

    Your problem follows the well-established pattern of using an "All" parameter filter in SSRS. There are a few approaches depending on the size of your data. The easiest one is to return all data from CAML and then filter it within SSRS, the following thread
    provides some examples,
    http://stackoverflow.com/questions/18203317/show-all-records-some-records-based-on-parameter-value.
    Other options include passing all of the possible values within the CAML query when "All" is selected, using multiple Report Files to distinguish between both CAML queries, or to use multiple datasets with some logic to show/hide the correct one.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Problem with dynamic query in Forms Builder

    Hi,
    I need in forms builder cursor in procedure which parameter is a whole query. But i stuck when i wanna give some text in signs '' to procedure.
    I wanna give like test('select ' ||'test' || ' from dual');
    But this is not good beacuse it is missing ''.
    Query which procedure get is select test from dual.
    The right sql would be select 'test' from dual.
    How could i pass signs '' to procedure.
    Any ideas.
    Thanks in advance.

    test('select ''' ||'test' || ''' from dual');Francois

  • Dynamic query in reports region(multiple condition)

    Hi I have this sql query in the report region. And everytime I will run the report and choose to put a value on :P3_REQUESTID and the rest of the variables to null.It doesnt display the report.The same goes to other variables except for :P3_OOTSELECT.
    If I choose to put a value on :P3_OOTSELECT and the rest to null, thats the only time that report will be displayed.
    What am I missing here?
    SELECT req_id,
    order_no,
    cust_nm,
    cust_req_type,
    entered_by,
    alt_ref,
    decode(cnt_rfs,null,null,'Yes')RFS,
    rec_id
    FROM oot_curr_stats
    WHERE (trunc(create_dt,'MONTH') like :P3_OOTSELECT OR
    trunc(create_dt) between to_date(:P3_FROMDT,'dd/mm/yyyy') AND to_date(:P3_DATETO,'dd/mm/yyyy'))
    AND req_id like '%'||:P3_REQUESTID||'%'
    AND sla_tag like :P3_SLATAG
    Thanks,
    acinorev

    Veronica (?),
    It doesnt display the report.
    What do you mean by that? The report query doesn't execute? Or it does execute and shows "no data found" or something?
    If you "choose to put a value on :P3_REQUESTID and the rest of the variables to null" then this part of the predicate won't match any rows (I'll replace the null bind variables with null):
    (trunc(create_dt,'MONTH') like null OR
    trunc(create_dt) between to_date(null,'dd/mm/yyyy') AND to_date(null,'dd/mm/yyyy'))
    Then you AND that with other terms but by then it's too late.
    Perhaps I misunderstood.
    Scott

  • Main Query modification result Report builder crash [Solved]

    Hi,
    I want to modify main Query of report builder because (it shows two columns which are not generated by query and when I run report it raises error that columns not found) but when I modify the query it result in report builder crash, plz give me any solution, I had experience same issue a month ago and I created new query with all formula columns but this time I have too much CF and CP columns is there any way to drop it from one group to another.
    Thanks and Regards, Khawar.
    Details:
    OS windows XP/2000
    Report Builder 10.1.2.0.2
    ORACLE Server Release 10.1.0.4.2
    Oracle Procedure Builder 10.1.2.0.2
    Oracle ORACLE PL/SQL V10.1.0.4.2 - Production
    Oracle CORE     10.1.0.4.0     Production
    Oracle Tools Integration Services 10.1.2.0.2
    Oracle Tools Common Area 10.1.2.0.2
    Oracle Toolkit 2 for Windows 32-bit platforms 10.1.2.0.2
    Resource Object Store 10.1.2.0.2
    Oracle Help 10.1.2.0.2
    Oracle Sqlmgr 10.1.2.0.2
    Oracle Query Builder 10.1.2.0.2 - Production
    PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
    Oracle ZRC 10.1.2.0.2
    Oracle XML Developers Kit 10.1.0.4.2 - Production
    Oracle Virtual Graphics System 10.1.2.0.2
    Oracle Image 10.1.2.0.2
    Oracle Multimedia Widget 10.1.2.0.2
    Oracle Tools GUI Utilities 10.1.2.0.2
    Message was edited by:
    S. Khawar

    Hi,
    I saved the report in JSP format and did the required change and it works great.
    Regards, Khawar.

  • Dynamic Sql In Report

    Hello
    Can i use dynamic sql in report builder , so as to allow user-defined reports .
    Thanx
    Shrikant

    read in the help system about lexical variables (these are variables with & at the begining).
    So you can define a query as select &P_1 where you get P_1 as a parameter.

  • Dynamic Queries in reports 6i

    Hi, I was wondering if its possible to build a dynamic query on reports 6i. on the report wizard I cant get a user parameter...
    here is what im trying to do: I have a query where the fileds am retrieving are always the same, what its going to change is the where clause, it can be like betwwen 2 different dates ot it also could be a lot of ORs, like, Company_ID = 1 or Company_ID = 2 and such.
    Thanks

    yes, the thing is when I build the query on the report wizard it goes like this:
    select field1,field3, field4 from Table
    where p_clause
    so I get an error, and the query cannot be build like that, it says ORA-00920 invalid relational operator Where p_clause ==>
    So I thing my problem basically is how to build the query... any idea on how to do it? thanks
    can you explain me how this After Parameter works a little bit more
    Edited by: user10798811 on Mar 24, 2009 1:11 PM

  • Comma separated output using report builder

    Hi Experts,
    I am working with EBS 11.5.10, database 9i, and report builder 6i. I have a XML Publisher report, with output type EXCEL, which is working fine. But if i get huge data like 1million, 2million, it's not able accommodate the output in EXCEL. Since it's EXCEL 2003, it can't handle data more than it's capacity(i think 60,000 rows).
    So we thought, if we can generate the output in CSV file with comma separte, then we can open the file in EXCEL 2007. Could somebody help me how to generate the CSV output using report builder 6i.
    or is there any work around to our problem, kindly help me, it's urgent.

    Hi,
    Not sure if report builder can be made to generate csv output.
    But you can create a PLSQL Report. Just use the query of Report Builder and write a Plsql procedure based on this query
    -Idris

Maybe you are looking for

  • Add java classes as Additional Classes to web service and JAXB 2.0 usage

    Hi, I start using JDeveloper 11g TP3 to create web service. I encounter two problems. 1. I created a schema file as the following, <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://FromWSDL/" xmlns:xsd="http://www.w3.org/2001/X

  • ACCESS used in Java

    by using Java and MS Access, i created a small system, which can read/write information from/to tables in database Access. I run this system in windows environment. it runs well. i gave this system to another guy, who runs Java in Linux environment.

  • Restricting vendors -any user exits please?

    Hi, I have a requriement where while creating Vendors they have configured in such a way that it has to be approved for all the create and change vendors. since there is some sensitive information like bank accounts and names . now we have changed th

  • No Database Selected - error when running queries

    Hi all, I have just got a shiny new macbook at work. For some reason whenever I try to run a query I receive the error "No Database Selected". I am connected, I have even tried including a "USE MyFancySchema;", but to no avail. I am using Version 3.0

  • Mac OS X system freeze and crash

    I have a MacBook (est. 3 years old) with Mac OS X 10.6.8 installed.  Last night, my computer froze (the mouse wasn't functional, I couldn't use short keys, there was no spinning wheel, it was totally unresponsive).  I did a manual reboot by holding d