Join WITH NULL

I have table1 and table2.what is the number of lines if I join table1 and table2 col1-based. I told 2 rows. Interview then asked write a query if you want that NULL, NULL in release and I don't know how to do this since Null will not match


TABLE1:

COL1, COL2

1, HAS

2, B

NULL, NULL

TABLE2:

COL1, COL2

1 C,

2, D

NULL, NULL

Don't know what the interviewer was looking for

SQL> with t1
  2  as
  3  (
  4  select 1 id, 'A' name from dual union all
  5  select 2 id, 'B' name from dual union all
  6  select null id, null name from dual
  7  ),
  8  t2
  9  as
 10  (
 11  select 1 id, 'C' name from dual union all
 12  select 2 id, 'D' name from dual union all
 13  select null id, null name from dual
 14  )
 15  select *
 16    from t1
 17    join t2
 18      on nvl(t1.id, -1) = nvl(t2.id, -1);

        ID NAME               ID NAME
---------- ---------- ---------- ----------
         1 A                   1 C
         2 B                   2 D
NULL       NULL       NULL       NULL

SQL> with t1
  2  as
  3  (
  4  select 1 id, 'A' name from dual union all
  5  select 2 id, 'B' name from dual union all
  6  select null id, null name from dual
  7  ),
  8  t2
  9  as
 10  (
 11  select 1 id, 'C' name from dual union all
 12  select 2 id, 'D' name from dual union all
 13  select null id, null name from dual
 14  )
 15  select *
 16    from t1
 17    left join t2
 18      on t1.id = t2.id;

        ID NAME               ID NAME
---------- ---------- ---------- ----------
         1 A                   1 C
         2 B                   2 D
NULL       NULL       NULL       NULL

Tags: Database

Similar Questions

  • Outer join with Oracle syntax

    Hi, I am new to oracle and I worked this request for reports for about 2 weeks, please take a look at my request
    SELECT mmt.transaction_date "Transaction Date", 
                msib.segment1 "Item", 
                gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
                (CASE mttype.transaction_type_name
                WHEN 'Average cost update' THEN
              ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
                ELSE
                 (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
               END) "Transaction Value",
                mttype.description "Transaction Type",
                mmt.subinventory_code "Subinventory",
                ood.organization_code "Org",
                msib.Primary_UOM_Code "UOM",
                mmt.Primary_Quantity "Primary Quantity",
                mtr.description "Reason",
                mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
             mtl_system_items_b msib,
             mtl_transaction_accounts mta,
             gl_code_combinations gcc,
             mtl_transaction_types mttype,
             Org_Organization_Definitions ood,
             mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM 
               and mmt.transaction_date  < :P_DATE_TO +1
               and mmt.organization_id = :P_ORGANIZATION 
               and msib.organization_ID = mmt.organization_ID  
               and msib.inventory_item_id=mmt.inventory_item_id 
               and mta.transaction_id=mmt.transaction_id
               and gcc.code_combination_id = mta.reference_account
               and mttype.transaction_type_id=mmt.transaction_type_id
               and mmt.reason_id=mtr.reason_id(+)
               and ood.organization_id=mmt.organization_id
               and mttype.transaction_type_id = :P_TRANSACTION_TYPE
               and msib.segment1 = :P_ITEM
               AND gcc.segment2 = :P_ACCOUNT
    null values is on the mtl_material_transactions table, which is reason_id, subinventory_code and transaction_reference
    put desired option on would show all archives on mtl_material_transactions with null values
    so I put the symbol of the outer join right?
    BTW
    I tried to put the (+) sign on various locations but it still not good and I am really at a loss

    Hello

    Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the desired results from these data. I know that's not always easy, but it is really necessary. Compounds that, I do not understand your problem.
    It could be useful that simplify you the problem. If you were not interested in, say, the mta, gcc, tables msib and ood, would you still have the same problem? If so, forget all these tables and just after, CREATE TABLE and INSERT statements for the remaining tables and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    The query you posted will not exclude any line of mmt just because it doesn't have a corresponding line in the mtr; That's what the condition:

    and mmt.reason_id=mtr.reason_id(+)
    

    but it will exclude mmt lines if they do not have matching rows in other tables. Maybe you need + plus join and may under certain conditions non-join, such as conditions

    gcc.segment2 (+) = :P_ACCOUNT
    

    Too much. It's just a guess. Without seeing your sample data and the correct results, you should get from this data, I can't say.

  • Left Join with a subquery

    Hey everybody!

    I have some difficulty in trying to create a SQL query.

    I have the following tables:

    -Table Products: Product list
    CREATE TABLE (PRODUCTS)
    PRODUCT_ID INTEGER NOT NULL,
    KEY ("PRODUCT_ID") PRIMARY CONSTRAINT 'PK_PRODUCTS '.
    );

    -Orders table: Decreed this product
    CREATE TABLE ORDERS)
    ORDER_ID INTEGER NOT NULL,
    PRODUCT_ID INTEGER NOT NULL, / * FK PRODUCTS (PRODUCT_ID) * /.
    KEY ("ID_PEDIDO") PRIMARY CONSTRAINT 'PK_ORDERS '.
    );

    -Orders_Approval table: register when an order is approved
    CREATE TABLE ORDERS_APPROVAL)
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL,
    USER_ID INTEGER,
    KEY("ORDER_ID","APPROVAL_DATE") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL '.
    );

    -Table Orders_ApprovalData: Register more details on the amenities of the order
    CREATE TABLE ORDERS_APPROVAL_DETAILS)
    APPROVALDET_ID INTEGER NOT NULL,
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS_APPROVAL (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL, / * FK ORDERS_APPROVAL (APPROVAL_DATE) * /.
    KEY ("APPROVALDET_ID") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL_DETAILS '.
    );

    The thing is that an order may OU cannot be approved. Thus, there could be no record of an order in ORDERS_APPROVAL.

    In addition, an order can have more than one approval.

    Here is the data that I use:

    /===========\
    | PRODUCTS |
    |===========|
    | PRODUCT_ID |
    |===========|
    | 1.
    |===========|
    | 2.
    |===========|
    | 3.
    \===========/

    /========================\
    | ORDERS |
    |========================|
    | ORDER_ID | PRODUCT_ID |
    |===========|============|
    | 27. 1.
    |===========|============|
    | 28. 2.
    |===========|============|
    | 29. 3.
    \===========|============/

    /=========================================\
    | ORDERS_APPROVAL |
    |=========================================|
    | ORDER_ID | APPROVAL_DATE | USER_ID.
    |===========|================|============|
    | 27. 01/10/2009 | 56.
    |===========|================|============|
    | 27. 04/10/2009 | 96.
    |===========|================|============|
    | 29. 03/10/2009 | 77.
    \===========|================|============/

    /=============================================\
    | ORDERS_APPROVAL_DETAILS |
    |=============================================|
    | APPROVALDET_ID | ORDER_ID | APPROVAL_DATE |
    |================|===========|================|
    | 1. 27. 01/10/2009 |
    |================|===========|================|
    | 2. 27. 04/10/2009 |
    |================|===========|================|
    | 3. 29. 03/10/2009 |
    \================|===========|================/
    I need to create a query that returns the data in all tables, but for orders with more than one certification,
    the query must return only the last record. It is also necessary return orders that have not yet been approved.

    My first query looked like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    PS: I use the Oracle 8 syntax because it's the server I'll use. In addition, I can't change the design of database.

    This query returns the data in table all. Because I used LEFT JOIN "(+)" to join the table orders_approval with the orders table, I am able to see even the orders with no approval.

    But this way, I see also two approvals for order 27 (with the data above, this order was approved twice). I need to reach my paintings in the last approval for each order is but should be a left join so I can see the orders with no approval.

    I tried this way:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But in this way, as I am specifying I want only records with approval equal to date at the latest for each order, I do not see the order without approval.

    I tried again, with a left join like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE (+) = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But I get a syntax error. Oracle said that it is not possible to do a join with a subquery.

    If anyone knows how I can bring all this data?

    Thanks in advance.

    Published by: user9936895 on 05/10/2009 09:42: tried to fix the predetermined data schema.

    Hello

    Welcome to the forum!

    A scalar, such as subquery

    (SELECT MAX(APPROVAL_DATE) FROM ORDERS_APPROVAL WHERE ORDER_ID=ORDAPPROV.ORDER_ID)
    

    is allowed in a WHERE clause, but not as a condition of outer join, as you discovered.

    A workaround is the query expression so that it is not part of the outer join condition, which invlove in May (as in this case), adding another subquery. In the following query, the table of orders_approval in your original OF Division is replaced with online view, which uses the exact same scalar subquery in the WHERE clause. The online display will only contain one line per order_id (assuming that there is no link with for last approval_date).

    SELECT
         *
    FROM
         orders               ord,
         products          prod,
         (     -- Begin in-line view ORDAPPROV of last approval_date only
         SELECT     *       -- or list the columns needed in main query
         FROM     orders_approval         oa
         WHERE     approval_date = (
                        SELECT  MAX (approval_date)
                        FROM     orders_approval
                        WHERE     order_id     = oa.order_id
                        )
         )                ordapprov,
         orders_approval_details ordappdet
    WHERE
         prod.product_id               = ord.product_id
    AND     ordapprov.order_id (+)          = ord.order_id
    AND     ordappdet.order_id (+)          = ordapprov.order_id
    AND     ordappdet.approval_date (+)     = ordapprov.approval_date
    ;
    

    Thank you for including CREATE TBAL statements; It is very useful.
    You want to be even more useful in the future? Post INSERT statements for the sample data. That will make it easier for people to respond and easier for them to test their ideas.

  • How to display the line empty as a line with null values

    Hi all

    Pls advise me if it is possible to use a single query statement to display
    Empty row (i.e. not a single return line) as a line with null values.

    For example,.

    Select the names of names_mst whose name = "sgasfgs".

    Result:
    Names of
    =====
    < null >

    Hello
    If you desire to join external to double, as shown below, you still get at least a line of production

    SELECT  nm.names
    FROM            dual
    LEFT OUTER JOIN names_mst   nm  ON nm.name='sgasfgs';
    
  • Outer join with a constant

    Outer join when made between the columns of the two tables is easy to understand and I'm familiar with it. But when it comes to the same join with a constant, my head starts spinning... you guys can help me with this? I would appreciate that show you with examples.
    Thanks a ton.

    Hello

    >
    Ok... I want to understand the output of the last sql statement given here.
    ...
    Select * from a, b
    where col_a (+) = col_b
    and col_a (+) = 1

    It shows put it is as follows
    col_a, col_b
    1 1
    2 NULL
    NULL NULL

    Joining means: 'display all rows in table b and the corresponding rows in the table one '.
    Since it is an outer join, it also means "view b lines even if there is no corresponding row in a.

    Thus, the output contains 3 lines, which correspond to the 3 lines in b.
    Only one of them (the one with col_b = 1) had a game in a.col_a, if the column is NULL in the other lines.

    With the sample data you posted, you will get the same results without condition

    and     col_a (+) = 1
    

    If you want to understand what makes this condition, use some examples of data where this condition would fail.
    For example, add this line to the table a:

    insert into a values (2);
    

    and run your original query (including the)

    and     col_a (+) = 1
    

    ). what output you get? You get the same exact results you did without the new line in a.

    In other words, the b line where col_b = 2 has still no matches in the table has.
    True, there is now a line of table where col_a = 2, but which does not constitute a game. A match is defined by two conditions:

    where   col_a (+) = col_b
    and     col_a (+) = 1
    

    in order to have a pair of lines which meets only the first condition

    where   col_a (+) = col_b
    

    is not enough.

  • Remove data with null value

    Hello

    I'm using Oracle 11 g. I have a table with an id of 3, node, the value column. Combination of the column id and node, that must be taken account for deletion on the registers.

    Here, I need to delete lines with the NULL value in the value column. If for a combination of id and node with non-null values, then I need to delete rows with a null value for this combination.

    If the combination of id, node is not null value then this records should not delete.

    Below table, I need to remove the second row, for which is a value not zero VOICE CAL '10' is there, so I need to delete the row with null values. (VOICE, CAL, NULL)

    Network, FL, there is no value is non-null then I should NOT delete this line.

    This table is to have 100 s of this association, we can delete data in a single delete query?

    Or how I can delete rows with nulls for this combination.

    Tab1

    VALUE OF THE NŒUD ID

    VOICE CAL 10
    VOICE CAL NULL
    NETWORK NULL FL

    Thank you

    Hello

    oradba11 wrote:

    Hello

    I'm using Oracle 11 g. I have a table with an id of 3, node, the value column. Combination of the column id and node, that must be taken account for deletion on the registers.

    Here, I need to delete lines with the NULL value in the value column. If for a combination of id and node with non-null values, then I need to delete rows with a null value for this combination.

    If the combination of id, node is not null value then this records should not delete.

    Below table, I need to remove the second row, for which is a value not zero VOICE CAL '10' is there, so I need to delete the row with null values. (VOICE, CAL, NULL)

    Network, FL, there is no value is non-null then I should NOT delete this line.

    This table is to have 100 s of this association, we can delete data in a single delete query?

    Or how I can delete rows with nulls for this combination.

    Tab1

    VALUE OF THE NŒUD ID

    VOICE CAL 10
    VOICE CAL NULL
    NETWORK NULL FL

    Thank you

    You can do this in a single DELETE statement (it is not a request), using an EXISTS or IN the subquery.  For example:

    REMOVE table_x m

    WHERE the value IS NULL

    AND THERE ARE)

    SELECT 0

    FROM table_x s

    WHERE s.id = m.id

    AND s.node = m.node

    AND s.value IS NOT NULL

    )

    ;

    If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test it.

  • join with condition

    Hi all

    Is there a possible way to cross the join with condition?

    I want something like this:

    Table A: custid, accu_id, sum

    CustID, accu_id unique =

    CustomerID amount accu_id

    10 25 400

    10 35 447

    10 29 420

    20 30 510

    30 35 472

    .

    .

    .

    Table b: accu_id, description

    accu_id description

    shoes 25

    Book 29

    30 computer

    pen 35

    Note: in table A, it is a mismatch of the accu_id values that do not use. Please, take into account this.

    I want to see all the columns in the TABLE B for each custid in A. TABLE (something like cross join but with ONE article.) The following query does not work.

    Select * from a right join B on A.accu_id = B.accu_id;

    10-25

    10-29

    10-30

    10-35

    20-25

    20-29

    20-30

    20-35

    30 25

    30 29

    30 30

    30-35

    What should I do for this?

    Thanks in advance

    Use partition outer join:

    with a (too)

    Select double union all 10 custid, accu_id 25, amount 400

    Select 10,35,447 from all the double union

    Select 10,29,420 from all the double union

    Select 20,30,510 from all the double union

    Select double 30,35,472

    ),

    b like)

    Select accu_id 25, "shoe" description of all the double union

    Select 29, 'book' from dual union all

    Select 30, 'computer' from dual union all

    Select 35, 'pen' from dual

    )

    Select a.custid,

    a.accu_id,

    a.amount,

    b.

    a

    by (a.custid) partition

    right join

    b

    On a.accu_id = b.accu_id

    order of a.custid,

    a.accu_id

    /

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    10 25 400 shoe
    10 29 420 book
    10 35 447 pen
    10 computer
    20 30 510 computer
    shoe 20
    book 20
    20                       pen
    30 35 472 pen
    30 shoe
    30 book

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    30 computer

    12 selected lines.

    SQL >

    SY.

  • For all the records for each record double, I need to get a single column with null or 0.

    Hi all

    I have a requirement where I need to get all the records, for each record in double, I need to get a single column with null or 0.

    create table a1

    (

    Identification number,

    VARCHAR2 (100), the point

    part varchar2 (100));

    Insert into a1

    values (1, 'ABC', 'A1');

    Insert into a1

    values (2, 'DEF', 'A2');

    TABLE A

    PART ITEM ID

    1 ABC A1

    1 ABC A1

    1 ABC A1

    DEF 2 A2

    DEF 2 A2

    3 DEF A2

    O/P

    PART ITEM ID

    1 ABC A1

    1        ABC             0

    1        ABC             0

    DEF 2 A2

    2       DEF              0

    3       DEF              0

    Thanks in advance.

    Thanks for your help FrankKalush...

    This one will work.

    WITH got_r_num AS

    (

    SELECT NVL (a1.id, a1.id) as id

    NVL (a1.item, a1.item) AS element

    NVL (a1.part, a1.part) IN the framework

    a1.id AS a_id

    ROW_NUMBER () OVER (PARTITION BY a1.id

    ORDER BY NULL

    ) AS r_num

    BY the a1

    )

    SELECT id

    element

    CASE

    WHEN a_id IS NOT NULL

    AND r_num = 1

    THEN part

    ELSE ' 0'

    END in the framework

    OF got_r_num

    ;

  • Throw the records with null values columns

    Hi all.

    Anyone know how to dispose of records containing null column values?

    In the target table, I have the set Null option? with "N"... then the process sqlldr load some records. I need to load all of this without the records with null column values. by result, if the field X is null then load the file.

    Kind regards.

    Published by: ASzo on 05/06/2013 12:37

    Published by: ASzo on 05/06/2013 12:38

    Published by: ASzo on 05/06/2013 12:42

    load data
    INFILE...
    in the table...
    When x! = ''
    fields completed by...
    (x ...)

  • Left Outer Join with sum

    Dear elders,



    Firstly, sorry if my question is considered to be 'very novice' but I have this problem of confusion.

    Can I use the left outer join with summary?
    For example:

    Work table
    JobCode      JobGroupCode      
    111A         1100              
    112B         1100               
    113C         1100
    121A         1200
    333F         3300               
    Table No.
    JobGroupCode    ParentCode
    1100            1000
    1200            1000
    1300            1000
    3300            3000
    Activity table
    Jobcode      Mandays
    111A         5
    112B         7
    113C         3
    I want to choose with this result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    121A           1200                 1000                      0
    333F           3300                 3000                      0
    All I did was:
    select j.jobcode, j.jobgroupcode, jg.parentcode, sum(a.mandays)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    and I got was only jobcode activity table, not exactly what I want to get all the work table jobcode. Could you please tell me, where I was wrong?

    result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    Thank you very much.

    Published by: user11197113 on May 25, 2009 03:31

    Published by: user11197113 on May 25, 2009 03:32

    Hello (and welcome!).

    Edit

    OK, try this:

    select j.jobcode, j.jobgroupcode, jg.parentcode, NVL(sum(a.mandays),0)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    

    That will give you this:

    JOBC JOBG PARE SUM(A.MANDAYS)
    ---- ---- ---- --------------
    111A 1100 1000              5
    112B 1100 1000              7
    113C 1100 1000              3
    121A 1200 1000              0
    333F 3300 3000              0
    

    These are real results of your test data.

  • Join the recordset with null field that causes errors

    The initial value of the form on this page fields are filled in by the next Recordset containing a join:

    SELECT *.
    OF customers_cus, orders_ord
    "" "WHERE the orders_ord.customerid_ord = customers_cus.customerid_cus AND company_cus ='" & Request.Form ("companymenu") & ""

    Whenever the database field orders_ord.customerid_ord is not null, the form fields on the well overview page. However, if orders_ord.customerid_ord is null, I receive the following error message:

    ADODB. Field error '800a0bcd '.

    BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

    How can I do that orders_ord.customerid_ord cannot be null?

    First, abandon your old join syntax. Then, use an outer join.
    If you join them join two tables on an intern, then a record with a NULL value in
    each join column will be returned.

    In addition, do not use SELECT *. And you are vulnerable to SQL injections.

    SELECT
    OF customers_cus
    LEFT OUTER JOIN orders_ord WE
    orders_ord.customerid_ord = customers_cus.customerid_cus
    ' "WHERE company_cus ='" & Replace (Request.Form ("companymenu"),"'","" "") & "'

    Replace the above does not offer complete protection, but it is at least
    What do you use to protect yourself.

    "aonefun" wrote in message
    News:enjb11$3MT$1@forums. Macromedia.com...
    > The initial value of the fields in the form on this page are met by the
    > suite
    > recordset containing a join:
    >
    > SELECT *.
    > OF customers_cus, orders_ord
    > Orders_ord.customerid_ord = customers_cus.customerid_cus WHERE AND
    ' "> company_cus ='" & Request.Form ("companymenu") & "'
    >
    > When the database field orders_ord.customerid_ord is not null, the
    > form
    > fields on the overview page. However, if orders_ord.customerid_ord is
    > null,.
    > I received the following error message:
    >
    > ADODB. Field error '800a0bcd '.
    >
    > BOF or EOF is True, or the current record has been deleted.
    > Asked
    > operation requires a current record.
    >
    > How to make it that orders_ord.customerid_ord cannot be null?
    >

  • display of the output cursor empty with null values

    I have the below procedure of the State where he is shown the output to the client.

    The requirement now is if the select statement does not return a value any with the input given then output parameter should see NULL values instead of no line at all.


    One method is to get the number of the select query that is written in "open p_out for." And then write the condition as if count is 0 then null other show data.

    Could you please suggest me any other alternative to this.

    Create or replace procedure test (p_empno in number , p_out out sys_refcursor) is
    
    begin
     open p_out for 
     select e.ename, d.deptname, s.sal , p.addr , v.age
      from emp e ,dept d, sal s, padress p , age v
     where e.deptno = d.deptno and d.deptno = s.deptno
     s.sal_id = p.sal_id and p.id = v.id
    and e.empno = p_empno ;
    
     
    exception when others then
     open p_out for 
     select null , null,null,null,null from dual;
    
     
    end test.
    

    Thank you

    Maybe NOT TESTED!

    Select x.ename, x.deptname, x.sal, x.addr, x.age

    of the double

    left outer join

    (select e.ename, d.deptname, s.sal, p.addr, v.age

    from emp e,.

    d Dept,

    SAL s,

    padress p,

    v of the age

    where e.deptno = d.deptno

    and d.deptno = s.deptno

    and s.sal_id = p.sal_id

    and p.id = v.id

    and e.empno = p_empno

    ) x

    1 = 1

    Concerning

    Etbin

    Select x.*

    of the double

    left outer join

    (select *)

    WCP

    where ename = 'ETBIN.

    ) x

    1 = 1

    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    - - - - - - - -
  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • Join with full pivot

    Oracle 11.2.0.1

    Windows

    create table empdetails

    (

    number of EmpID,

    EmpName varchar2 (30)

    )

    /

    create the table saldetails

    (

    number of EmpID,

    VARCHAR2 (10) months.

    number of salamt

    )

    /

    insert into empdetails values (1, 'John');

    insert into empdetails values (2, 'Smith');

    insert into empdetails values (4, 'Robert');

    insert into empdetails values (3, 'Joseph');

    insert into empdetails values (7, 'Téo');

    insert into saldetails values (2, 'July', 200);

    insert into saldetails values (6, 'May', 150);

    insert into saldetails values (1, 'May', 150);

    insert into saldetails values (1, 'June', 150);

    insert into saldetails values (1, 'July', 175);

    insert into saldetails values (4, 'June', 180);

    SQL > select * from empdetails;

    EMPID EMPNAME

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

    1 John

    2 Smith

    4 Robert

    3 Joseph

    Khaoula 7

    SQL > select * from saldetails;

    EMPID MONTHS SALAMT

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

    2 July 200

    May 6 150

    May 1 150

    June 1 150

    1 July 175

    June 4 180

    6 selected lines.

    SQL >

    Power required:

    EMPID EMPNAME April May June July

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

    1 Jean 150 150 175

    2 Smith                                                    200

    3 Joseph

    4 Robert 180

    6                                 150

    Khaoula 7

    Logic for column of April, may, June and July.  Saldetails table have the processing of data from may, June and July, in the desired output, we need to have min (months) - 1 to max (month).

    Thank you.

    HI - find the minimum of months given month is not a big deal, but as said above to rotate based on months, than we need to know the name of the months before hand. If we know not what month we would not be able to provide the name of this month under the name of the column in the SELECT query.

    However, there is a solution: in this approach, you build him SELECT queries dynamically, and then run it.

    Reference: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4471013000346257238

    http://technology.AMIS.nl/2006/05/24/dynamic-SQL-pivoting-stealing-Antons-Thunder/

    For example:

    Connected to:

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

    With partitioning, Automatic Storage Management, OLAP, Data Mining

    and Real Application Testing options

    -create a temporary table after joining the 2 data tables (instead you can try giving this query in the procedure below directly)

    SQL > create table tmp_1 like

    2 with t as (select e.empname, nvl (e.empid, s.empid) empid, s.month, s.salamt, to_char (min (to_date(s.month,'MON')) over () - 1, 'Month') min_month

    3 of e empdetails

    4 full outer join

    5 s saldetails

    6 on (e.empid = s.empid)

    7             )

    8 select

    9 of

    10 (select empname, empid, salamt, month

    11 t

    12 union

    13. Select null, null, null, min_month

    14 t

    15 where rownum = 1

    16)

    17.

    Table created.

    -create procedure that generates the SELECT dynamically query and run it

    SQL > create or replace procedure dynamic_pvt (p_cursor in the sys_refcursor)

    2 is

    3 clob l_query: = 'select empid, empname;

    4 start

    5

    6 x (select distinct month of tmp_1 where the month is not null order by to_date (month, 'Month'))

    7 loop

    8 l_query: = l_query |

    9. replace (q'|, sum (decode(month,'$X$',salamt)) $X$ |',)

    10                      '$X$',

    11 x.month / * sys.dbms_assert.simple_sql_name (x.empid) * /.

    12                    );

    13 end of loop;

    14

    15 l_query: = l_query | 'from tmp_1 group by empid, empname order by empid;

    16 open p_cursor for l_query;

    17

    18 end;

    19.

    Created procedure.

    SQL > variable refcursor x

    SQL > execute dynamic_pvt(:x)

    PL/SQL procedure successfully completed.

    SQL > print x

    EMPID EMPNAME APRIL MAY JUNE

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

    JULY

    ----------

    1 John                                             150        150

    175

    2 Smith

    200

    3 Joseph

    EMPID EMPNAME APRIL MAY JUNE

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

    JULY

    ----------

    4 Robert                                                      180

    6                                                  150

    Khaoula 7

    EMPID EMPNAME APRIL MAY JUNE

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

    JULY

    ----------

    7 selected lines.

    SQL > col 9999 empid format

    SQL > col empname format a30

    SQL > col April format 9999

    SQL > col can format 9999

    SQL > col June format 9999

    SQL > format of July col 9999

    SQL > execute dynamic_pvt(:x)

    PL/SQL procedure successfully completed.

    SQL > print x

    EMPID EMPNAME APRIL MAY JUNE JULY

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

    1 Jean 150 150 175

    2 Smith                                              200

    3 Joseph

    4 Robert                                       180

    6                                        150

    Khaoula 7

    7 selected lines.

    SQL >

  • outer join with the additional constraint

    Hello

    With the help of Oracle 11 g R2.

    I would of outer join tables 2 together and put down restrictions on the types of records that are returned in the query result. Here's a mock-up of the tables and data.

    create table aaa (col1 number not null, col2 number not null)

    create table bbb (col1 number not null, col2 number not null)

    insert into values of aaa (1: 80)

    insert into values aaa (2, 90)

    insert into values aaa (3, 80)

    insert into values aaa (4, 90)

    insert into values aaa (5, 80)


    insert into bbb values (3, 600)

    insert into values of bbb (4, 700)

    This is the query

    
    select a.col1, a.col2, b.col1, b.col2
    from aaa a, bbb b
    where a.col1 = b.col1 (+)
    and   (a.col2, b.col2) <> ((90, 700))
    

    The result of the query is as follows.

    col1 col1 col2 col2

    1 80

    3 80 3 600

    5 80

    Where col1 = 4 has been deleted, which is an expected result. However, where col1 = 2 has also been removed, which is not a desired outcome. Your response is appreciated.

    Hello

    Here is a way that works for the given sample data:

    SELECT *.

    AAA a

    LEFT OUTER JOIN bbb b ON a.col1 = b.col1

    WHERE the NVL (a.col2, 0) <> 90

    OR NVL (b.col2, 0) <> 700

    ;

    I don't know if that will satisfy your requirements with other data, since you didn't say what your needs are.

    Whenever you have a WHERE clause is applied after the outer join, all columns of the table in option (table bbb in this example) must be used in an NVL, NVL2 or something like a CASE expression that takes into account null values; otherwise, the effect will be the same as an inner join.

Maybe you are looking for

  • How to connect to a friends email

    I know that my friends email address and password on gmail. How can I connect his e-mail with T-bird?

  • Toshiba Service Station has stopped working

    Window will appear indicating"Toshiba Service Station has stopped working" It offers two choices: check online for a solution and close the programclose the program When you select check online nothing seems to happen... the move dashes indicatingsom

  • Satellite A75 - config\system missing or damaged

    A month ago I successfully restored all the settings from the factory with the recovery cd for my satellite A75.Everything was working well until yesterday, I have received the \windows\system32\config\system missing or damaged. My laptop can not rea

  • Satellite P870-320 - disorders Touchpad

    Greetings, My name is Jakerper. I experienced a lot of problems with my touchpad on my fairly new laptop. And Yes, I must admit that it's probably my fault, because I accidentally deleted my original touchpad drivers, thanks to a kind of idiocy tempo

  • How do engage you the switch cover?

    I replaced the microphone cable in a pavilion of DV2617US.  Everything seems to be fine (?) but I can not replace the cover of the switch in place on the left side.  It seems that the left hinge is not completely.  The part of the joint that connects