DBAsupport.com Forums - Powered by vBulletin
Results 1 to 10 of 10

Thread: cusor_sharing

  1. #1
    Join Date
    Nov 2000
    Location
    Birmingham, UK
    Posts
    360

    cusor_sharing

    I've got some strange results from an insert query I've been asked to look at and I was hoping someone could shed some light on what Oracle is doing under the covers.

    This is 9.2.0.4 on Solaris with cursor_sharing = similar.

    The statement checks to see if a row exists in a table and inserts it if it doesn't exist. The statement is failing with ORA-01400: cannot insert NULL into even though the statement is trying to insert literals.

    Another issue is the statement is trying to insert strings into number fields so there is some implicit conversion going on.

    Here's the weird bit:

    1. The statement fails when cursor_sharing=similar but works when cursor_sharing=exact.
    2. If run with cursor_sharing=exact followed by a run with cursor_sharing=similar both work.
    3. if the shared pool is flushed the next run fails if cursor_sharing=similar.

    The issue has been fixed bu using to_number on the string but I cant understand why Oracle is trying to insert NULL's in the first place.

    1. cursor_sharing=similar - FAILS
    Code:
    NAME                                 TYPE                             VALUE
    ------------------------------------ -------------------------------- ------------------------------
    cursor_sharing                       string                           SIMILAR
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  '10' COL1,
     10  '10' COL2,
     11  '5' COL3
     12  FROM dual;
    INSERT WHEN NVL(n,'0') != '1' THEN
    *
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("BUSFYC"."T1"."COL1")
    2. cursor_sharing = exact - SUCCESS

    Code:
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    cursor_sharing                       string      EXACT
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  '10' COL1,
     10  '10' COL2,
     11  '5' COL3
     12  FROM dual;
    
    1 row created.
    3. cursor_sharing = similar now a successful one has been run - SUCCESS

    Code:
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    cursor_sharing                       string      SIMILAR
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  '10' COL1,
     10  '10' COL2,
     11  '5' COL3
     12  FROM dual;
    
    1 row created.
    4. flush shared pool then cursor_sharing = similar - FAILS

    Code:
    SQL> alter system flush shared_pool;
    
    System altered.
    
    NAME                                 TYPE                             VALUE
    ------------------------------------ -------------------------------- ------------------------------
    cursor_sharing                       string                           SIMILAR
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  '10' COL1,
     10  '10' COL2,
     11  '5' COL3
     12  FROM dual;
    INSERT WHEN NVL(n,'0') != '1' THEN
    *
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("BUSFYC"."T1"."COL1")

  2. #2
    Join Date
    Nov 2000
    Location
    Birmingham, UK
    Posts
    360
    Some additional information to confuse things a bit more:

    1. If the string literals are replaced with numbers,the insert still fails
    2. If to_number is used on the literals then it succeeds

    1. Use number literals - FAIL

    Code:
    NAME                                 TYPE                             VALUE
    ------------------------------------ -------------------------------- ------------------------------
    cursor_sharing                       string                           SIMILAR
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  10 COL1,
     10  10 COL2,
     11  5 COL3
     12  FROM dual;
    INSERT WHEN NVL(n,'0') != '1' THEN
    *
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("BUSFYC"."T1"."COL1")
    2. Use to_number - SUCCEEDS

    Code:
    NAME                                 TYPE                             VALUE
    ------------------------------------ -------------------------------- ------------------------------
    cursor_sharing                       string                           SIMILAR
    
    
    SQL> drop table t1;
    
    Table dropped.
    
    SQL> 
    SQL> create table T1
      2  (
      3    COL1          number(4) NOT NULL,
      4    COL2          number(4) NOT NULL,
      5    COL3          number(4) NOT NULL
      6  );
    
    Table created.
    
    SQL> 
    SQL> 
    SQL> INSERT WHEN NVL(n,'0') != '1' THEN
      2  INTO T1(COL1,COL2,COL3)
      3  VALUES
      4  (COL1,COL2, COL3)
      5  SELECT (SELECT '1' FROM T1 WHERE
      6  NVL(COL1,'-1')=NVL('10','-1') AND
      7  NVL(COL2,'-1')=NVL('10','-1') AND
      8  NVL(COL3,'-1')=NVL('5','-1') ) n,
      9  to_number(10) COL1,
     10  to_number(10) COL2,
     11  to_number(5) COL3
     12  FROM dual;
    
    1 row created.

  3. #3
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    That seems to be a bug.
    Definitely statement success or failure should not be influenced by the cursor_sharing parameter.
    About the second case with to_number, this is easily to explain, just when using to_number statements are not considered similar and are reparsed, so the optimizer behaves the same as if the cursor_sharing is exact.

    So, search the metalink with cursor_sharing, similar, and ora... error and see if any bugs appears
    if not, as long as you have a test case, log an SR.
    First they will tell u to go for 9.2.0.6 and if it does not disappears, Oracle will probably work on fixing the issue in 11g

  4. #4
    Join Date
    Nov 2000
    Location
    Birmingham, UK
    Posts
    360
    I was thinking bug too so I've already got an SR raised with Oracle but have had no reply as yet

    Thanks for the insight on to_number.
    Last edited by fraze; 10-24-2007 at 05:23 PM.

  5. #5
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    Well,
    push them a bit :-)
    If there have passed more than 6 hours without a replay, update the SR and tell them u r waiting for replay. They should start moving ;-)

  6. #6
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    Quote Originally Posted by Bore
    Oracle will probably work on fixing the issue in 11g
    not reproducable in 10.2.0.3.0..
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

  7. #7
    Join Date
    Nov 2000
    Location
    Birmingham, UK
    Posts
    360
    Quote Originally Posted by Bore
    Well,
    push them a bit :-)
    If there have passed more than 6 hours without a replay, update the SR and tell them u r waiting for replay. They should start moving ;-)
    Well its been 48 hrs since I raised and nothing yet! Raised as a Sev 4 - good old Oracle Support! No doubt they'll tell us to go to 9.2.0.8 which we cant do because of vendor restrictions.

  8. #8
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    then better live with Exact.. as they will never give you the requried fix..
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

  9. #9
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Quote Originally Posted by fraze
    Well its been 48 hrs since I raised and nothing yet! Raised as a Sev 4
    Sev=4? better for you to take a seat, wait is gonna be long... it's gonna take forever.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  10. #10
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    Sev 4 - Minor error, no lost of service :-)
    Or to translate that, it means you NOTIFIED them about that. You almost told them that you do not expect a fix ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width