Dynamic SQL Report

Hi everybody
I want to build a dynamqi sql query to use in a report. What is dynamic is the name of the table I want to request. I have a nice item named P8-ECHELLE, a select List with a LOV returning a part of the name.
For example the select list returns "E034". I want to add this part of the name to the beginning of the name of the table which is "EVV_" in order to get the name of the table which would be "EVV_E034'.
The select would like this : SELECT * FROM SIVOA.EVV_E034
This is the code :
DECLARE
x VARCHAR2 (4000);
BEGIN
x := 'SELECT * FROM SIVOA.EVV_' || :P8_ECHELLE ;
RETURN (x);
END;
I get an error : "failed to parse SQL query: ORA-00942: table or view does not exist"
Coudl you help ?
Christian
PS : thank to D. Kubicek for his example !

This is the code.
DECLARE
x VARCHAR2 (4000);
BEGIN
x :=
'SELECT * '
|| 'FROM EMP '
|| 'WHERE 1=1 '
|| CASE
WHEN :p184_ename IS NOT NULL
THEN 'AND UPPER(ename) LIKE '''
|| UPPER (:p184_ename)
|| '''||''%'' '
ELSE NULL
END
|| CASE
WHEN :p184_deptno IS NOT NULL
THEN 'AND INSTR('':''||'
|| ''''
|| :p184_deptno
|| ''''
|| '||'':'', '':''||deptno||'':'') > 0'
ELSE NULL
END;
RETURN (x);
END;

Similar Messages

  • PLSQL processing of a dynamic sql report

    Hi there,
    I have a problem processing a dynamic sql report, specifically in referencing the PL/SQL column headings I have.
    Basically I have a report that generates one row for each project a person belongs to, and then using htmldb_item.text creates one field for each day of the week (sysdate - sysdate+6) so that people can enter their hours worked. The idea is they then press a submit button and the hours are entered into a project table something like (date_worked, project_id, hours_worked), one row for each entry.
    So I have:
    for i in 1..HTMLDB_APPLICATION.G_F01.count
    loop
    ... err... here I want to insert into the table the values(column_header, project_id, HTMLDB_APPLICATION.G_F01(i)).. but I don't know how to access that column_header value.
    Is this possible and if so, how?
    Many thanks,
    Tosh.

    that gives me the values of the text fields, but what
    I'd like to insert is the value of the column
    header... so for example:Yes, I understood what you meant. I did have a differect project_id for each INSERT in my SQL above. I guess that should have been day_id
    Since you are generating the tabular form SQL manually, you know which htmldb_item.text index corresponds to which column (which represents day_id in your case). So, use this to write 6 INSERT statements, one for each day. day_id would be a number going from 0 thru 6 where 0 represents Sunday and 6 represents Saturday.
    Bottom line: This is like generating/updating a calendar, your column headings are always fixed (Sun thru Saturday), just the date they represent would change.

  • How to rename C00n generic column names in a Dynamic SQL report

    I have a an interface whereby the user can select 1 to 60 (upper limit) columns out of 90 possible columns (using a shuttle) from one table before running a report.
    To construct the SQL that will eventually execute, I'm using a "PLSQL function body returning SQL query" with dynamic SQL. The only problem is that I have to use "Generic Column Names" option to be able to compile the code and end up with c001 to c060 as the column names.
    How can I use the names of the selected columns as the report headings rather than c001, C002... etc?
    I do not know beforehand which columns, or how many columns or the order of the selected columns.
    I know Denes K has a demo called Pick Columns but I can't access his code. I have a hunch though that he may be just using conditions to hide/show the apropriate columns.
    thanks in advance
    PaulP

    Hi Paul
    I would change the Heading Type in the Report Details screen to PLSQL and use the shuttle item to return the column values. e.g.
    RETURN :p1_shuttle;
    I'm assuming the shuttle already has a colon separated list of the column headings in the correct order?
    I hope that helps
    Shunt

  • Dynamic SQL report  on Oracle apex4.0

    Hi Everyone,
    I have two reports in one page.One is the Interactive and other is Sql report. Based on the selection of the row(using checkbox) in the interactive report, the sql report has to display the selected columns.
    Note :The report has to be loaded whenever a row is selected and without submitting a button
    Can anyone please suggest?
    I am using oracle Apex4.0
    Regards
    Raj

    I believe you store the values in the checkboxes. For example, your Interactive Report query looks like:
    SELECT '<input type=checkbox value='||OBJID||' />' AS CHECKBOX, T.*
    FROM SOME_TABLE T
    and in "Report Atributes" the CHECKBOX is displayed as "Standard Report Column".
    *1.Create a hidden check list input field.*
    It will store a list values of selected checkboxes. make it long enough, eg. 1000.
    Let's say the input name is: P000_X_CHECK_LIST
    *2. Create Dynamic Action*
    This dynamic action is supposed to fill in the P000_X_CHECK_LIST with a list of values, separated by ":" character.
    These values will be an input for the SQL report.
    Name: Update Check List
    Event: Change
    Selection Type: jQuery Selector
    jQuery Selector: input:checkbox
    Action: Set Value
    Set Type: JavaScript Expression
    function check_list() {
    var n = "";
    $(":checked").each( function () {
    n = n + (n === "" ? "" : ":") + $(this).val();
    return n;
    check_list();
    Selection Type: Item(s) - P000_X_CHECK_LIST
    *3. Adjust the "SQL report" query with this magic formula*
    AND SEARCHED_ITEM IN (
    SELECT item
    FROM (SELECT REGEXP_SUBSTR (str, '[^:]+', 1, LEVEL) item
    FROM (SELECT :P000_X_CHECK_LIST str
    FROM DUAL)
    CONNECT BY LEVEL <= length (regexp_replace (str, '[^:]+')) + 1)
    for example:
    SELECT O.*
    FROM SOME_OTHER_TABLE O
    WHERE SEARCHED_ITEM IN (
    SELECT item
    FROM (SELECT REGEXP_SUBSTR (str, '[^:]+', 1, LEVEL) item
    FROM (SELECT *:P000_X_CHECK_LIST* str
    FROM DUAL)
    CONNECT BY LEVEL <= length (regexp_replace (str, '[^:]+')) + 1)
    *4. Adjust the Dynamic Action:*
    Advanced: Event Scope: "live"
    *5. Add one more True action to the Dynamic Action:*
    Action: Refresh
    Selection type: Region
    Region: The region of the "SQL report".
    Volia!
    Best regards,
    Krzysztof

  • Erratic Report Region Behavior with Dynamic SQL Queries

    I'm running HTMLDB v 1.5.1.00.12 and I've noticed some odd behavior with report regions using dynamic SQL queries. Every so often, our testers will run a page containing a dynamic sql report region and get the following error, (despite the fact the query was working only moments ago and no other developer has touched it):
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    or sometimes
    failed to parse SQL query:ORA-01403: no data found
    The only solution I've found so far is to:
    1) Make a copy of the failed report region.
    2) Disable or delete the original failed report region.
    The new copy of the report region runs without issue.
    My search of the forums turned up the following two threads, but neither provided me with a clear explanation of the cause, and how to avoid it:
    ORA-06502:PL/SQL: numeric or value error: character string buffer too small
    Re: Import Export Error (ORA-06502)
    The columns being returned are below the 4000 character limit, and the rows being returned are far less than 32k in size.
    Could this have anything to do with the way HTMLDB is internally storing the PL/SQL used to generate the dynamic SQL Query? Is there any known issue related to this with that version of HTMLDB?
    This problem occurs without any discernable pattern or consistency, making it hard to determine where I should focus my efforts in tracking down the cause.

    Hi all,
    My report seems to be behaving correctly once i set it to "Use Generic Column Names (parse query at runtime only)" :)
    Cheers,
    Joel

  • Multiple Parameter Dynamic Query/Report

    I'm very much a newbie to both APEX and SQL. I want to create a page with two regions, one used to hold parameters (LOV Select Lists), and one to reflect a dynamic SQL report including filtering the results using the values of the items in the select lists.
    I can do this with one Parameter/LOV select list - but am not clear on how to code for multiple parameters.
    Can someone give me an example on how to code the query, to include multiple parameters (P1_Empl, P1_AssetNo, P1_AssetType, etc)? The query with 'null' parameters/filters gives you all records; with any or many parameters acting as filters the query and resulting report would reflect the value of the filters.
    In addition, is there a specific type of region that needs to be used for the report region?
    Implied is the question - how do you handle the initial page view, so no error messages are seen - I'd like to get all records as a default.
    Thanks
    Rich

    sbkenned,
    The referenced sql for that report gives me problems.
    [ P3_Department_ID is the LOV of departments ]
    [ Null allowed and null return value is -1 ]
    <code>
    SELECT e.EMPLOYEE_ID,
    e.FIRST_NAME,
    e.LAST_NAME,
    e.HIRE_DATE,
    e.SALARY,
    e.COMMISSION_PCT,
    calc_remuneration(salary, commission_pct) REMUNERATION,
    e.DEPARTMENT_ID,
    d.DEPARTMENT_NAME
    FROM OEHR_EMPLOYEES e,
    OEHR_DEPARTMENTS d
    WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID(+) AND
    (e.DEPARTMENT_ID = :P3_DEPARTMENT_ID or
    (e.DEPARTMENT_ID is null and nvl(:P3_DEPARTMENT_ID,'-1') = '-1'))
    </code>
    The where clause: I'm guessing it is checking e.deptno = d.deptno
    but then what is (+)?
    can I use the '(+) and' to add on sections for each select list/parameter?
    In the paran part of the where clause, I get the first part and the use of 'or' - but I'm not sure what the last statement is doing.
    e.deptno is null AND ?? if there is a null value in P3_Department_ID return -1 otherwise return -1 ??
    I'm lost at that point as I clearly don't understand the syntax.
    Would you suggest multiple clauses in a where statement in order to add multiple filter values, and how do I handle nulls so those filters are not used/relfected?
    I am not using a self submitting LOV select list - I am using a button to refresh the query region manually
    I am comfortable with using an interactive report, but that interface is not what I need to present.
    As I indicated - I'm weak in the SQL area and need an example on how to code this type of query.
    Thanks.
    Rich

  • Can we use Dynamic SQL in Oracle Reports ?

    Hi ,
    Can we use Dynamic SQL in Oracle Reports ?
    If yes please give some examples .
    Thanx
    srini

    I believe the built-in package SRW.Do_Sql is what you are looking for
    Example from the document:
    /* Suppose you want to create a "table of contents" by getting the
    ** first character of a columns value, and page number on which its
    ** field fires to print. Assume that you want to put the "table of
    contents"
    ** into a table named SHIP. You could write the following construct:
    DECLARE
    PAGE_NO NUMBER;
    PAGE_FOR INDEX NUMBER;
    SORT_CHAR CHAR(1);
    CMD_LINE CHAR(200);
    BEGIN
    SORT_CHAR := :SORT_NAME ;
    IF :CALLED = Y THEN
         SRW.GET_PAGE_NUM(PAGE_FOR_INDEX);
         SRW.USER_EXIT(RWECOP PAGE_FOR_INDEX
         P_START_PAGENO);
         SRW.MESSAGE(2,TO_CHAR(:P_START_PAGENO));
    END IF;
    SRW.GET_PAGE_NUM(PAGE_NO);
    CMD_LINE := INSERT INTO SHIP VALUES
                          (||SORT_CHAR||,||TO_CHAR(PAGE_NO)||);
    SRW.MESSAGE(2,CMD_LINE);
    SRW.DO_SQL(CMD_LINE);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
            NULL;
      WHEN SRW.DO_SQL_FAILURE THEN
            SRW.MESSAGE(1,FAILED TO INSERT ROW INTO SHIP TABLE);
      WHEN OTHERS THEN
           COMMIT;
    END;

  • Report using ref cursor or dynamic Sql

    Hi,
    I never create a report using a ref cursor or a dynamic sql. Could any one help me to solve the below issue.
    I have 2 tables.
    1. Student_Record
    2. Student_csv_help
    Student_Record the main table where the data is stored.
    Student_csv_help will contain the all the column names of the Student_record.
    CREATE TABLE Student_CSV_HELP
    ENTRY_ID NUMBER,
    RAW_NAME VARCHAR2(40 BYTE),
    DESC_NAME VARCHAR2(1000 BYTE),
    IN_OUTPUT_LIST VARCHAR2(1 BYTE)
    SET DEFINE OFF;
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (1, 'S_ID', 'Student ID', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (2, 'S_Name', 'Student Name', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (3, 'S_Join_date', 'Joining Date', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (4, 'S_Address', 'Address', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (5, 'S_Fee', 'Tution Fee', 'N');
    commit;
    CREATE TABLE Student_record
    S_ID NUMBER,
    S_Name VARCHAR2(100 BYTE),
    S_Join_date date,
    S_Address VARCHAR2(360 BYTE),
    S_Fee Number
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (101, 'john', TO_DATE('12/17/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94777', 2000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (102, 'arif', TO_DATE('12/18/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94444', 3000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (103, 'raj', TO_DATE('12/19/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94555', 2500);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (104, 'singh', TO_DATE('12/20/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94666', 2000);
    Commit;
    Now my requirement is:
    I have a form with Student_record data block. When i Click on print Button on this form. It will open another window which has Student_CSV_HELP.DESC_NAME and a check box before this.
    The window look like as below:
    check_box       DESC_NAME+
    X                   S_ID+
    --                   S_Name+
    X                   S_Join_date+
    X                   S_Address+
    --                  S_Fee+
    X  means check box checked.+
    --  means check box Unchecked.+
    After i selected these check boxes i will send 2 parameters to the report server
    1. a string parameter to the report server which has the value 'S_ID,S_Join_date,S_Address' (p_column_name := 'S_ID,S_Join_date,S_Address');
    2. the s_id value from the student_record block (p_S_id := '101');
    Now my requirement is when i click on run. I need a report like as below:
    Student ID : 101+
    Joining Date : 12/17/2009 08:00:00+
    Address : CA-94777+
    This is nothing but the ref cursor should run like as below:
    Select S_id from student_record block S_id = :p_S_id;
    Select S_Join_date from student_record block S_id = :p_S_id;
    Select S_Address from student_record block S_id = :p_S_id;
    So, according to my understanding i have to select the columns at the run time. I dont have much knowledge in creating reports using ref cursor or dynamic sql.
    So please help me to solve this issue.
    Thanks in advance.

    Plain sql should satisfy your need. Try ....
    Select S_id, S_Join_date, S_Address
    from student_record
    where S_id = :p_S_id

  • Applying a Template to a Dynamic PL/SQL Report

    I have an application in which there are several reports, all based on the wizard and using standard templates.
    One of my reports, however is a Dynamic PL/SQL Report, using htp.print statements to create the output.
    I'm not quite sure, how I can specify that I want to use the same template as the rest of my reports, so as to maintain the look and feel of the whole application.
    Can someone tell me how this is done, or where I can read about it?
    Thank you.

    Sergio,
    I have a table with two columns I want to display. The columns aren't wide but there are 15 or 20 rows. What I would like is that after 10 rows the report starts another set of colums beside the first ones. The standard report continues on down so you have to scroll down to see the bottom. I'm not sure if my explanation is clear so instead of:
    1 info1
    2 info2
    3 info3
    4 info4
    5 info5
    6 info6
    I want:
    1 info1 4 info4
    2 info2 5 info5
    3 info3 6 info6
    Not being too picky, it could also be:
    1 info1 2 info2
    3 info3 4 info4
    5 info5 6 info6
    I don't see a way of doing this with standard reporting so a PL/SQL report seems to be the way to go (which works fine except for the formatting). Sorry if I've just missed it in the options. I'd prefer to do it using standard HTMLDB
    Thanks.
    Paul

  • 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.

  • How to obtain IR report dynamic SQL in Apex 4.0

    Hello,
    I have 2 regions on the same page
    Interactive Report –
    Chart (Flash Chart) – This is a sub region of the above
    Now the requirement is when user applies a filter to the interactive report I would like to apply the same filter criteria to the flash chart so that data representation in flash chart matches with the IR report content. I am fairly new to the Apex, apologies if  used any apex terminology in correctly
    Appreciate if you  can point me in the right direction
    Thank you
    -Raj

    Hello , I did some research how to achieve this , one way is to get the IR report dynamic sql using APEX_IR.GET_REPORT package and apply the same sql for the chart  so that the chart representation will match with the IR report data, But the challenge is as i am using the APEX 4.0.0.00.46 version, the APEX_IR package is not available in that version , Any other way we can achieve this  in Apex 4.0??
    Thanks
    -raj

  • Dynamic SQL for creating report in portal

    Has anyone had to create report in Portal using dynamic sql. That is you build up the query commands depending on the parameters entered by the user.
    E.g the columns displayed will be what the users has selected in the parameter form.
    Urgent reply please,
    Femi

    Hi,
    You can use SQL based reports to do this. The report should have a bind variable. The bind variable is used for the users to enter their values and query is built using the value in the bind variable. The user should enter the value of the bind variable from the customization screen.
    Here is an example
    select * from scott.emp
    where deptno = :vdept
    Here vdept appears in the customization screen and user should enter a value for this and run the report.
    Thanks,
    Sharmila

  • Pop up text on clicking link on a sql report

    Hi
    I'm using apex 3.2
    I've a sql report like below
    taskId(edit) Task_details Notes owner .....
    What I want to do is if I click on taskId which is edit link ,pop up text box should open where I can add notes to that row.
    How can I achive this?
    Thanks in advance

    Hi,
    Take a look at the following blog posts and see if they can help you get what you are looking for (there are sample applications in them showing the functionality):
    http://monkeyonoracle.blogspot.com/2010/07/modal-pop-up-with-dynamic-actions.html
    http://www.danielmcghan.us/2008/12/popup-in-report.html
    Hope that's useful for you.
    Regards,
    Sergio

  • [Interface] - Passing variety parameters/input to PL/SQL report

    Hi,
    I've the PL/SQL report which can allow passing in the parameter, i use '&'.
    the report is given to the end user who do not have the IDE for PL/SQL. the machanism of the report is generated into the spool file and import into excel format.
    now i am wondering how to create a tool using SQL or PL/SQL to allow the end user to choose the parameter(s) dynamically and passing into the PL/SQL to generate the report based on the input selected.
    the parameters like below:
    package code :
    week no :
    year :
    department :
    all the above parameters, the data would be selected from the existing lookup table. the user is allow to select more than 1 input for specified parameter for instance i want to spool report for week 1 until week 5.
    pls advise any solution on this topic. thanks

    hi scoot,
    thank for reply.
    yep, i'm using sql*plus and also sql navigator 4.0 .
    the user don't have the software to interact. i'm thinking of build an simple interface using VB and passing in the parameter then initiate the sql*plus to run the program in background mode.
    but if you have any other solution which not need to use other software to wirte such program , pls let me know immediately. thank

  • Dynamic sql and ref cursors URGENT!!

    Hi,
    I'm using a long to build a dynamic sql statement. This is limited by about 32k. This is too short for my statement.
    The query results in a ref cursor.
    Does anyone have an idea to create larger statement or to couple ref cursors, so I can execute the statement a couple of times and as an result I still have one ref cursor.
    Example:
    /* Determine if project is main project, then select all subprojects */
    for i in isMainProject loop
    if i.belongstoprojectno is null then
    for i in ProjectSubNumbers loop
    if ProjectSubNumbers%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    else
    for i in ProjectNumber loop
    if ProjectNumber%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    end if;
    end loop;
    /* Open ref cursor */
    open sql_output for SqlStatement;
    Thanks in advance,
    Jeroen Muis
    KCI Datasystems BV
    mailto:[email protected]

    Example for 'dynamic' ref cursor - dynamic WHERE
    (note that Reports need 'static' ref cursor type
    for building Report Layout):
    1. Stored package
    CREATE OR REPLACE PACKAGE report_dynamic IS
    TYPE type_ref_cur_sta IS REF CURSOR RETURN dept%ROWTYPE; -- for Report Layout only
    TYPE type_ref_cur_dyn IS REF CURSOR;
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn;
    END;
    CREATE OR REPLACE PACKAGE BODY report_dynamic IS
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn IS
    ref_cur_dyn type_ref_cur_dyn;
    BEGIN
    OPEN ref_cur_dyn FOR
    'SELECT * FROM dept WHERE ' | | NVL (p_where, '1 = 1');
    RETURN ref_cur_dyn;
    END;
    END;
    2. Query PL/SQL in Reports
    function QR_1RefCurQuery return report_dynamic.type_ref_cur_sta is
    begin
    return report_dynamic.func_dyn (:p_where);
    end;
    Regards
    Zlatko Sirotic
    null

Maybe you are looking for

  • Dopacity registry key deletes itself when closing acrobat 9.5.1

    Hello, Everytime the user closes out of acrobat, the registry key (dopacity) deletes itself.  When you relaunch it, it creates a new dopacity key with the value of 0.0005, then the typewriter tool does not work.  We manually change that key to 1.0 an

  • Using Thunderbolt Display with Alienware Laptop

    I want to also use my thunderbolt display with a m18x alienware laptop which has HDMI out and a mini display port.  Is there any way I can use this display with this laptop either directly or with an adapter? Thanks

  • Questions for FI workshop

    Hello folks, I want to know if you guys have a question bank to start conducting workshop and create Blueprint for GL,AP, AR process. Any help would be appreciated. Best Regards Shine

  • F110 - Sending CC & Paying CC

    Hi Guys, While carrying out F110 payments from one company code to the other, initially I have made the settings in FBZP for sending CC and Paying CC. In F110 while entering the parameters, under Company code, I am giving ABCD,XYZ1. I want ABCD to be

  • PO cancel

    Hi While cancelling PO, we get a message "Express document - update was terminated'. Pls help regards