How to solve where clause matter when it can have a value or be null.

Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

Hello, I am trying to understand how a query in which I have a where clause clause that can be null or a value, that is to say:
SELECT   supply,
              duration,
              count,
              action
FROM     MDR
WHERE    (client     = gbl_client OR (group = gbl_group AND section = gbl_section ))
AND      (prov_code   = gbl_prov_code );
In the query, the gbl variables can have a value or be null, based on the results of a previous cursor. The problem is that if they have the value NULL, I don't get the correct results because where clause will have to be modified to be checked IS NULL instead of = gbl. Is it possible to do it by modifying select it?

Hello

Because these columns are all strings, the CONCAT method will work fine:

SELECT     *
FROM     mdr
WHERE     '?' || grp       = '?' || glb_grp         -- GROUP is not a good column name
AND     '?' || section    = '?' || glb_section
AND     '?' || prov_code  = '?' || prov_code
;

I think that the code is a little nicer with the '?' before the actual data. No matter whether it is before or after, just be consistent.

Published by: Frank Kulash, January 25, 2011 15:59

Tags: Database

Similar Questions

  • How to solve the error 49 when the photoshop trial download?

    How to solve the error 49 when the photoshop trial download?

    Hello, Scarlett,.

    Please see the below help document to solve the problem:

    Download error, installation or update of Cloud Creative applications

    You can also see the thread below where the issue has been addressed:

    CC of Photoshop update failed. Download error 49

    Kind regards

    Sheena

  • How only include a WHERE clause only when a connection variable has a value?

    I use JDeveloper 11 g using business components of the tables. I'm now modify the auto-generated SQL code to include WHERE clauses which depend on the values of bind variables. For example I have something like this:
    SELECT mytable.firstColumn
    FROM myTable 
    WHERE myTable.secondColumn= :VariableValue
    However, this means that when VariableValue is null SQL would fail and I get an error. Is there a way I can include the WHERE clause (or clause AND according to the position in SQL) only when a bound variable has a value (or a particular value)?

    Or use: WHERE NVL(:VariableValue,myTable.secondColumn) = myTable.secondColumn

  • How to change where clause in VO interview at the bean

    Hi experts

    I need to change vo object query where clause execution... is - it possible?

    If so please suggest me.

    as mentioned by Timo, it is quite possible

    See this link-

    Change in the WHERE clause or query on VO when running in Oracle ADF | Techartifact

    Dynamically change the query in the view object in Oracle ADF | Techartifact

  • ADF business components: how to apply where Clause to the new lines

    Hello world.
    I develop Web Application from merger under Jdeveloper 11.1.1.0.1.
    I read this post http://blogs.oracle.com/jheadstart/rowmatch/
    And I have a question. How should I configure rowmatch if I instance the same viewobject except 2 2 viewobject defined on the same entity.

    If you use view criteria to make your filtering and scoring mode 'filter' of the Victoria Cross to be "Both" (database and in-memory), then the framework will automatically use your filter to filter the lines again without having to write code or use your own rowMatch object.

  • How to add where clause in LOV... ?

    Hello

    I want to set the dynamicaaly value to the VO LOV.
    But I get errors of

    java.sql.SQLException: parameter IN or OUT to missing index: 1

    Invalid column type

    Please help me on this?

    Hello

    use

    String where_clause = "COST_ALLOCATION_KEYFLEX_ID LIKE ' %: 1" ";
    vo.setWhereClause (where_clause);
    vo.setWhereClauseParam(0,rc);

    Thank you
    Pratap

  • How do I recover my msn when I can't put in a claim for another 24 hours my account was hacked twice in 24 hours

    I can't access my other accout due to a hacker I deleted my account this morning and they have hacked into again I want to retrieve my contact list and to close the account please someone HELP me

    Contact your mail service provider for email account problems.

  • Plugin Automation: how to select a spot channel when 2 channels have the same name?

    I have a CMYK document open in photoshop. In the "LAYERS" Panel, I just added 2 tones with the same name "color 1" Sport.

    I click on the spot channel to select, the "Listener" plugin will be released a few c ++ code like below:


    SPErr PlayeventSelect(/*your parameters go here*/void)
    {
    Result PIActionDescriptor = NULL;
    DescriptorTypeID runtimeKeyID;
    DescriptorTypeID runtimeTypeID;
    DescriptorTypeID runtimeObjID;
    DescriptorTypeID runtimeEnumID;
    DescriptorTypeID runtimeClassID;
    DescriptorTypeID runtimePropID;
    DescriptorTypeID runtimeUnitID;
    SPErr error = kSPNoError;
    Move it to the top of the routine!
    PIActionDescriptor desc0000000000003980 = NULL;

    error = sPSActionDescriptor-> Make (& desc0000000000003980);
    If (error) goto returnError;

    Move it to the top of the routine!
    PIActionReference ref0000000000001A48 = NULL;
    error = sPSActionReference-> Make (& ref0000000000001A48);
    If (error) goto returnError;

    error = sPSActionReference-> PutName (ref0000000000001A48, classChannel, "1 Spot color");
    If (error) goto returnError;

    error = sPSActionDescriptor-> PutReference (desc0000000000003980, keyNull, ref0000000000001A48);
    If (error) goto returnError;

    error = sPSActionControl-> Play (& result, eventSelect, desc0000000000003980, plugInDialogSilent);
    If (error) goto returnError;

    returnError:
    If (result! = NULL) sPSActionDescriptor-> Free (result);
    If (desc0000000000003980! = NULL) sPSActionDescriptor-> Free (desc0000000000003980).
    If (ref0000000000001A48! = NULL) sPSActionReference-> Free (ref0000000000001A48).
    error return;
    }

    -------------------------------------------

    You can see "PutName" adds the name of the channel 'Spot color 1' to make reference to and I think it will not work properly if I add such a code for my project as the PS can not differentiate the 2 channels than by their name. Can someone tell me if there is another method of selecting channel spot? Thanks in advance.

    Hello

    Here's something tht docs, you may find useful.

    Index of Tryusing instead of name:

    SPAPI OSErr (*) ( PutIndex ) (RefPIActionReference , DescriptorClassIDdesiredClass, uint32 value)
    Puts an index into a reference ( formIndex ) as well as the class desired for reference.

    Unfortunately I do not have C++ here to try I used just definition of documentation.

    Hope this helps.

    Kind regards

    Momir Zecevic

    ARS media

    www.Arsmedia.TV

  • How to create a procedure for REF CURSOR output with any WHERE clause?

    I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.

    I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.

    i.e.
    PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
    BEGIN
    
      OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
    
    END;
    The foregoing gives an error.

    How to handle such a situation? Any help would be greatly appreciated.

    Hello

    Channa wrote:
    ... However, when I change the procedure like this:

    PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
    v_stmt VARCHAR2(1000);
    BEGIN
    v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
    
    OPEN p_out_cursor FOR v_stmt using p_where_cluase;
    
    END;
    

    And run this block of code:

    declare
    v_tname varchar2(200);
    out_cursor sys_refcursor;
    begin
    forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
    LOOP
    fetch out_cursor INTO v_tname;
    exit when out_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_tname);
    END LOOP;
    end;
    /
    

    I get the error:

    [1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
    

    Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?

    A bind variable, such as: it, represents a single value.
    If: is the VARCHAR2 '1 = 1', then

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
    

    takes the value

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
    

    I think you want something like this:

    CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST
    (     p_where_clause      IN      VARCHAR2
    ,      p_out_cursor      OUT      SYS_REFCURSOR
    ) IS
      v_stmt VARCHAR2(1000);
    BEGIN
      v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND '
              || p_where_clause;
    
      OPEN p_out_cursor FOR v_stmt;
    
    END;
    /
    show errors
    
    SET  SERVEROUTPUT  ON
    
    declare
      v_tname varchar2(200);
      out_cursor sys_refcursor;
    begin
      forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
      LOOP
        fetch out_cursor INTO v_tname;
        exit when out_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(v_tname);
      END LOOP;
    end;
    / 
    

    Output:

    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    
  • When I insert a memory card in my PC not using windows 10 I suddenly for no apparent reason get a no found the message of photos. How to solve it?

    When I insert a memory card in my PC not using windows 10 I suddenly for no apparent reason get a no found the message of photos. How to solve it?

    Looks like you have a card reader malfunctioning.

    You can connect the camera to the computer via the USB cable provided with the camera to see if the pictures can be read like that?

  • Case statement in a WHERE clause

    Gurus,

    Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.

    Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.

    and case  when 'New Items' = 'xxx' --p_item_status 
             then  msi.creation_date = msi.last_update_date
          when 'Updated Items' = 'bbb' --p_item_status  
             then  msi.creation_date != msi.last_update_date
          else 1=1
    end;  
    Points for correct and helpful answers!

    Published by: sreese on March 27, 2012 17:51

    Hello

    The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:

    WHERE     (     :p_item_status        = 'New Items'
         AND     msi.creation_date  = msi.last_update_date
         )
    OR     (     :p_item_status        = 'Updated Items'
         AND     msi.creation_date  != msi.last_update_date
         )
    OR     (     :p_item_status        NOT IN ( 'New Items'
                               , 'Updated Items'
                               )
         )
    

    This guess: p_item_status is not NULL.
    If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition to

    OR     ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items'
                                 , 'Updated Items'
                                 )
         )
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • My watch connects the cloud. How to solve the problem

    I associated with my new iPhone 6 s more the iWatch after reset. He was previously associated with my iPhone 5s and worked perfectly. The software on all phones are up-to-date and Bluetooth is on. My problem is that the watch disconnects from the phone if the phone is not connected to the wi - fi in the House. It will automatically reconnect when I go in the House. How to solve this? It shows that it is connected to the cloud when I go in the House. I don't know how it happened. Even when I désapparier it from the phone, that he still continues to show as connected to the cloud. How to solve this.

    HI - it can help try the following steps:

    On your watch, go to: homescreen (via a simple press on the digital Crown) > (cog icon) settings > general > reset > erase content and settings.

    Then match your watch in your iPhone again, choose either backup restore (if the option is available) or set up as a new watch.

    Before doing so, it may be useful to close open applications on your iPhone (double-click the Home button and then drag upward on each app preview) and also to restart your iPhone.

    - Set up your Apple Watch - Apple Support

    For best performance, keep the Bluetooth and Wi - Fi enabled at all times on your iPhone (settings > Bluetooth settings > Wi - Fi).

  • My 2 year old somehow gave a password on our computer and now we can get in our office. Without having to return to the default settings, anyone have a suggestion on how to solve this problem?

    My 2 year old somehow gave a password on our computer and now we can get in our office.  Without having to return to the default settings, anyone have a suggestion on how to solve this problem?

    If you have a different user account with administrative privileges, Panel you can connect that account and change the password of your account of origin of the user accounts applet in Control Panel. If you do not have another account like this set upwards or that you do not have the password which you will need to log on to the built-in Administrator account. In XP Home, start the computer in Mode safe. This, by repeatedly pressing the F8 key as the computer starts. This will put you in the right menu. Navigate using your arrow up; the mouse does not work here. Once in safe mode, you will see the normally hidden administrator account. The default password is white.

    In XP Pro, you don't need to go to Safe Mode. In the home screen, do Ctrl-Alt-Del twice to get the classic Windows logon box. Type in "Administrator" and the password that you assigned when you set up Windows.

    MS - MVP - Elephant Boy computers - don't panic!

  • How to solve error code: 82 downloading creative cloud?

    How to solve error code: 82 when you download the most recent version of the creative cloud?

    Close the aam:

    (win) - end a process - Windows help

    (mc) - Activity Monitor: exit a process

  • a slightly different similar query where clause

    Hi all, I am facing a problem with my request.
    I have a query that looks like this

    with names like
    (select name, lastname, id
    FROM table1
    where id = 1
    and type = "enu".
    and asset = 'other '.
    and cashid = 2
    and $vdate = system_date
    )
    Select * from names
    (< joins with other tables)

    the thing is that enu value is past as parameter of the procedure. This is only of value if away from the front end.
    further, I have to spend 2 different values now ("cae", "peq")
    However, for these two values, of what I need not use the active column in where clause and the cashid will have to be change to cashid in (3.4)

    I was thinking a dynamic query construction and function of the value pass, I'll build the query. I am looking for another way to implement these changes with minimal impact on the code. Anyone know how to go around this case?

    with these two new values for the query are very similar with the exception of the active column that is more use and cashid will include an IN clause. only a value will be in the procedure, either enu, cae, peq. for enu, the query must be as above, but for the other two active column values are not in the query and cashid must be cashid in (3.4). How to take care of these scenarios
    with names as
    (select name, lastname, id
       from table1
      where id = 1
        and (
        (type = 'enu' and asset = 'others' and cashid =2)
        or
        (type in ('cae','peq') and cashid in (3,4))
        )
        and vdate = system_date
    )
    select * from names
    
    

    Max

Maybe you are looking for