Dynamic Query for 'Select IN' -- URGENT!!!

I've got the following Select statement -
SELECT Employee_Name, SSN FROM Company
WHERE EMPLOYEE_NAME IN (c_Employee_Name) ;
Here c_Employee_Name is a Returned RefCursor from another function. It gives error as Type mismatch.
Is there anyway I can run one SELECT statement for all the Employee_Name returned by the function?
Any sample code will be great.
Thanks a lot,
Suman

If you have a packaged function that returns a ref cursor,
something like this:
CREATE OR REPLACE PACKAGE package_name
AS
  TYPE c_employee_name IS  REF cursor;
  FUNCTION function_name
    (p_tables      IN  VARCHAR2,
     p_columns     IN  VARCHAR2 DEFAULT '*',
     p_where       IN  VARCHAR2 DEFAULT ' 1 = 1 ',
     p_others      IN  VARCHAR2 DEFAULT NULL)
    RETURN package_name.c_employee_name;
END package_name;
CREATE OR REPLACE PACKAGE BODY package_name
AS
  FUNCTION function_name
    (p_tables      IN  VARCHAR2,
     p_columns     IN  VARCHAR2 DEFAULT '*',
     p_where       IN  VARCHAR2 DEFAULT ' 1 = 1 ',
     p_others      IN  VARCHAR2 DEFAULT NULL)
    RETURN package_name.c_employee_name
  IS
    v_sql              VARCHAR2 (4000) := NULL;
    v_results          package_name.c_employee_name;
  BEGIN
    v_sql :=
       ' SELECT ' || p_columns
    || ' FROM '   || p_tables
    || ' WHERE '  || p_where || ' '
    || p_others;
    OPEN v_results FOR v_sql;   
    RETURN v_results;
  END function_name;
END package_name;
Then, you can use a procedure, something like the
one below, to call the function and loop through
the ref cursor to concatenate a string of employee
names to be used in the select statement.  You can
then open another ref cursor for that select statment
and process the results however you like.  I used
dbms_output in the following example:
CREATE OR REPLACE PROCEDURE procedure_name
AS
  c_employee_names  package_name.c_employee_name;
  v_employee_name   company.employee_name%TYPE;
  v_employee_names  VARCHAR2 (4000) := NULL;
  v_delimiter       VARCHAR2 (1) := NULL;
  v_sql             VARCHAR2 (4000) := NULL;
  TYPE cursor_type IS REF CURSOR;
  cursor_name cursor_type;
  v_ssn             company.ssn%TYPE;
BEGIN
  c_employee_names := package_name.function_name
                        ('company', 'employee_name');
  LOOP
    EXIT WHEN c_employee_names%NOTFOUND;
    FETCH c_employee_names INTO v_employee_name;
    v_employee_names := v_employee_names
    || v_delimiter
    || v_employee_name;
    v_delimiter := ',';
  END LOOP;
  v_employee_names := REPLACE (v_employee_names, ',', ''',''');
  v_sql := ' SELECT employee_name, ssn'
        || ' FROM   company'
        || ' WHERE  employee_name IN ('''
        || v_employee_names
        || ''')';
  OPEN cursor_name FOR v_sql;
  LOOP
    EXIT WHEN cursor_name%NOTFOUND;
    FETCH cursor_name INTO v_employee_name, v_ssn;
    DBMS_OUTPUT.PUT_LINE (v_employee_name || ' ' || v_ssn);
  END LOOP;
  CLOSE cursor_name;
END procedure_name;
To execute the procedure that calls the function:
SET SERVEROUTPUT ON
EXEC procedure_name

Similar Messages

  • How to use dynamic query for this ??

    hi , i am new to ABAP. i got a requirement to write  dynamic query for the following code.
    kindly address. two set of queries are same.but condition is different.
    .IF p_psd EQ ' '.
    *C--End of change DF 1232137- (Transport # :CIDK980530 )
    *C--FETCH THE Deliverd Quantiity and Material Number
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng IN s_dqt
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
        IF sy-subrc = 0.
          SORT t_afpo BY aufnr matnr pwerk.
    *C--FETCH THE OBJECT NUMBER
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_aufk BY aufnr objnr.
    *C--FETCH THE Target Quantiity
            SELECT aufnr "ORDER number
                   gamng "Total order quantity target quantity
                   FROM afko
                   INTO TABLE t_afko
                   FOR ALL ENTRIES IN t_afpo
                   WHERE aufnr = t_afpo-aufnr
                   AND   gamng IN s_tqt.
            IF sy-subrc = 0.
              SORT t_afko BY aufnr .
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
          LEAVE LIST-PROCESSING.
        ENDIF.
    *C--Begin of change DF 1232137- (Transport # :CIDK980530 )
      ENDIF.
      IF p_psd EQ c_x.
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng > 0
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
    if sy-subrc = 0.
    *C--FETCH THE OBJECT NUMBER
        IF  NOT t_afpo[] IS INITIAL.
          SORT t_afpo BY aufnr matnr pwerk.
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
        IF NOT t_afpo[] IS INITIAL.
    *C--FETCH THE Target Quantiity
          SELECT aufnr "ORDER number
                 gamng "Total order quantity target quantity
                 FROM afko
                 INTO TABLE t_afko
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr
                 AND   gamng <> t_afpo-wemng .
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
      ELSE.
        MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
        LEAVE LIST-PROCESSING.
      ENDIF.
    Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tags

    Hi friend,
    Try using MACRO and dynamic WHERE condition.
    Group simialr Select statements under a Macro.
    Build a dynamic where by checking conditions
    Call macro passing dynamic where condition.
    TABLES afpo.
    DATA: str TYPE string.
    *Macro definition
    DEFINE operation.
      select single *
           from afpo into afpo
           where (&1).    " Dynamic condition
    END-OF-DEFINITION.
    *Build dynamic WHERE by checking some conditions
    *If conditon 
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
    *Else
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
    *Endif.
    *Call Macro passing dynamic WHERE condition
    operation str.

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

  • Query for selecting the 4 highest marks of the student

    query for selecting the 4 highest marks of the student

    Guys dont start an argument,
    tey this one; please
    Hi,
    Try this
    Top 4
    Select ename,
    sale
    From dept d,
    emp e1
    Where d.deptno = e1.deptno
    And &p > (Select Count(e2.sal)
    From emp e2
    Where e2.sal > e1.sal
    And e2.deptno = e1.deptno
    Order By 1,2
    Bottom 4
    Select ename,
    sale
    From dept d,
    emp e1
    Where d.deptno = e1.deptno
    And &p > (Select Count(e2.sal)
    From emp e2
    Where e2.sal < e1.sal
    And e2.deptno = e1.deptno
    Order By 1, 2
    &P you use any value say 3,4,5,6
    This is top N analysis
    Regards
    Umesh

  • Query for selecting first  3 characters of name of any person

    query for selecting first 3 characters of name of any person

    10:52:44 SQL> SELECT SUBSTR(ename, 1, 3) first_three FROM emp;
    FIRST_THREE
    SMI
    ALL
    WAR
    JON
    MAR
    BLA
    CLA
    SCO
    KIN
    TUR
    ADA
    FIRST_THREE
    JAM
    FOR
    MIL
    Ton
    15 rows selected.
    Elapsed: 00:00:00.00

  • Query for select CLOB data field

    Hi All,
    I want to know how to write a SQL query for select CLOB tyoe data from a tablw. when I am trying to use the simple SQL it gives an messageLOB types requires OCI8 mode and currently uasing OCI7 ode.
    Also I am not aware of oci mode?
    If its working for OCI8 mode how I should changer it in to OCI8 mode? (I am using 10g rel 2)
    Thans and regards
    Buddhike

    Hi ,
    i don't want to use loop (sy-tabix) ..
    any particular reason for this ?
    as u cannot automatically generate serial number, u have to go for loop....endloop.
    Thanks
    Karthik

  • DYNAMIC QUERY FOR INSERT USING SELECT

    Hi All,
    I am facing an issue...I am un bale to do an dynamic query. i have explained my code and the sample create, insert statements. I shud insert values in a table using a select statement dynamically..
    create table listing (tel_no varchar2(16), list_key varchar2(30));
    create table dummy_extract ( extract_name varchar2(10),extract_query varchar2(400),extract_date date );
    create table dummy_query (tel_no varchar2(16), list_key varchar2(30));
    insert into listing (tel_no ,header_key) values ('123456','123.23');
    insert into dummy_extract (extract_name,extract_query,extract_date) values ('SP','SELECT TEL_NO, LIST_KEY FROM LISTING','10-DEC-2010');
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    V_STMT := 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE V_STMT using i.extract_query;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;

    Hi Blue shadow and Saubik,
    I tried my query.It shows missing expression...Could you tell me the reason...
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    --V_STMT := 'INSERT INTO'|| DUMMY_QUERY ||'VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;
    Error report:
    ORA-00936: missing expression
    ORA-06512: at line 14
    00936. 00000 - "missing expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use dynamic query for Result table

    Hello Experts,
    I want to use dynamic query and then display the result in the assignment block.
    Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
    SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
    Regards.

    Hi,
    Please find below sample code:
    data:  query         TYPE REF TO cl_crm_bol_dquery_service,
               result        TYPE REF TO if_bol_bo_col.
    DATA: lt_params       TYPE crmt_name_value_pair_tab,        
               lwa_params      TYPE crmt_name_value_pair.             
    query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
    Set general query parameter for maximum number of hits
          lwa_params-name = 'MAX_HITS' .
          lwa_params-value = '50'.
          APPEND lwa_params TO lt_params.
          query->set_query_parameters( it_parameters = lt_params ).
          query->add_selection_param( iv_attr_name = 'OBJECT_ID'
                                                    iv_sign      = 'I'
                                                    iv_option    = 'EQ'
                                                    iv_low       = <lv_objectid>
                                                    iv_high      = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
    "You can find possible search options for a query object in  GENIL_BOL_BROWSER
    result ?= query->get_query_result(  ).   " Get result from your search query
    me->typed_context-> <your result context node>->set_collection( result ). 
    Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct                      
    Hope this helps.
    e Regards,
    Bhushan

  • Infoset query ('At Selection-Screen') - Urgent

    Hi All,
    The below code for selection criteria 'At Selection-Screen' for an infoset-query works ok, but i find 2 problems, can someone help.
    1. When user presses F4, i wanted the output to display
       SG Singapore
       IN   India
       But at the moment it just displays
       SG
       IN
    2. If the user enters any other value apart from the above 2 i do not want the query to execute, instead show something like enter a valid value. But at the moment if i enter another country code manually just to test eg: US, the query runs with this selection which i do not want.
    Hope my problem is clear, await inputs.
    Code:
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR VEN_CTY-LOW.
            IT_LAND-VEN_CTY = 'SG'.
            IT_LAND-LTEXT   = 'Singapore'.
              APPEND IT_LAND.
            IT_LAND-VEN_CTY = 'IN'.
            IT_LAND-LTEXT   = 'India'.
              APPEND IT_LAND.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD   = 'VEN_CTY'
          VALUE_ORG  = 'S'
        TABLES
          VALUE_TAB  = IT_LAND
          RETURN_TAB = IT_RETURN
        EXCEPTIONS
          PARAMETER_ERROR = 1
          NO_VALUES_FOUND = 2.
    IF SY-SUBRC = 0.
        READ TABLE IT_LAND INDEX 1.
        MOVE IT_RETURN-FIELDVAL TO VEN_CTY-LOW.
    ENDIF.

    Hi vivek,
    for the 2nd problem,
    create a range for ingapor and india say r_range.
    and
    r_range will have two values say india, singapore.
    loop at VEN_CTY.
    if ven_cty not in r_range.
    display error message.
    exit.
    endloop.
    try this and let me know.
    reward if helpful.
    thanks .
    ranya

  • DYNAMIC LOV FOR SELECT LIST

    hi to all,
    i've a question regarding lov query based select list:
    For a certain user i need that the lov display a list
    if app_user = BACK_OFFICE I NEED THAT ther query on wich is populated the
    select list is qry 1.
    if app_user is another (consultant) i need query 2 for populating the select list
    1) select name|| ' ' || fname D, id K from partner
    2) select name|| ' ' || fname D, id K from partner WHERE UNAME=(:APP_USER)
    Any solutions would be greatly appreciated.
    Another solution would be to have 2 different apps (one for back-office, one for external consultant), but there i should always duplicate all changes to the second one, loosing a lot of time.
    Now thinking as well to use hidden fields.
    If not clear enough please ask me.
    Thanx a lot.
    Message was edited by:
    Marcello Nocito

    I think one solution wold be to create two different named querys, one containing query 1 and the second query 2. Than u must create an Application Item(like a session variable) in wich u will store you condition. If you want to use the app_user variable u allready have it so you don't need to create it any more. On your page where u want to display the different select list u create two items, one with the query 1 as source and a second item(select list) having the source query 2. Then you must add a condition display on both of them like. Item one is displayed when Value of Item in expression 1 equals expression 2. And you pust :APP_USER in expression 1 and BACK_OFFICE in expression 2. And for the other item, that contains query 2, you put the opposite condition Value of item in expression 1 is not equal to expression 2, and expression 1 is :APP_USER and in expression 2 is BACK_OFFICE.
    Hope this helps.
    Florin

  • Dynamic variant for select option High value

    Hi ,
    Please help me in creating dynamic variable for a select option date field high value.
    II tried the following method:
    1. Enter the values in the selection screen
    2. Save the variant using the SAVE button
    3. In the next screen for the date variable select the 'Selection variable' checkbox (L) and click on the button 'Selection variable' in the toolbar.
    4. Now you will see this variable in the next screen with 3 types of buttons. Click on the middle button (i.e. D - Dynamic date calculation).
    5. Click on the down arrow button and select the option 'Current Date'.
    5. Save the variant.
    But it is saving the date value in Field LOW of select option( From value).
    I need it in TO field( High value).
    Please help.
    regards,
    Sheeba

    Hi Sheeba
        we can do it other way .. Select the same steps as you have done but after the assigning the value current date to low ..click on the selection option push button at the application bar and choose the 'less than or equal to' option to your select option value and try the same ....
    I guess this would throw you same results as that of the value in the high value button
    Cheers,
    Jacks.

  • Generating Dynamic Query for Ad-Hoc Reports

    Hello,
    What is the best way to create a dynamic query to generate ad-hoc reports? I have a couple of ideas but not sure which would work best and be most flexible.
    I would like our users to be able to check checkboxes for what data they would like returned in their report. The data would be pulled from a number of tables, 10+, depending on what pieces of data they checked.
    Should I write one dynamic query, with a bunch of IF statements in it?
    Should I write many individual queries and then join them together in a temp query?
    Should I create a temp table on our SQL server which contains the data from all of the tables; then query that? (I am worried about data being out-of-date with this option.)
    Which one of these solutions should I go with or is there a better solution that I am not considering?
    Thanks for the help.
    Josh

    Do you mean a Stored Procedure? Would the Stored Procedure then have one query on it with a bunch if IF statements? Maybe a bad example, but something like this?
    Yep.
    I haven't written a proc for a coupla years (I have DB people to do that for me now, bless 'em), but every DB is different, so the approach will vary depending on what DB you have.  It's perhaps time to buy a book or do a google or something.
    Adam

  • A test query for selecting by ticketid

    This is a test query to select tickets by ticketid , starting with the most recent, as to get the top5 most recent tickets. There will be still mistakes in it. please don't tell me those about stupid mistakes,and spaces, at first and obvious syntax mistakes. Otherwise I don't learn it. My question has to do with the loop. Do you think it is useful to use a loop for this, or should it stay as it is, or should it be something else.
    DECLARE
    Define, and open a cursor;
    min_ticket NUMBER; -- minimum ticketid
    laatste_ticket NUMBER; -- latest ticketid
    tussen_ticket NUMBER; -- in between ticket
    Query_to_use VARCHAR2(4000);
    BEGIN
    Select max(ticketid) into laatste_ticketid from ticket;
    Select count(*) into teller from ticket where (ticketid<laatste_ticketid ) AND (ticketid>(laatste_ticketid-6));
    Select ticketid, categoriecd, titel into cursor from ticket where (ticketid<laatste_ticketid ) AND (ticketid>(laatste_ticketid-6));
    Select min(ticketid) into min_ticketid from ticket;
    If teller= < 5
         If teller = 5
              Query_to_use := Query_to_use || ';';
              Return Query_to_use;
         else
              --Loop through records from laatste_ticketid to min_ticketid
                   Select gebruikerid into te_testen_veld from ticket where ticketid = tussen_ticketid ;
                   If te_testen_veld is NULL THEN
                        tussen_ticketid := tussen_ticketid - 1;
                        te_testen_veld := NULL;
                   Else
    Query_to_use := query_to_use || ' UNION select ticketid, categoriecd, titel from ticket '||
                   ' where ticketid = tussen_ticketid ';
                   te_testen_veld := NULL;
                   Teller := teller + 1;
                        If (teller < 5)
                             tussen_ticketid := tussen_ticketid - 1;
                        Else if (teller = 5)
                             teller := 6;
                        End if;
                   End if;
              --End Loop;
         End if;
    End if;
    Query_to_use := Query_to_use || ';';
    Return Query_to_use;
    END;

    You can get all this using one SQL statement, without resorting to explicit cursors. Have a look at http://asktom.oracle.com and search for Top-N Query.
    Depending on what you are doing, you may want to use a cursor for loop.
    I assume this is for some sort of electronic queueing system. if you gave us more detail as to what you are trying to do, you may get better advice.

  • Code for selection screen,  urgent

    Hi Everyone,
      I need code for selection screen.
      I have four radio buttons, p1, p2,p3,p4(assume)
    If I select second radiobutton, remaining three radiobuttons should be in disable mode and also the information under them should be in disable mode. Give the coding details. Thanks in advance. U will be rewarded.
    Regards,
    Nagaraju

    Hi,
    REPORT ZTEST222 .
    PARAMETERS : p_add  RADIOBUTTON GROUP radi
                             USER-COMMAND radio MODIF ID MOD,
      p_disp RADIOBUTTON GROUP radi DEFAULT 'X'  MODIF ID pod,
      p_chng RADIOBUTTON GROUP radi MODIF ID rad,
      p_er_log RADIOBUTTON GROUP radi MODIF ID cod.
    SELECT-OPTIONS : s_idn    FOR  vendor   MODIF ID mod,
                                   s_pcode  FOR ws_c_pcode MODIF ID pod.
    PARAMETERS:  p_plant    LIKE  zaw_pol_plan-plant   MODIF ID rad,
                 p_zzvend   LIKE  zaw_pol_plan-zzvendor   MODIF ID cod.
    AT SELECTION-SCREEN OUTPUT.
    LOOP AT SCREEN.
    IF p_add EQ 'X'.
          IF screen-group1 EQ 'MOD'.
            screen-active = 1.
            MODIFY SCREEN.
    ELSE.
             screen-active = 0.
            MODIFY SCREEN.
    ENDIF.
    IF p_disp EQ 'X'.
          IF screen-group1 EQ 'POD'.
            screen-active = 1.
            MODIFY SCREEN.
    ELSE.
             screen-active = 0.
            MODIFY SCREEN.
    ENDIF.
    IF p_chng EQ 'X'.
          IF screen-group1 EQ 'RAD'.
            screen-active = 1.
            MODIFY SCREEN.
    ELSE.
             screen-active = 0.
            MODIFY SCREEN.
    ENDIF.
    IF p_er_log EQ 'X'.
          IF screen-group1 EQ 'COD'.
            screen-active = 1.
            MODIFY SCREEN.
    ELSE.
             screen-active = 0.
            MODIFY SCREEN.
    ENDIF.
    Pls. reward if useful
        ENDLOOP.
    Pls. reward if useful

  • Dynamic Query for a report

    Hi,
    I have to generate a report which contains a query with database link. This database link is not hard coded and would be picked up from another report which contans a link to this report. So this database link value for the query could be any. Can anyone guide me hot to write a dynamic select statement so that i could append database link value at run time.
    Thanks
    Salman

    Hi,
    You can not directly use a PL/SQL query to create an Interactive Report - that is not yet available.
    What you could do is create a collection from your query and then use that for the report. Have a look at: [http://download-uk.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32471/advnc.htm#BABGHJFD].
    In there, you will see APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY - this allows you to create a collection from a string. You could add a PL/SQL process to your page that runs "On Load: Before Header" that actually creates the collection. Something like:
    BEGIN
    IF APEX_COLLECTION.COLLECTION_EXISTS('MYCOLLECTIONNAME') THEN
      APEX_COLLECTION.DELETE_COLLECTION('MYCOLLECTIONNAME');
    END IF;
    APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING');
    END;Your Interactive Report can then be based on:
    SELECT SEQ_ID, C001, C002, C003, ...
    FROM APEX_COLLECTIONS
    WHERE COLLECTION_NAME = 'MYCOLLECTIONNAME'The tricky part is the headings as these would tend to be the SEQ_ID, C001, C002, C003, etc column names from the collection itself.
    To get around this, make sure that the report's sql statement includes as many Cnnn columns as you will need for the widest of the reports. Before doing anything else, run the report once to make sure that all these columns are included in the output.
    Then, through Shared Components, Application Items, create items that will hold heading names - for example, G_HEADING1, G_HEADING2 etc - one for each possibile column.
    Now, update the process to:
    BEGIN
    IF APEX_COLLECTION.COLLECTION_EXISTS('MYCOLLECTIONNAME') THEN
      APEX_COLLECTION.DELETE_COLLECTION('MYCOLLECTIONNAME');
    END IF;
    IF ..test1.. THEN
      APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING 1');
      :G_HEADING1 := 'ColumnHeading1Value';
      :G_HEADING2 := 'ColumnHeading2Value';
      :G_HEADING3 := NULL; -- column not used for this query, so set it to null
    ELSIF ..test2 .. THEN
      APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING 2');
      :G_HEADING1 := 'ColumnHeading1Value';
      :G_HEADING2 := 'ColumnHeading2Value';
      :G_HEADING3 := 'ColumnHeading3Value';
    ELSIF ...etc...
      .. etc ...
    END IF;
    END;Finally, on the report itself, set the column headings to *&G_HEADING1.*, *&G_HEADING2.* etc. Then, on each column, set a Condition of "Value of Item in Expression 1 is NOT NULL" and in Expression 1, enter in the application item for that column - eg, G_HEADING1
    I have done all that here: [http://apex.oracle.com/pls/otn/f?p=16338:5] - select either Departments or Employees from the list and the report will change.
    Andy

Maybe you are looking for

  • My mid-2010 10.8.2 iMac won't detect external displays.

    My mid-2010 10.8.2 iMac won't detect external displays. I've tried using a third-party minidisplay port to DVI adapter, as well as an Apple-brand minidisplay port to VGA adapter. The monitor I'm using is a Dell SP2008WFPt. It is a functional monitor.

  • Phone signal drops and says 'searching...' no idea what to do

    Half way through calls or after calls the phone signal drops and i can't get it back unless i switch on and off numerous times. THis has been gong on to a greater or lesser degree since I got the phone a year ago but has got much worse recently. i ha

  • Missing left border on Word Document

    I have a word document (Windows Vista) in A5 size, landscape, with a 4 sided border. The print preview shows all borders but when printing on HP L7480 Officejet Pro the left edge of the document is missing including the border. I have tried resetting

  • I own Photoshop CC and Lightroom 5 as subscriber. Do I get Lightroom CC as an update?

    I wonder if I will get the new lightroom CC too... or if I have to upgrade my subscription... which would be awkward!

  • How to install missing kaleidoscope effect

    I'm trying to edit a Final Cut project created by a friend who has the same version of FCStudio that I do: 5.1.4 I copied the project and media files onto my computer, but when I try to render it I get the message: "The following effects could not be