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

Tags: Java

Similar Questions

  • How to dynamically generate where clause in Linq

    Hi all


    Oracle DB: 11 gR 2
    Oracle Client: 11.2.0.3.0 (ODP.NET)
    Oracle Developer Tools for Visual Studio
    VS 2010 (C#)

    In a Windows Form, it must query the data based on the values in list dropdown listboxes, which the user selects.
    Let's say two combox, one Department and one for salary
    Department:
    -1 all the
    10 Department 1
    20 Department 2
    30 Department 3

    Salary:
    -1 all the
    1 < 20000
    2 20000 to 50000
    3 50000 to 100000
    4 > 100000


    Here is the c# code to query data:
    using (var myEDMctx = new HREntities())
    {
    var LINQrslt = from emp in myEDMctx.EMPLOYEES
    Select emp;

    }


    The default values for the two combox should be everything.
    How to write dynamic where clause for this LINQ?

    Thanks in advance!

    That's what I do.

    var query = from c in customers
    Select c;

    If (where1 > - 1).
    Query = query. Where(c.Where1 > where1);

    If (where2 > - 1).
    Query = query. Where(c.where2 == where2);

    to return the query;

    Published by: Invincible on July 4, 2012 09:25

    Published by: Invincible on July 4, 2012 09:27

  • Windows Live ID typo, how to remove this pop-up list when I connect?

    Windows Live ID typo, how to remove this pop-up list when I connect?

    Post Windows Live questions in the appropriate forum found here:
    http://windowslivehelp.com/

  • 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

  • [JDev ADF] How is made the ' where clause ' default display criteria "all searchable attributes?

    Hallo,


    on a view object, I create my view of the criteria customized; I'm going to use it to create a "query with the table panel.

    I wish that his beahviour, when I use it to create a "query with the table panel", corresponds to that of "attributes searchable all.

    Unfortunately I'm having some trouble in his creation and I would like to see how is made the "object view where Clause" CV "all searchable attributes.

    My VO motion is:

    Select the username, name, RegisteringDate

    I would like to create my VC in a way that is the result "query with table Panel:

    UserId | ___ |

    Name | ___ |

    RegisteringDate of | ___ | to |_________|

    For each search field, I set a variable binding (PName, PUserId, PRegisteringDateTo, PRegisteringDateFrom).

    Each field must be used in the "query with table Panel" only if it is filled with a value.

    You kindly help me?

    Thank you very much

    F.

    The criteria to view all searchable attributes is implied all the attributes of a vo. Each attribute is used unless you specify a value for it. The problem with this IS, is that you can not change it.

    However, you can build your own RESUME that works in the same way, but allows you to change certain attributes. To do this, you create a new business card and add each attribute, select the operation you want to test the attribute against (equals, start by,...). You do not bind variables for attributes specify. The framework will add them for you automatically.

    The only thing that can not this vc is check varies as you want to do when you check "RegisteringDate." To do this you must use bind variables.

    Once you have create this EGG and it makes you drag onto the page you can use it as the "all attributes searchable.

    Timo

  • How to define a WHERE clause of the subquery in a bean managed?

    Hi people,

    is it possible to define the place where clause of a subquery in a bean managed?
    For example, it is more SQL charly:

    SELECT * FROM
    (SELECT Person.Name
    OF the person)

    To change or add a WHERE clause, I use following code for the 'viewObject: view

    String whereClause = "ROWNUM < =: numberOfRows;
    viewObject.setWhereClause (whereClause);

    viewObject.defineNamedWhereClauseParam ("numberOfRows", null, null);
    viewObject.setNamedWhereClauseParam ("numberOfRows", new Number (100));

    AttributeList myattr = this.getNamedWhereClauseParams ();
    viewObject.setNamedWhereClauseParams (myattr);

    For example, this code works well for the first SELECT statement limit the output to the first 100 results. But how do I add a WHERE clause of the subquery in a managed bean? For example, when I want to limit the names of people that begin with the letter "A"?
    The query should look like this:

    SELECT * FROM
    (SELECT Person.Name
    OF the person
    WHERE Person.Name LIKE 'A %')

    Anyone know more?

    Thank you!

    Put a variable binding in your query, something like:

    where (: bv is null) or (xxx love: bv)

    John

  • How to compare in Where clause

    Hello

    I need help comparing the value in where clause


    There is a table called productivity which has columns as
    OBJECT_TYPE, COMPLEXITY, OBJECTIVE


    Now my requirement is I have a query like this


    SELECT
    PRO. PROJECT NAME,
    POBJ. OBJECT_NAME,
    POBJ.COMPLEXITY,
    PRO. EFFORT
    Of
    PROJECT PRO, PROJECT_OBJECTS POBJ
    WHERE
    PRO.ID = POBJ.ID

    I have to compare data between the effort of columns in the query and target in the table of productivity

    SELECT
    PRO. PROJECT NAME,
    POBJ. OBJECT_NAME,
    POBJ. OBJECT_TYPE,
    POBJ.COMPLEXITY,
    PRO. EFFORT
    Of
    PROJECT PRO, PROJECT_OBJECTS POBJ
    WHERE
    PRO.ID = POBJ.PRO_ID



    now I change the query to compare


    SELECT
    PRO. PROJECT NAME,
    POBJ. OBJECT_NAME,
    POBJ.COMPLEXITY,
    -case when
    POBJ. OBJECT_TYPE IN (SELECT OBJECT_TYPE OF PRODUCTIVITY) AND
    POBJ.COMPLEXITY (SELECT COMPLEXITY OF PRODUCTIVITY)
    PRO. EFFORT > (SELECT GOAL OF PRODUCTIVITY WHERE type_objet =? AND
    COMPLEXITY =? ) / / here instead of? I have to say
    POBJ. OBJECT_TYPE and POBJ.COMPLEXITY
    then
    10
    ON THE OTHER
    0
    END "Effort."
    Of
    PROJECT PRO, PROJECT_OBJECTS POBJ
    WHERE
    PRO.ID = POBJ.PRO_ID


    How to specify this POBJ column. OBJECT_TYPE and POBJ.COMPLEXITY in please of? I put please suggest.

    Is there a way where we can spend the value of POBJ. OBJECT_TYPE and POBJ.COMPLEXITY to a variable binding and select it in the where clause

    Indicate please let me know if this issue is not understood.


    Thank you
    Sudhir

    Something like that, maybe?

    SELECT PRO.PROJECT_NAME,
           POBJ.OBJECT_NAME,
           POBJ.COMPLEXITY,
           case when PRO.EFFORT > PROD.GOAL
                     then 10
                ELSE 0
           END "Effort"
    FROM   PROJECTS PRO,
           PROJECT_OBJECTS POBJ,
           PRODUCTIVITY PROD
    WHERE  PRO.ID = POBJ.PRO_ID
    AND    POBJ.OBJECT_TYPE = PROD.OBJECT_TYPE (+)
    AND    POBJ.COMPLEXITY = PROD.COMPLEXITY (+)
    

    I did an outer join; don't know if that's what you want - if not, just get rid of the (+) {noformat} {noformat}

  • where clause to see if they contain the null value

    So I've finalized my function but now am having some problems:

    the bl field (or the v_bl parameter) has null values in it. When I run the function using the "Select FH ('ACCESS', NULL, 8675309') From dual; I get a NULL return value because it uses the variable to compare with q.bl and you can not have q.bl = null in a Where clause.

    The main problem is when the parameters are passed, a line can have the same prob and site, but the bl might be different as null, which would give a different lname.


    In where clause I need to have something that will compare the parameter with the bl field. Sometimes it's null sometimes is not, but we need to find the line concerned. I made the "BOLD" in the question police

    Here are two possible lines in the data
    prob bl site lname
    ACCESS Smith 8675309 (null)
    54321 8675309 Johnson ACCESS

    so in theory, if the function is called with the parameters FH ('ACCESS', NULL, 8675306')
    He would return the lname: Smith

    and conversely FH ("ACCESS", "54321 ', 8675309") would return Johnson

    Here's the function

    create or replace
    Function FH
    (v_prob IN varchar2, v_bl IN varchar2, v_site IN varchar2)
    RETURN varchar2
    AS
    v_lname varchar2 (16);

    BEGIN

    S.Lname SELECT INTO v_lname
    Of
    request q
    JOIN THE
    s response
    On
    (q.order = s.order)

    WHERE
    q.BL = v_bl AND - where it is
    q.site = v_site AND
    q.prob = v_prob AND
    s.Lname IS NOT NULL;

    RETURN v_lname;
    END;



    -When I run the FH ('ACCESS', NULL,' 86753) function, it returns an empty value and not the family name

    Published by: user11210446 on May 28, 2009 17:03

    Published by: user11210446 on May 28, 2009 17:03

    user11210446 wrote:
    If v_bl is Null in the where clause it would even say q.bl = Null which will not work.

    Matches the NULL value
    (1) either you have to say-> q.bl IS NULL
    OR
    (2) WHERE the NVL (q.bl-99) = NVL (v_bl-99) - this will be true if q.bl and v_bl both are NULL
    NULL = NULL evaluates to TRUE, so you use NVL

    SS@XE > select * from dual where null = null ;
    
    no rows selected
    
    SS@XE > select * from dual where null is null ;
    
    D
    -
    X
    
    SS@XE > select * from dual where NVL(null,-1) = NVL(null,-1) ;
    
    D
    -
    X
    

    SS

  • * Displays an invisible field when a database field has a value specified? !!

    Hi all
    I have two fields, a database and a database not
    IAM using a LOV to return the values of these two areas, I want to display another invisible field only when the database has filed the value returned by the LOV is equal to a specified value.
    I used a trigger WHEN-VALIDATE-ITEM on this field (named db_field) db with this code:

    DECLARE
    IT_ID POINT;
    BEGIN
    IT_ID: = FIND_ITEM ('item'); -It's the invisible element that I want to appear
    IF: db_field = 'some_value' THEN
    Set_Item_Property (IT_ID, visible, PROPERTY_TRUE);
    Set_Item_Property (IT_ID, Enabled, PROPERTY_TRUE);

    ON THE OTHER
    Set_Item_Property (IT_ID, visible, PROPERTY_FALSE);
    END IF;
    END;

    This trigger works fact (the same result as after the CHANGE and POST-TEXT-POINT), but the "article" field is released after leaving this db_field!
    I want to show this 'subject' field after returning from the value of the LOV directly not after leaving the db_field
    How to do this please?

    Hello

    You must have a when button pressed trigger, associated with the LOV... right?
    Typical code inside that would be:

    go_item ('db_field');
    do_key ('list_values');

    You must write the code that you wrote below after that. No need for when-validate-item trigger here.
    If your code in when-pressed button LOV trigger associated with db_filed should be as below:

    DECLARE
      IT_ID ITEM;
    BEGIN
      go_item('db_field');
      do_key('list_values');
      IT_ID := FIND_ITEM('item'); -- this is the unvisible item that I want to appear
      IF :db_field = 'some_value' THEN
         Set_Item_Property(IT_ID,VISIBLE,PROPERTY_TRUE);
         Set_Item_Property(IT_ID,ENABLED,PROPERTY_TRUE);
      ELSE
         Set_Item_Property(IT_ID,VISIBLE,PROPERTY_FALSE);
      END IF;
    END;
    

    It will be useful.

    Check the answer as useful / OK, if this can help you

    Carole

  • DW CS6 test server shows only the login screen of my site. Can't do under the hood live wiew. The pages I want to change/modify is visible only when I connect but I do not know how to reolve that.

    I'm trying to edit a CMS site to my needs and "open" pages is not serious, that is to say those that do not require the user to connect to. I can see and I can modify them according to my needs.

    The trickiest part is when I want to change/modify something inside. Then it wont let me. The only thing I see is the "Login" screen I can see the code and I can do what I need, but when I turn on 'Live wiew' is the log in page that greets me


    Tests of servers is correct because I can use it in my localhost

    Connection MySQL works as it should (Test OK)

    I guess that's something that has to do with permissions, but I don't know what.

    A CMS site, the page is usually filled with data that is stored in a database using a scripting language on the server side. Unfortunately, the Design mode only supports a static language like HTML, there is therefore no recovery information from the database.

    The only way out of your situation is to temporarily remove the permission to the user to the page that you are editing so that you do not to log-in each time. The problem is that you may forget to reactivate the authorization.

    What I always do is to open the site in a browser and verify the change in DW refreshing the page in the browser. In this way, you need to log-in once.

  • Fix problem 'local only' when the connection is through a wireless connection

    access point appear: unidentified network
    Internet appear bloqued

    access: Local only
    connection: Wi - Fi connection.

    Please help verify what is the reason for which "local only".
    IP is assigned automatically by DHCP, but is not possible to connect to the internet, the problem appears only on windows vista PC, in my other computer with XP, version the connection is good.

    I have Microsoft Windows Vista Home Premium SP1.

    Thank you

    Check how your security is configured on your access point.  I had to mess with mine a bit.  For some reason, my machines windows 7 were sensitive, in particular on the netgear access point

  • Windows Live Messenger connected poster with a UPnP port not restricted NAT ONLY when I connect.

    LIV emessenger shows that I am connected with a port unrestricted UPnP NAT ony when I sign in to messenger.  If I look under tools/options/connection before sign in or under different username s, there is no problem.  Why is this and how to fix it.  I don not use a router, or have a webcam.  Thank you!  revgriz

    Thank you for visiting the Microsoft answers community site.

    The question you have posted is related to Windows Live Messenger and would be better suited in the Windows Live Solution Center.

    Please visit the link below to find a community that will support what ask you:

    http://windowslivehelp.com/forums.aspx?ProductID=2

    Cody C
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • My Vista computer connect wireless, but it remains on local only when I connect via Ethernet his local and Internet

    I tried everything in the other blogs. I disable the and uninstalled the wireless card and disabled buttons 6 and 4. I also manually put the address ip and nothing.

    Hello

    • What were the changes made before the problem occurred?

    You can check this link:

    Wired and wireless network connection problems in Windows

    http://Windows.Microsoft.com/en-us/Windows/help/wired-and-wireless-network-connection-problems-in-Windows

  • Combine values separated by '&amp;' only if the second field has a value.

    I try to combine the 2 fields and add & symbol between the two, but only if there is in the second text field.  In this way, I wouldn't end up with "names of seller: Joe Smith &" If there was only one seller name.

    Here is my current script is add automatically of course "and" all the time.

    Get the field values as strings

    var s1 = getField("s1").valueAsString;

    var S2 = getField("s2").valueAsString;

    Combine values, separated by &

    Event.Value = s1 + '&' + s2;

    Replace the last line with:

    Event.Value = s1;

    If (s2! = "" ") event.value +="&"+ s2;

  • Can someone tell me how to view a different main menu when someone connects?

    When a client is connected, they can view secure pages. I also want a different menu from appearing when you are connected, and you must be offline I want the menu to return to normal. Can someone help please? Let me know if you need information about me. Thank you in advance!

    I recommend referring to the post on the forum on how to achieve this: Re: Secure area - show, hide, or disable content when a user is recognized as registered.

    To sum up, you need to use the {module_isloggedin} module that will make a 0 or 1 depending on whether the client is connected or not. With a combination of CSS/JS, you can specify another menu to display based on whether they are connected or not.

Maybe you are looking for

  • How do the smaller letters in the mail?

    When I go to the emails, all the letters are so large that only about 4 or 5 mails can be there at the same time.need to know how to make them smaller.

  • Ericsson 3G F3607gw - Question on the parameters

    We have different models of Toshiba (A11, M11, S11, R600, R700) with internal 3G card Ericsson F3607gw.After the new installation of the laptop with Windows 7 (no upgrade) and the driver version "R3M03" for the card 3G, the network card is not proper

  • Power supply drive hard 320 is death - where to find replacement?

    Hello The power supply for my 320 GB external hard drive (PX1223E - 1 32) that I bought a year ago died. I'm a little annoyed that the player has been barely used and only just out of storage after a move of the House! Can anyone help to track down a

  • Satellite Pro A210 DVD Drive not working no-error code 39

    Hi all My Satellite Pro A210 dvd player does not load.When I looked inside, he showed an error code 39.I tried uninstalling and reinstalling but it still doesn't work. Any ideas?

  • Card Pnovatel WLan PCMCIA U530 suddenly stopped working

    Suddenly, my pcmcia card from novatel wireless u530 doesn't work. My laptop began to recognize it as a map of MTD-0002 (?). I uninstalled and reinstalled several times, he pilots looking for latest drivers. The card is a Wireless Merlin U530 Novatel.