How to write the query with parameters below and is null


Hi, I need to recover the data if the parameter is passed on the ground, else retrieve all records where the field is null

Example of


CREATE TABLE DEPT
(DEPTNO NUMBER (2),)
DNAME VARCHAR2 (14).
LOC VARCHAR2 (13));

INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO VALUES DEPT (20, 'SEARCH', 'DALLAS');
insert into dept values (30, 'SALES', 'CHICAGO');
INSERT INTO VALUES DEPT (40, 'OPERATIONS', 'BOSTON');

ALTER table dept add (object_id number);
insert into dept values (50, 'OPERATIONS', 'BOSTON', 1);
insert into dept values (60, 'OPERATIONS', 'BOSTON', 1);
INSERT INTO VALUES DEPT (70, 'OPERATIONS', 'BOSTON', 2);

Select * from Department where object_id =: p_object_id

If I pass the object_id 1, it shloud retrieve the values of dept with object_id 1, but if I don't pass the object_id, it must retrieve all records where object_id is null

IF 1 is passed as the id of the object, he must recover, 50, 60, if 1 is not passed as object_id it should 10,20,30,40 retive

It works fine for me separately as,.

Select * from Department where object_id =: p_object_id - 1

Select * from Department where the object_id is null;

Is it possible to do in a single query.

Thank you

SELECT *
FROM dept
WHERE object_id = :p_object_id
OR (object_id is null and :p_object_id is null)

is an approach.  It's a little talkative, but the meaning is clear.  If you can identify a value that would never appear in the data (for example-1)

WHERE nvl( object_id, -1 ) = nvl(p_object_id, -1 );

Justin

Tags: Database

Similar Questions

  • How to write the query option in expdp

    Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...

    where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';


    Please do what is necessary...

    Pavan Kumar says:
    QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")

    Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.

    query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    

    You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.

  • How to write the script in FDMEE below.

    How to write the script in FDMEE below.

    Script below is the FDM Script.How write in FDMEE.

    If (varValues (14) '113101' =) OR (varValues (14) '113201' =) OR (varValues (14) '113301' =) OR (varValues (14) = "252111") OR (varValues (14) '156101' =) then

    Result = "21_asd."

    Please help me on this issue.

    Kind regards

    Satheesh, S

    If you want to determine the id of the target account your opening assignment statement must be:

    Account = fdmRow.getString ("ACCOUNTX")

    As if - elif-instructions else keep lowercase stream operators. If you continue a command on multiple lines, then place parentheses is

    If (account == "113101") or (account == "113201") or (account == "113301") or (account == "113401") or (account == "113501") or (account == "113601") or (account == "215101") or (account == "215201") or (account == "215301") or (account == "215401") or (account == "215501") or (account == "215601") or (account == "252111") or (account == "156101"):

    fdmResult = "21_ADNIP".

    should be (also get rid of the unnecessary parentheses)

    If (account is "113101" account is "113201" or account is '113301' account is "113401" or account is "113501" or account is "113601" or account is "215101" or account is "215201" or account is "215301" or account is "215401" or account is "215501" or account is "215601" or account is "252111" or account is "156101"):

    fdmResult = "21_ADNIP".

  • Structure of the query with parameters

    Hello
    Consume the web service, the results in a file xml with complex structures.
    The function below the structure of the query
    < TemplateName CcResultItems = "CgrInfo_1" >
    My question is how to reorganize the query to obtain the results of the structure
    < TemplateName CcResultItems = "CgrOwners_4" >
    which should return three rows.

    Kind regards
    Kostadin

    create or replace
    FUNCTION WS_SELECT_XML RETURN VARCHAR2 AS
    XML_VAR XMLTYPE: = XMLTYPE)
    "" ' < soap envelope: xmlns:soap = 'http://www.w3.org/2003/05/soap-envelope"" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" >. "
    < soap: Header >
    "< XmlSoapHeader xmlns ="https://test.wstestx.com/XWS2/ "/>"
    < / soap: Header >
    < soap: Body >
    "< ProcessRequestResponse xmlns ="https://test.wstestx.com/XWS2/">."
    < ProcessRequestResult > <! [CDATA [< CcResponse >

    < TemplateName CcResultItems = "CgrInfo_1" >
    < CcResultItem > < InfoMessage > < / InfoMessage > < IsitTerminated > 0 < / IsitTerminated > < IdObject > 365124 < / IdObject > < sanctuary ObjectlName > < / ObjectlName > < ObjectTaxNumber > 305089321502 < / ObjectTaxNumber > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrUnits_2" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrActors_3" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < UnitNo > 0 < / UnitNo > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrOwners_4" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 610697843014 < / OwnerID > < OwnerName > ALEX < / OwnerName > < / CcResultItem >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 840645947005 < / OwnerID > < OwnerName > JOHN < / OwnerName > < / CcResultItem >
    < CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 2 < / EntityTYPEcode > < company EntityTYPEdesc > < / EntityTYPEdesc > < OwnerID > 703454 < / OwnerID > < OwnerName > BROWN < / OwnerName > < / CcResultItem >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrActivities_5" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrMembership_6" >
    < / CcResultItems >
    < TemplateName CcResultItems = "CgrFounding_7" >
    < CcResultItem > < IdObject > 365124 < / IdObject > < FoundingDate > 2007-08-16 13:53 < / FoundingDate > < Total > 146701.00 < / Total > < / CcResultItem >
    < / CcResultItems >
    [[< / CcResponse >]] > < / ProcessRequestResult >
    < / ProcessRequestResponse >
    < / soap: Body >
    < / envelope soap: >
    ');
    BEGIN
    FOR R IN)
    WITH T AS (SELECT (XML_VAR) DOUBLE COLLAR)
    SELECT x2.*
    FROM XMLTable)
    XMLNamespaces)
                ' http://www.w3.org/2003/05/soap-envelope ' LIKE 'SOAP'
    , by default ' https://test.wstestx.com/XWS2/ '
    )
    , ': soap envelope / soap: Body/ProcessRequestResponse/ProcessRequestResult '
    by the way XML_VAR
    path of CcResponse clob columns '.'
    ) x 1
    XMLTABLE)
    ' / CcResponse/CcResultItems.
    XMLPARSE PASSAGE (DOCUMENT X 1.) CCRESPONSE)
    COLUMNS
    TemplateName VARCHAR2 (140) path "@TemplateName"
    , IDOBJECT VARCHAR2 (140) PATH "CcResultItem/IdObject.
    , PATH of VARCHAR2 (340) OBJECTLNAME ' CcResultItem/ObjectlName '.

    , PATH of VARCHAR2 (140) VRSKA 'CcResultItem '.
    ) X 2
    WHERE X 2. TemplateName = "CgrInfo_1."
    -WHERE X 2. TemplateName = "CgrActors_3."
    -WHERE X 2. TemplateName = "CgrOwners_4."
    ) LOOP
    DBMS_OUTPUT. Put_line (' IdObject: ' |) R.IDOBJECT |  ' ObjectlName: ' | R.ObjectlName | "TemplateName ' |" R.TemplateName);
    END LOOP;
    DBMS_OUTPUT. Put_line ("- end -");
    RETURNS A NULL VALUE.
    END WS_SELECT_XML;

    Based on your query, I'll assume that you started with

    Extract data from webservice response

    In my opinion, it comes of the change you are looking for

    FOR R IN (
       SELECT x2.TemplateName, x3.idobject, x3.OWNERID
          FROM XMLTable(
                 XMLNamespaces(
                   'http://www.w3.org/2003/05/soap-envelope' AS "soap"
                 , default 'https://test.wstestx.com/XWS2/'
                 )
               , 'soap:Envelope/soap:Body/ProcessRequestResponse/ProcessRequestResult'
                 passing XML_VAR
                 columns
                 CcResponse clob path '.'
               ) x1
          , XMLTABLE(
              '/CcResponse/CcResultItems[@TemplateName="CgrOwners_4"]'
              PASSING XMLPARSE(DOCUMENT X1.CCRESPONSE)
              COLUMNS
                      TemplateName  VARCHAR2(20) PATH '@TemplateName'
                    , ItemXML       XMLTYPE       PATH 'CcResultItem'
            ) X2
          , XMLTABLE(
              '/CcResultItem'
              PASSING x2.itemXML
              COLUMNS
                      IDOBJECT      VARCHAR2(20) PATH 'IdObject'
                    , OWNERID       VARCHAR2(20) PATH 'OwnerID'
            ) X3
    )
    

    As Odie post pointed out.  The first (x 1) XMLTable retrieves the content of ProcessRequestRequest and by doing this, delete the CDATA tag.  We now have a CLOB that resembles XML.  The second XMLTable (x 2) converts this CLOB into an XMLType and looking for the node that matches the XPath expression.  It's where I've hardcoded in your query to search for a specific node.  As you want node has a repeated structure that you want to retrieve each row, I spent structures repeatedly in the third XMLTable (x 3) so he could analyze.  You could combine x 2 and x 3 using XQuery, but I suggest starting by this method I found that it's easier to understand what is happening.

    To test out your code, simply replace the line

    by the way XML_VAR

    with

    from XMLTYPE ("... the content of the SOAP Message...")

    and run the query.  You can do this to debug the query as you and just do a SELECT * to see what all went from XMLTable to XMLTable, so went to check the correct data.

  • How to write the query

    Hello

    How to write the sql query

    I have three type of table as

    1 table emp

    EMP_ID FIRST_NAME DEPT_ID

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

    1 kumar 10

    2 sam                          20

    3 30 damu

    2 table dept

    EMP_ID SALE_ID DEPT_ID

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

    1 101 10

    2 102 20

    3 103 30

    3. table sale

    EMP_ID SALE_ID SALE_AMT

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

    1 101 7

    2 102 8

    3 103 9

    I want the result as

    EMP_ID DEPT_ID SALE_AMT

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

    1                10                  7

    Thank you

    Are you looking for this?

    SELECT T1. EMP_ID,

    T1. DEPT_ID,

    W3M SALE_AMT

    FROM EMP T1,

    SALE T3

    WHERE T1. EMP_ID = T3. EMP_ID;

    OUTPUT:

    EMP_ID DEPT_ID SALE_AMT

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

    1         10          7

    2         20          8

    3         30          9

    If this is not the case, after the actual output, you need. Because that gives you the amount of sales deptwise

  • How to transpose the query with the following result

    Dear all,

    Can someone tell me a method to convert my query result

    Details are provided in

    http://obiee11ge.blogspot.com/2010/07/how-to-transpose-query-with-following.html

    Concerning

    Mustafa

    Hello

    Try this
    Create a request combined with,

    criterion no. 1: model, revenue (Actual), Cogs (Actual), Opex (Actual), PL (Actual)

    in the dummy column fx enter the "Real" value

    criterion 2: model, revenue (Yago), Cogs (YAgo), Opex (Yago), PL (Yago)

    in the dummy column fx enter the value as "Yago".

    criterion 3: model, revenue (Budget), Cogs (Budget), Opex (Budget), PL (Budget)

    in the dummy column fx enter the value as 'Budget '.

    Now go to the columns of result and set names coumn (revenue, COGS, Opex, PL) for the result set.
    For the Dumny, remove column header.

    In a sheet view, you will get the result.

    Thank you
    Vino

  • How to write the condition with the value of the parameter

    Hello
    I'm working on siebel BI publisher report. I am able to display the value of the parameter in the report.

    Now, I wanted to do something logical based on the value of the parameter.

    for example: If the user changes the value of the parameter then I have to call A submodel if user don't past not any value then it should not display A submodel

    can someone tell me how to write that above logic?

    If the parameter exists then MODEL of APPEAL one another do not call MODEL A

    Kind regards
    JAG


    Dial a submodel

  • How to optimize the query with a join of virtual tables

    I'm working on a query that is get the data of virtual tables 2 and b
    one is formed by the Union, all say 4 queries and b is formed by the Union, all say 3 queries
    then these two virtual tables and b are joined on a column common and data are extracted from their part.
    Problem is that there is about 1 minutes each in the two virtual tables has and b. If individual a and b queries virtual takes about 5 seconds to retrieve data
    but the join on column takes about 25 seconds to retrieve data.
    Can someone guide me how to optimize the recovery of joining 2 virtual tables having large data

    Thank you

    Please read these:

    When your query takes too long
    When your query takes too long...

    How to post a SQL tuning request
    HOW to: Validate a query of SQL statement tuning - model showing

  • How to run the script with parameters such as alarm action .ps1

    Hello

    I know not how to configure alarms, I know that I can point to monitor cluster for changes (via the GUI), but... I have different groups and I would like to set an alarm by vCenter which monitors cluster for changes. Let's call it "RefreshCapacityInfoOnExternalDB".

    So, lets just say. I would like to run my script whenever a virtual computer is added, Reconfigured or ESX host are removed, added in a Cluster. The alarm would launch the .ps1 script written in turn the ability to update external db cluster info.

    Shortly said: ability to cluster values are changed

    What I need is this: run the script-> CapacityInfoRefresher.ps1 < Cluster_name_where_ReconfigEventsTookPlace >

    I guess that, first I need an environment variable (if it exists) that can be used as a parameter for the < Cluster_name_where_ReconfigEventsTookPlace > placeholder script. Right?

    Chapter 16 of the book of LucD & Friends "PowerCli reference" mentions some environment vars but I'm stuck. Anyone using these options?

    THX

    A.S.

    You can set your alarm on the node above in your vCenter tree, this way it will be active for all collections in the vCenter.

    These alarm environment variables are automatically available for your alarm script when it is triggered.

    These environment variables, you will be able to determine to which cluster the alarm was pulled.

    So I don't think that you need to pass this information as a parameter to the script.

    Perrhaps you could share what exactly alarm you want to set and what looks like the script which should trigger alarm.

    And Yes, I use these environment variables in scripts of alarm

  • PL/SLQ - how to create the query with the total horizontal current

    Hello:
    I am creating a report in the following format

    Year name Reg1 Reg2 Reg3
    Al 2001 3 4 5
    2001 4-1-1
    2001 7 5 6
    2002 sue 2 4 1
    2002 Al 1 3 6
    Jim 2002 6 1 3
    2002 16 15 16
    2003 Jim 4-2 - 3
    2003 5 4 - 2
    2003 20 16 23

    Note that totals are piling up horizontally, broken on the year. How to do that, please? Thank you very much!
    Al
  • How to perform the procedure with parameters of type collection

    Hello

    I have the setting as the procedure
     PROCEDURE addGroup (
        Id IN NUMBER,
        sId IN NUMBER,
        gIds IN NUMBERLIST)
    CREATE OR REPLACE TYPE NUMBERLIST AS TABLE NUMBER;
    /





    could you help me by asking this type as a parameter the procedure...

    Thank you

    This is the type:

    SQL> create or replace type NUMBERLIST is table of number;
      2  /
    
    Type created.
    

    This is the procedure:

    SQL> create or replace PROCEDURE addGroup (
      2      Id IN NUMBER,
      3      sId IN NUMBER,
      4      gIds IN NUMBERLIST)
      5  is
      6  begin
      7    null;
      8  end;
      9  /
    
    Procedure created.
    

    And you call it this way:

    SQL> declare
      2  n numberlist := numberlist(1,2,3,4);
      3  begin
      4    addGroup(1,2,n);
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    

    Max
    [My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/01/23/la-forza-del-foglio-di-calcolo-in-una-query-la-clausola-model/]

  • How to write the JUnit with ATG

    as the topic, can someone help me, thanks!

    Take a look at DUST ATG (unit of Dynamo and System Tests) that facilitates the writing of JUnit tests for the ATG based applications.

    http://atgdust.sourceforge.NET/project-info.html

  • How to rebuild the waveform with zero new and create histogram type of waveform?

    Hello everyone, I have an application where I need to rebuild a waveform using some amount of 'x' of the data samples. the conditions are:

    1. the new zero of the new waveform is peak value frm the old form of wave., allows to assign this value of y s.

    2. based on this peak value, I have to draw points of sampling (y - t) and (y + t)...

    the waveform above may look like a histogram, but isn't exactly a histogram... can anyone suggest a concept?

    I'm not able to take the time to "throw in a sample VI.

    But if you look at the help file get the subset of waveform, you will see that he has all the inputs you need.

    There is an enum constant that allows you to choose samples or time.  I would say that the samples since this is what will come from most of the table Max/Min detector or Peak live

    There is a sample start time.  Put in the value of your Ridge detector less t.

    There was a time.  Put in the value of t 2 times.

    If t is the time, you may need to convert to samples based on your sample rate.

  • How to write the select query for it

    Hello

    I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.

    When I try to write the select statement and trying to run I get the error message.

    Select * from Table

    where emo_no = '1,2,3 '.

    That's how I write the query please suggest me how to write the query to select several values in the drop-down box.

    Thank you

    Use the keyword sql 'in '.  If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.

  • How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    I have a table whose columns with values such as

    MINNEAŸPOLIS and ¿VV ¿A

    Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.

    Please help to write a SQL SELECT with Regexp_like query or any other option.

    Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.

    SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;

Maybe you are looking for