Dynamic where clause for MULTIPLE values

In the following of dynamic where clause?
i have some somewhat different problem.
Is a dynamic where clause for multiple values possible?
If the inputvariable varCode1,varCode2,varCode3,varCode4 are 0 then show all id's otherwise filter the resultset on var1 and/or var2,and/or var3,and/or var4.
Example table:
create table t
(d int,var int);
insert into t values (1 ,1 );
insert into t values (2 ,1 );
insert into t values (3 ,2 );
insert into t values (4 ,3 );
insert into t values (5 ,4 );
insert into t values (6 ,4 );
insert into t values (7 ,4 );
insert into t values (8 ,4 );
insert into t values (9 ,5 );
insert into t values (10, 6);
insert into t values (11, 6);
So what i want to change the where clause upon the value of the varCodes. If var1 and var are not 0 a "AND" should be used otherwise an "OR"
select id
from tst
where var = DECODE( :varCode1, 0, var, :varCode1)
or/and(?) DECODE( :varCode2, 0, var, :varCode2)
or DECODE( :varCode3, 0, var, :varCode3)
or DECODE( :varCode4, 0, var, :varCode4)

Please turn off your Caps Lock
and try this link
Dynamic WHERE clause

Similar Messages

  • ADF dynamic where clause for VO query using BC

    I'm hoping someone can help me out. I have a read only view object that I want to filter results based on some user choices. For example the user may want to see all results or they may only want to see a much smaller subset. This is for an error dashboard, the smaller subset maybe by application or maybe by application and by error severity. I think I can use a dynamic where clause but I'm not sure, Can someone get me started down the right path, or post an example that I can see.

    Hi user,
    You can use a dynamic where clause for this, but maybe there is a more practical option. Maybe you can have a fixed where clause, but using a bind parameter, like:
    vo.application like :applicationParam. This makes an executeWithParams method available that you can call from your page, and use in the bindings. This parameter you can populate with the results of for example a poplist, with a default value of '%'.
    When you do want to use a dynamic where clause, you will need to add a method to the java code of your application module, and make this method available for the client. In this method, you can use findViewObject to retrieve your VO, use VO.setWhereClause to set the whereclause to what you want, and then call VO.executeQuery. This method can then again be called from the page.
    Success,
    Jeroen van Veldhuizen

  • Dynamic where clause for generated reports (designer 6.0)

    Hi,
    I'd like to include dynamic where clause into my reports. It's easy with report builder by using bind parameter in a query where clause (&param where param is a parameter in which you fill a VARACHAR2 to complete default where clause).
    Problem with designer 6.0 report generator is that he failed while trying to parse the query statement he contructs if there is a bind parameter within.
    How can I manage this problem ?
    Thanks for answers
    Romain

    Hi Divya,
         SET_REPORT_OBJECT_PROPERTY(repid,REPORT_OTHER,'paramform=no P_WHERE_CLAUSE= '||Where_Clause);Instead of using SET_REPORT_OBJECT_PROPERTY built in try using ADD_PARAMETER built in which
    adds parameters to a parameter list. Each parameter consists of a key, its type, and an associated value.
    v_rep := RUN_REPORT_OBJECT(repid); and instead of using RUN_REPORT_OBJECT try using RUN_PRODUCT.
    DECLARE
         repid REPORT_OBJECT;
         v_rep  VARCHAR2(100);
         Where_Clause Varchar2(4000) := null ;
            *Pl_Id        ParamList;*
            *Pl_Name      VARCHAR2(10) := 'param_list';*
    BEGIN
         Where_Clause := 'Where '||Create_Where_Clause();
         message(Where_Clause);
         message(' ');
            pl_id := Get_Parameter_List(pl_name);
            IF not Id_Null(pl_id) THEN
               Destroy_Parameter_List(pl_id);
            END IF;
            pl_id := Create_Parameter_List(pl_name);
            Add_Parameter(pl_id,'P_WHERE_CLAUSE', TEXT_PARAMETER, WHERE_CLAUSE);
            Add_Parameter(pl_id,'PARAMFORM',TEXT_PARAMETER,'NO');
    --      Add_Parameter(pl_id,'ANY_OTHER_PARAMETER', TEXT_PARAMETER, 'VALUE FOR OTHER PARAMETER');
            RUN_PRODUCT(REPORTS,'REPORT_NAME', ASYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id, NULL);
    END;Also you can add as many User created or System parameters as you want using add_parameter. Updated the code to add PARAMFORM parameter.
    Best Regards
    Arif Khadas
    Edited by: Arif Khadas on Mar 15, 2011 9:31 AM

  • How to add a dynamic where clause for a sql based VO with group by query?

    Hi,
    Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
    vo.setWhereClause("type='MyType1' ");
    vo.executeQuery();
    Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
    Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
    Thanks,
    Chunyang
    Edited by: Chunyang on Dec 13, 2012 9:09 PM

    Hi,
    When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
    select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
    select * from (select empno, ename from emp) where ename='KING' - VALID
    select * from (select empno, ename from emp) where deptno=10  - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
    -Arun

  • Dynamic where clause for cursor

    Hi Friends,
    I have a stored procedure with a single input parameter where in the input comes as
    a string of values (ex: EMPLOYEE NAMES) separated by commas. I use this parameter in my cursor query
    and my requirement is like when the parameter is NULL the query has to run for ALL the employees but if
    its not, it has to run for the EMPLOYEE NAMES passed as the input parameter.
    What are the possible and apt solutions for this requirement ?
    Should I go for dynamic sql or do I have any other optimal solutions?
    Please advice me.
    Thanks
    Zara

    Dear,
    I have a stored procedure with a single input parameter where in the input comes as
    a string of values (ex: *EMPLOYEE NAMES*) separated by commas. I use this parameter in my cursor query
    and my requirement is like when the parameter is NULL the query has to run for ALL the employees but if
    its not, it has to run for the EMPLOYEE NAMES passed as the input parameter.
    What are the possible and apt solutions for this requirement ?
    Should I go for dynamic sql or do I have any other optimal solutions?
    Please advice me.I would suggest you to let down this dynamic SQL and those concatenations that are going to introduce a threat of SQL injection and non shared code into your application.
    And, as far as you've opted for a stored procedure I want to suggest you to use
    (a) stored procedure in wich only static SQL is used
    (b) if point (a) is respected then you don't have to care about using litteral inside your stored procedure. All what you will do in this procedure will be 'auto-binded'; that is PL/SQL (static).
    (c) However, make sure to call your stored procedure using bind variables; otherwise your shared pool (v$sql) will be full of hundred and thousands of calls to your stored procedure.
    Best Regards
    Mohamed Houri

  • Dynamic orderby clause for multiple columns with out Dynamic query

    Hi,
            I've a query like
    "select  * from tablename order by column1,column2,column3,column4,column5,column6"
    in the above query the order by column will be dynamically changed. The query is placed in a stored procedures and the order by column will come by parameter.
       For ex: @orderbycol = column2,column1,column3,column4,column5,column6
                                         or
                    @orderbycol = column3,column2,column1,column4,column5,coumn6
    How can we manage the order by clause as dynamically without go to dynamic query.

    ORDER BY CASE @sortcol1
                 WHEN 'col1' THEN col1
                 WHEN 'col2' THEN col2
             END,
             CASE @sortcol2
                 WHEN 'col1' THEN col1
                 WHEN 'col2' THEN col2
             END,
    Note: these CASE expressions assumes that all columns have the same data type.
    You could consider sorting in the presentation layer instead.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Where clause for TaskLOVVO on OTL Timecard

    Hi,
    Following is the customization on our OTL timecard layout(Projects and Payroll Layout):
    ->Extended TaskLOVVO and based on a value selected in TaskLOV, i am defaulting Hours type.
    The dynamic where clause for the TaskLOVO is taken care of by the below QUALIFIER_ATTRIBUTES(Same as seeded layout)
    QUALIFIER_ATTRIBUTE14 = "HxcCuiTaskProjectId|PROJECT|Y#HxcCuiTaskProjectNumber|PROJECT-DISPLAY|Y"
    QUALIFIER_ATTRIBUTE15 = "project_id = ::HxcCuiTaskProjectId#upper(project_number) = upper(::HxcCuiTaskProjectNumber)"
    But in some scenarios the dynamic layout is not getting appended to TaskLOVO and the query behind the TaskLOV is pulling too many records.
    This issue is happening on Fridays when around 15000 employees submit the timecards, as Friday is our deadline for Timecard submission.
    I have tried different scenarios to replicate this issue in test intances but I am not able to replicate it.
    Please suggest what could be the issue and why is the whereclause is not getting appended in some scenarios.
    Thank you

    Hi,
    Thank you for your reply.
    The whoole LDT file is more than 30000 characters, which is not allowed in the post, so I have included only the lines which have customization.
    FYI: This is a Projects and Payroll layout.
    Following is my LDT file:
    # $Header: hxczzhxclayt0093.ldt 120.0 2008/02/08 09:26:10 bbayragi noship $
    # dbdrv: exec fnd bin FNDLOAD bin &phase=dat+10 checkfile:~PROD:~PATH:~FILE &ui_apps 0 Y UPLOAD @HXC:patch/115/import/hxclaytlayoutsld.lct @~PROD:~PATH/~FILE
    LANGUAGE = "US"
    LDRCONFIG = "hxclaytlayoutsld.lct 120.0"
    #Source Database seed121
    #RELEASE_NAME 12.1.0
    # -- Begin Entity Definitions --
    BEGIN HXC_LAYOUT_COMPONENTS
    "Projects Details Alternate Timecard Layout - Project"
    OWNER = "ORACLE12.1.0"
    COMPONENT_VALUE = "PROJECT"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_CODE_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "HXC_TIMECARD_PROJECT"
    ATTRIBUTE_CODE_APP_SHORT_NAME = "HXC"
    SEQUENCE = "200"
    COMPONENT_DEFINITION = "LOV"
    RENDER_TYPE = "WEB"
    PARENT_COMPONENT = "Projects Details Alternate Timecard Layout - Day Scope Building blocks for worker timecard matrix"
    LAST_UPDATE_DATE = "2004/05/24"
    BEGIN HXC_LAYOUT_COMP_QUALIFIERS
    "Projects Details Alternate Timecard Layout - Project"
    OWNER = "ORACLE12.1.0"
    QUALIFIER_ATTRIBUTE_CATEGORY = "LOV"
    QUALIFIER_ATTRIBUTE1 = "ProjectLOVVO"
    QUALIFIER_ATTRIBUTE2 = "N"
    QUALIFIER_ATTRIBUTE3 = "HXC_CUI_PROJECT_DETAILS_LOV"
    QUALIFIER_ATTRIBUTE4 = "809"
    QUALIFIER_ATTRIBUTE5 = "25"
    QUALIFIER_ATTRIBUTE6 = "HxcCuiProjectDetails|PROJECT-DISPLAY|CRITERIA|N|HxcCuiProjectId|PROJECT|RESULT|N|HxcCuiProjectDetails|PROJECT-DISPLAY|RESULT|N|HxcCuiProjectCoOrgId|LOCATION1|RESULT|N|HxcCuiProjectName|CNAME|RESULT|N"
    QUALIFIER_ATTRIBUTE8 = "ProjectDetails"
    QUALIFIER_ATTRIBUTE9 = "ProjectId#NUMBER"
    QUALIFIER_ATTRIBUTE10 = "oracle.apps.hxc.selfservice.timecard.server.ProjectLOVVO"
    QUALIFIER_ATTRIBUTE11 = "RESOURCE_IDENTIFIER_ID"
    QUALIFIER_ATTRIBUTE17 = "OraTableCellText"
    QUALIFIER_ATTRIBUTE20 = "N"
    QUALIFIER_ATTRIBUTE21 = "Y"
    QUALIFIER_ATTRIBUTE22 = "L"
    QUALIFIER_ATTRIBUTE25 = "FLEX"
    QUALIFIER_ATTRIBUTE26 = "PROJECTS"
    QUALIFIER_ATTRIBUTE27 = "Attribute1"
    QUALIFIER_ATTRIBUTE28 = "PROJECT"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_QUALIFIERS
    END HXC_LAYOUT_COMPONENTS
    BEGIN HXC_LAYOUT_COMPONENTS
    "Projects Details Alternate Timecard Layout - Task"
    OWNER = "ORACLE12.1.0"
    COMPONENT_VALUE = "TASK"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_CODE_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "HXC_TIMECARD_TASK"
    ATTRIBUTE_CODE_APP_SHORT_NAME = "HXC"
    SEQUENCE = "210"
    COMPONENT_DEFINITION = "LOV"
    RENDER_TYPE = "WEB"
    PARENT_COMPONENT = "Projects Details Alternate Timecard Layout - Day Scope Building blocks for worker timecard matrix"
    LAST_UPDATE_DATE = "2004/05/24"
    BEGIN HXC_LAYOUT_COMP_PROMPTS "HxcCuiTaskProjectId" "AK_PROMPT"
    OWNER = "ORACLE12.1.0"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "HXC_TIMECARD_PROJECT"
    ATTRIBUTE_APP_SHORT_NAME = "HXC"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_PROMPTS
    BEGIN HXC_LAYOUT_COMP_QUALIFIERS
    "Projects Details Alternate Timecard Layout - Task"
    OWNER = "ORACLE12.1.0"
    QUALIFIER_ATTRIBUTE_CATEGORY = "LOV"
    QUALIFIER_ATTRIBUTE1 = "TaskLOVVO"
    QUALIFIER_ATTRIBUTE2 = "N"
    QUALIFIER_ATTRIBUTE3 = "HXC_CUI_TASK_DETAILS_LOV"
    QUALIFIER_ATTRIBUTE4 = "809"
    QUALIFIER_ATTRIBUTE5 = "10"
    QUALIFIER_ATTRIBUTE6 = "HxcCuiTaskDetails|TASK-DISPLAY|CRITERIA|N|HxcCuiTaskProjectId|PROJECT|PASSIVE_CRITERIA|Y|HxcCuiTaskId|TASK|RESULT|N|HxcCuiTaskDetails|TASK-DISPLAY|RESULT|N|HxcCuiTaskBillableFlag|EXPTYPE|RESULT|N"
    QUALIFIER_ATTRIBUTE8 = "TaskDetails"
    QUALIFIER_ATTRIBUTE9 = "TaskId#NUMBER"
    QUALIFIER_ATTRIBUTE10 = "oracle.apps.hxc.selfservice.timecard.server.TaskLOVVO"
    QUALIFIER_ATTRIBUTE11 = "RESOURCE_IDENTIFIER_ID|TIMECARD_BIND_END_DATE"
    QUALIFIER_ATTRIBUTE14 = "HxcCuiTaskProjectId|PROJECT|Y#HxcCuiTaskProjectNumber|PROJECT-DISPLAY|Y"
    QUALIFIER_ATTRIBUTE15 = "project_id = ::HxcCuiTaskProjectId#upper(project_number) = upper(::HxcCuiTaskProjectNumber)"
    QUALIFIER_ATTRIBUTE17 = "OraTableCellText"
    QUALIFIER_ATTRIBUTE20 = "N"
    QUALIFIER_ATTRIBUTE21 = "Y"
    QUALIFIER_ATTRIBUTE22 = "L"
    QUALIFIER_ATTRIBUTE25 = "FLEX"
    QUALIFIER_ATTRIBUTE26 = "PROJECTS"
    QUALIFIER_ATTRIBUTE27 = "Attribute2"
    QUALIFIER_ATTRIBUTE28 = "TASK"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_QUALIFIERS
    END HXC_LAYOUT_COMPONENTS
    BEGIN HXC_LAYOUT_COMPONENTS
    "Projects Details Alternate Timecard Layout - Location"
    OWNER = "CUSTOM"
    COMPONENT_VALUE = "LOCATION"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_CODE_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "HXC_CUI_LOCATION_LABEL"
    ATTRIBUTE_CODE_APP_SHORT_NAME = "HXC"
    SEQUENCE = "215"
    COMPONENT_DEFINITION = "CHOICE_LIST"
    RENDER_TYPE = "WEB"
    PARENT_COMPONENT = "Projects Details Alternate Timecard Layout - Day Scope Building blocks for worker timecard matrix"
    LAST_UPDATE_DATE = "2004/05/24"
    BEGIN HXC_LAYOUT_COMP_QUALIFIERS "Projects Details Alternate Timecard Layout - Location"
    OWNER = "CUSTOM"
    QUALIFIER_ATTRIBUTE_CATEGORY = "CHOICE_LIST"
    QUALIFIER_ATTRIBUTE1 = "Custom2VO"
    QUALIFIER_ATTRIBUTE4 = "N"
    # QUALIFIER_ATTRIBUTE5 = "10"
    # QUALIFIER_ATTRIBUTE8 = "DisplayValue"
    # QUALIFIER_ATTRIBUTE9 = "Value#NUMBER"
    QUALIFIER_ATTRIBUTE10 = "oracle.apps.hxc.selfservice.timecard.server.Custom2VO"
    QUALIFIER_ATTRIBUTE17 = "OraTableCellText"
    QUALIFIER_ATTRIBUTE20 = "N"
    QUALIFIER_ATTRIBUTE21 = "Y"
    QUALIFIER_ATTRIBUTE22 = "L"
    QUALIFIER_ATTRIBUTE25 = "FLEX"
    QUALIFIER_ATTRIBUTE26 = "Dummy Element Context"
    QUALIFIER_ATTRIBUTE27 = "Attribute15"
    QUALIFIER_ATTRIBUTE28 = "LOCATION1"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_QUALIFIERS
    END HXC_LAYOUT_COMPONENTS
    BEGIN HXC_LAYOUT_COMPONENTS "Projects Details Alternate Timecard Layout - Expenditure Type"
    OWNER = "ORACLE"
    COMPONENT_VALUE = "EXPENDITURETYPE"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_CODE_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "HXC_TIMECARD_EXPTYPE"
    ATTRIBUTE_CODE_APP_SHORT_NAME = "HXC"
    SEQUENCE = "225"
    COMPONENT_DEFINITION = "PACKAGE_CHOICE_LIST"
    RENDER_TYPE = "WEB"
    PARENT_COMPONENT = "Projects Details Alternate Timecard Layout - Day Scope Building blocks for worker timecard matrix"
    LAST_UPDATE_DATE = "2004/05/23"
    BEGIN HXC_LAYOUT_COMP_QUALIFIERS "Projects Details Alternate Timecard Layout - Expenditure Type"
    OWNER = "ORACLE"
    QUALIFIER_ATTRIBUTE_CATEGORY = "PACKAGE_CHOICE_LIST"
    QUALIFIER_ATTRIBUTE1 = "BOLINF.XXHXC_TYPE_CHOICE.EXPTTYPE"
    QUALIFIER_ATTRIBUTE2 = "@RESOURCE_IDENTIFIER_ID|@TIMECARD_BIND_END_DATE"
    QUALIFIER_ATTRIBUTE4 = "N"
    QUALIFIER_ATTRIBUTE8 = "aliasname"
    QUALIFIER_ATTRIBUTE9 = "value#NUMBER"
    QUALIFIER_ATTRIBUTE20 = "N"
    QUALIFIER_ATTRIBUTE21 = "Y"
    QUALIFIER_ATTRIBUTE22 = "R"
    QUALIFIER_ATTRIBUTE24 = "ET_EXPENDITURE_TYPE"
    QUALIFIER_ATTRIBUTE25 = "FLEX"
    QUALIFIER_ATTRIBUTE26 = "OTL_ALIAS_1"
    QUALIFIER_ATTRIBUTE27 = "Attribute1"
    QUALIFIER_ATTRIBUTE28 = "EXPTYPE"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_QUALIFIERS
    END HXC_LAYOUT_COMPONENTS
    BEGIN HXC_LAYOUT_COMPONENTS "Projects Details Alternate Timecard Layout - Customer name"
    OWNER = "ORACLE"
    REGION_CODE = "HXC_CUI_TIMECARD"
    REGION_CODE_APP_SHORT_NAME = "HXC"
    ATTRIBUTE_CODE = "XXTW_HXC_TIMECARD_CUST_NAME"
    ATTRIBUTE_CODE_APP_SHORT_NAME = "HXC"
    SEQUENCE = "205"
    COMPONENT_DEFINITION = "TEXT_FIELD"
    RENDER_TYPE = "WEB"
    PARENT_COMPONENT = "Projects Details Alternate Timecard Layout - Day Scope Building blocks for worker timecard matrix"
    LAST_UPDATE_DATE = "2004/05/24"
    BEGIN HXC_LAYOUT_COMP_QUALIFIERS "Projects Details Alternate Timecard Layout - Customer name"
    OWNER = "ORACLE"
    QUALIFIER_ATTRIBUTE_CATEGORY = "TEXT_FIELD"
    QUALIFIER_ATTRIBUTE1 = "N"
    QUALIFIER_ATTRIBUTE2 = "Y"
    QUALIFIER_ATTRIBUTE3 = "20"
    QUALIFIER_ATTRIBUTE4 = "1"
    QUALIFIER_ATTRIBUTE5 = "20"
    QUALIFIER_ATTRIBUTE7 = "OraTableCellText"
    QUALIFIER_ATTRIBUTE17 = "NONE"
    QUALIFIER_ATTRIBUTE20 = "Y"
    QUALIFIER_ATTRIBUTE21 = "Y"
    QUALIFIER_ATTRIBUTE22 = "L"
    QUALIFIER_ATTRIBUTE25 = "FLEX"
    QUALIFIER_ATTRIBUTE26 = "PROJECTS"
    QUALIFIER_ATTRIBUTE27 = "Attribute9"
    QUALIFIER_ATTRIBUTE28 = "CNAME"
    QUALIFIER_ATTRIBUTE30 = "Y"
    LAST_UPDATE_DATE = "2004/05/24"
    END HXC_LAYOUT_COMP_QUALIFIERS
    END HXC_LAYOUT_COMPONENTS
    And the query in TASKLOVVO:
    SELECT task.task_number tasknumber, task.task_name, task_details taskdetails, task.task_id taskid, bolinf.GETALIASID(proj.project_type,proj.project_id,task.task_id, :1, :2) billable_flag, task.project_id, task.start_date, task.completion_date, task.chargeable_flag, proj.project_number , proj.project_details from pa_online_tasks_v task ,pa_online_projects_v proj where proj.project_id = task.project_id
    In the above query GETALIASID is a custom function that returns a value.
    Thank you
    Edited by: Santo on Mar 18, 2013 2:12 PM

  • Using multiple values in a where clause, for values only known at runtime

    Dear all
    I am creating a PL/SQL program which returns multiple rows of data but only where it meets a set id values that a user has previously chosen. The id values are stored in an associative array and are chosen by a user in the preceding procedure at run time.
    I know all the table and column names in advance. The only things I don't know are the exact number of ids selected from the id column and what their values will be. This will only be known at runtime. When the procedure is run by the user it prints multiple rows of data to a web browser.
    I have been reading the following posting, which I understand to a large extent, Query for multiple value search But I cannot seem to figure out how I would apply it to my work as I am dealing with multiple rows and a cursor.
    The code as I have currently written it is wrong because I get an error not found message in my web browser. I think the var_user_chosen_map_list_ids in the for cursor loop could be the problem. I am using the variable_user_chosen_map_list_ids to store all the id values from my associatative array as a string. Which I modified from the code that vidyadhars posted in the other thread.
    Should I be creating a OPEN FOR ref cursor and if so where would I put my associative array into it? At the moment I take the value, turning it into a string and IN part in the WHERE clause holds the string, allowing the WHERE clause to read all the values from it. I would expect the where clause to read everything in the string as 1 complete string of VARCHAR2 data but this would not be the case if this part of the code at least was correct. The code is as follows:
    --Global variable section contains:
    var_user_chosen_map_list_ids VARCHAR2(32767);
    PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
    IS
    CURSOR cur_map_search (par_user_chosen_map_list_ids IN NUMBER)
    IS
    SELECT MI.map_date
           MT.map_title,
    FROM map_info MI,
         map_title MT,
    WHERE MI.map_title_id = MT.map_title_id
    AND MI.map_publication_id IN
    (var_user_chosen_map_list_ids);
    var_map_list_to_compare VARCHAR2(32767) := '';
    var_exe_imm_map VARCHAR2(32767);
    BEGIN
    FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
    LOOP
       var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
       '''' ||
       par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
    END LOOP;
    var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
                                            1,
                                            length(var_user_chosen_map_list_ids)-1);
    var_exe_imm_map := 'FOR rec_search_entered_details IN cur_map_search
    LOOP
    htp.print('Map date: ' || cur_map_search.map_date || ' Map title: ' || cur_map_search.map_title)
    END LOOP;';
    END PROCMAPSEARCH;EXECUTE IMMEDIATE var_exe_imm_map;
    I would be grateful of any comments or advice.
    Kind regards
    Tim

    I would like to thank everyone for their kind help.
    I have now successfully converted my code for use with dynamic SQL. Part of my problem was getting the concept confused a little, especially as I could get everything work in a static cursor, including variables, as long as they did not contain multiple values. I have learnt that dynamic sql runs the complete select statement at runtime. However even with this I was getting concepts confused. For example I was including variables and the terminator; inside my select string, where as these should be outside it. For example the following is wrong:
         TABLE (sys.dbms_debug_vc2coll(par_user_chosen_map_list_ids))....
    AND MI.map_publication_id = column_value;';Where as the following is correct:
         TABLE (sys.dbms_debug_vc2coll('||par_user_chosen_map_list_ids||'))....
    AND MI.map_publication_id = column_value';PL/SQL is inserting the values and then running the select statement, as opposed to running the select statement with the variables and then accessing the values stored in those variables. Once I resolved that it worked. My revised code is as follows:
    --Global variable section contains:
    var_user_chosen_map_list_ids VARCHAR2(32767);
    var_details VARCHAR(32767);
    PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
    IS
    BEGIN
    FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
    LOOP
       var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
       '''' ||
       par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
    END LOOP;
    var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
                                            1,
                                            length(var_user_chosen_map_list_ids)-1);
    var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids);
    htp.print(var_details);
    END PROCMAPSEARCH;
    FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767)
    RETURN VARCHAR2
    AS
    TYPE cur_type_map_search IS REF CURSOR;
    cur_map_search cur_type_map_search;
    var_map_date NUMBER(4);
    var_map_title VARCHAR2(32767);
    begin:
    OPEN cur_map_search FOR
    'SELECT MI.map_date,
           MT.map_title
    FROM map_info MI,
         map_title MT,
         TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || '))
    WHERE MI.map_title_id = MT.map_title_id
    AND MI.map_publication_id = column_value';
    LOOP
    FETCH cur_map_compare INTO
    var_map_date,
    var_map_title;
    var_details := var_details || 'Map date: '||
                        var_map_date ||
                        'Map title: ' ||
                        var_map_title;
    EXIT WHEN cur_map_compare%NOTFOUND;
    END LOOP;
    RETURN var_details;
    END FUNCMAPDETAILS;Kind regards
    Tim

  • Passing values to Dynamic where clause as IN parameter - ADF

    Hi,
    I am trying to get the Dynamic where clause query output something like below,
    select * from EMP where emp_id IN(200,203,204)
    How to pass values from setWhereCluase(emp_id,????)
    Thanks,

    I'd go about this a little differently (probably not the best way):
    1. Create view object lk_department (lookup). In the query add a union with something like "select null as ID, 'All' as name' from dual;". This adds a null value that they can select by leaving the combo box on "All". Add a 'order by id" so the null value is the first one. When creating the combo box you want it set to navigation mode, so select the whole viewobject from the data palette rather a specific field.
    2. Create a jTextField for the "Jobs" field.
    3. Create an application module method that does something like:
    public void filterEmployees(String job){
    ViewObject vo_departments = findViewObject("lk_departments");
    ViewObject vo_employees = findViewObject("employees");
    String wc = "1 = 1 ";
    String wc = " and job like '%"+job+"%'"
    if (vo_departments.getCurrentRow().getAttribute("Id") != null) {wc += "and department_id = "+vo_departments.getCurrentRow().getAttribute("Id");}
    vo_employees.setWhereClause(wc);
    vo_employees.executeQuery();
    this.sync;
    4. In your Jclient app, you just need to call the method of your appmodule and insert the string from the textbox, using code similar to this:
    AppModule b = (AppModule)panelBinding.getApplicationModule();
    b.filterEmployees(jTextField.getText());
    I didn't test this code, but that's how I go about the same thing.

  • How to create VO with multiple dynamic where clauses on select with UNION?

    I am trying to implement the View Object for the UNION query that looks like this:
         select a,b,c...
              from t1,t2,...
              where dynamic_where_clause1     
         union all
         select a,b,c,...
              from t11,t12, ...
              where dynamic_where_clause2
    There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
    So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
    I understand that recommended way with UNIONs is to wrap both queries into a parent select:
    select * from (
         select a,b,c...
              from t1,t2,...
              where ... -- table relationship joints
         union all
         select a,b,c,...
              from t11,t12, ...
              where ... -- table relationship joints
    ) QRSLT
         where dynamic_where_clause
    Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.

    I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
    I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
    Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
    Edited by: viksicom on Aug 2, 2012 8:48 AM

  • SetSelectedValue for multiple values in List Box

    Hi,
    I want to set the selectedValue for multiple values in the List Box. If i use setSelectedValue for all the values, it just highlights the last one.
    Can anyone tell me how do i highlight multiple values in the List Box?
    Scenario:
    I have one screen where the List Box and "Go" button is placed. When i select multiple values in the list box and hit "Go" it should display what i have selected in the List Box.
    Note: List Box is generated dynamically.
    Thanks,
    Naresh V

    setSelectedValue as the name indicates will set one value and in your case since you are using it multiple times it would pick the last value.
    When the user selects multiple values from the list box and clicks on Go you can capture those values in the controller for processing. What are you trying to achieve by resetting all the selected values on the same listbox ?

  • Dynamic Where clause in 4.6C [Literals allowed but not variables]

    Good afternoon-
    We have a dynamic select statement that works perfectly in 4.7 ext 2, but is causing a short dump in 4.6C. The error in the short dump says:
    The current ABAP/4 program attempted to execute an ABAP/4 Open SQL       
    statement containing a WHERE condition of the form WHERE (itab) or       
    WHERE ... AND (itab). The part of the WHERE condition specified at       
    runtime in the internal table itab contains an invalid                   
    value "HDR_COMP_CODE". Literals are allowed as values, but not variables.
    HDR_COMP_CODE is in incoming parameter to the function module that is calling this code. It is of type BKPF-BUKRS.
    Here is the code:
    DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
            TEXT_LINE(60) TYPE C,
      END OF L_WHERE_CLAUSE.
      CLEAR L_WHERE_CLAUSE.
      IF NOT HDR_COMP_CODE IS INITIAL.
        SELECT SINGLE KTOPL
        INTO LV_KTOPL
        FROM T001
        WHERE BUKRS = HDR_COMP_CODE.
        L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'AND'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'AND'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
      ENDIF.
      L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
      APPEND L_WHERE_CLAUSE.
      CLEAR  L_WHERE_CLAUSE.
      SELECT BSAKNR TTXT50
      INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
      FROM  SKB1 AS B INNER JOIN SKAT AS T
         ON TSAKNR = BSAKNR
      WHERE (L_WHERE_CLAUSE).
        APPEND LT_GL_ACCOUNT_DATA.
        CLEAR  LT_GL_ACCOUNT_DATA.
      ENDSELECT.
    This EXACT query works in 4.7, has anyone run into this, or can they tell me why I might be getting the error?
    Thanks,
    Andy

    Well, in this case, unless I'm missing something,  you do not requre a dynamic WHERE clause.  You can use RANGES instead.
    report zrich_0001.
    *DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
    *TEXT_LINE(60) TYPE C,
    *END OF L_WHERE_CLAUSE.
    ranges: r_bukrs for t001-bukrs.
    ranges: r_ktopl for t001-ktopl.
    *CLEAR L_WHERE_CLAUSE.
    IF NOT HDR_COMP_CODE IS INITIAL.
    clear r_bukrs. refresh r_bukrs.
    r_bukrs-sign = 'I'.
    r_bukrs-option = 'EQ'.
    r_bukrs-low = hdr_comp_code.
    append r_bukrs.
    SELECT SINGLE KTOPL
    INTO LV_KTOPL
    FROM T001
    WHERE BUKRS = HDR_COMP_CODE.
    clear r_ktopl. refresh r_ktopl.
    r_ktopl-sign = 'I'.
    r_ktopl-option = 'EQ'.
    r_ktopl-low = lv_ktopl.
    append r_ktopl.
    *L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'AND'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'AND'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    ENDIF.
    *L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    SELECT B~SAKNR T~TXT50
    INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
    FROM SKB1 AS B INNER JOIN SKAT AS T
    ON T~SAKNR = B~SAKNR
    WHERE  b~bukrs in r_bukrs
      and  t~ktopl in r_ktopl.
    APPEND LT_GL_ACCOUNT_DATA.
    CLEAR LT_GL_ACCOUNT_DATA.
    ENDSELECT.
    Regards,
    Rich Heilman

  • Dynamic WHERE Clause in a Calendar

    I would like to have a Calendar display values based on a dynamic WHERE clause created using PL/SQL anonymous block evaluating the values of items that the user uses as filters. I have done this dynamic SQL for reports and would lke to do the same for a Calendar.

    I figured out how to do this.
    I created a Hidden Item with the source value of &APP_USER.
    named P50_APP_USER.
    This is how my query looks now:
    SELECT * FROM APX_EVENT WHERE APX_EVENT.STORE_NR IN (SELECT APX_Z.STORE_NR FROM APX_Z WHERE APX_Z.USERNAME = :P50_APP_USER)
    And it works.
    I got the answer from this thread:
    CALENDAR - SQL ORDER BY CLAUSE NOT WORKING

  • Dynamic where clause in "delete itab where..." variant

    Hi,  I need to be able to delete the contents of an internal table based on a dynamic where clause. I don't want to loop through the entire table to test each record.  Since the delete statement doesn't seem to allow a dynamic "where" clause I am trying to use a macro.  I can't get the macro to work either. 
    I get the following error in my syntax check:
    Statement concluding with "...FINAL_STATEMENT" ended unexpectedly.          
    Is there any way to get this macro to pass the syntax text or accomplish the dynamic delete?
    MACRO TO FILTER OUT UNWANTED RECORDS (RETAIL OUTLETS)
      DEFINE DELOUT.
        DELETE MY_ITAB WHERE &1.
      END-OF-DEFINITION.
    Example FINAL_STATEMENT = (  ZRRDIVIS = '4' )
    USING MACRO DOES NOT PASS SYNTAX CHECK
      DELOUT FINAL_STATEMENT.

    Well, if you really need this kind of functionality,  here is a code sample that I just threw together that would work.  A lot of code for one little delete statement though.
    report zrich_0001 .
    data: begin of itab occurs 0,
          fielda type c,
          fieldb type c,
          fieldc type c,
          end of itab.
    data: where_clause type string.
    class lcl_source definition.
      public section.
        types: t_source(72).
        class-data: routine(32) value 'TEMP_ROUTINE',
                    program(8),
                    message(128),
                    line type i.
        class-data: isource type table of t_source,
                    xsource type t_source.
        class-methods: execute_source importing im_clause type string.
    endclass.
    start-of-selection.
    * Build the itab.
      itab-fielda = '1'.
      itab-fieldb = '2'.
      itab-fieldc = '3'.
      append itab.
      itab-fielda = '3'.
      itab-fieldb = '2'.
      itab-fieldc = '1'.
      append itab.
    * Set the where clause
      where_clause = 'FIELDA = ''1''.'.
    * call the delete statement.
      call method lcl_source=>execute_source
                exporting
                    im_clause = where_clause.
    *       CLASS lcl_source IMPLEMENTATION
    class lcl_source implementation.
      method execute_source.
        xsource = 'REPORT ZTEMP_REPORT.'.
        insert xsource  into isource index 1.
        xsource = 'FORM & tables itab.'.
        replace '&' with routine into xsource.
        insert xsource  into isource index 2.
        xsource = 'Data: begin of xitab occurs 0,'.
        append xsource to isource.
        xsource = 'fielda type c,'.
        append xsource to isource.
        xsource = 'fieldb type c,'.
        append xsource to isource.
        xsource = 'fieldc type c,'.
        append xsource to isource.
        xsource = 'end of xitab.'.
        append xsource to isource.
        xsource = 'xitab[] = itab[].'.
        append xsource to isource.
        concatenate 'DELETE xITAB WHERE' im_clause into xsource
                      separated by space.
        append xsource to isource.
        xsource = 'ENDFORM.'.
        append xsource to isource.
        generate subroutine pool isource name program
                                 message message
                                 line line.
        if sy-subrc = 0.
          perform (routine) in program (program) tables itab.
        else.
          write:/ message.
        endif.
      endmethod.
    endclass.
    Regards,
    Rich Heilman

  • Creating dynamic where clause with string delimiter " ; "

    hi...
    i need a solution for complex problem like, 1. start_date IN date,
    end_date IN date,
    shift_type IN varchar2
    i will get shift_type as "first_shift" or "first_shift;second_shift" or "first_shift;second_shift;third_shift" ....etc any combination. where fist & second & third shits are nothing but 1 , 2 , 3. i need to find out data between start_date and end_date in combination of shifts ( may be 1;2 or 1;3 or 1;2;3 or 2;3 ...etc) . now i need to write this code in dynamic where clause ...i tried in different ways...but not succeeded. can anybody guide me step by step...or with script.
    NOTE: there is a table called "shift" with data like
    shift_type shift_mode
    1 first_shift
    2 second_shift
    3 third_shift

    Hi,
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    If the question involves parameters, give a few different sets of parameters and the results you want for each set, given the same sample data.
    It's unclear that you need dynamic SQL at all.
    If shift_type is a variable, that can be either a single value or a ;-delimited list (such as '1;3'), you can compare that to a column called shift_column like this:
    WHERE        ';' || shift_type   || ';'     LIKE
           '%;' || shift_column || ';%'No dynamic SQL or PL/SQL required.
    If you really do want to use dynamic SQL, these two pages should gives you some ideas:
    http://www.oracle-base.com/articles/misc/DynamicInLists.php
    http://tkyte.blogspot.com/2006/06/varying-in-lists.html

Maybe you are looking for

  • Diagnosing cause of kernel panic on a Mac Pro

    I've got an early 2009 Mac Pro with the following specs: 2.66 GHz Quad-Core Intel Xeon 16 GB 1066 MHz DDR3 ECC NVIDIA GeForce GT 120 512 MB OS X 10.8.1 Problem is, at random times, my Mac would just shut down and then restart after I clicked through

  • SVGA to RCA cable TV not working

    I have a Macbook and I bought SVGA to RCA cable that I connect to the adapter from my Macbook so I can try to use it with my TV. The SVGA to RCA cable prongs are green, red and blue and are designed for HDTV. I am trying to connect the Macbook to a S

  • KSPP -Scheduled Activity are not updated for last 2 periods

    Hi All, When we run KSPP by using LTP, noticed that for one cost center and activity type the plan scheduled Acivities are not updated for last 2 period's.(shows Zero) Do we miss any thing. Regards, Raj

  • I don't have the option "Create from Scanner".  How do I scan my documents?

    I am trying to scan multiple documents (to save and email), but I don't have the option of "Create from Scanner" on the Adobe Reader XI.  How do I scan my documents (multiple pages on one file, not each page on a seperate file)?

  • Quick time will crash when opening movies

    I am using MS Vista 32bit, with 2 Invida cards. I installed QuickTime 7 with out any errors, but when I try to open a movie QuickTime will immediately close with the lovely "QuickTime player has stopped working, windows will close the application and