Issue while inserting through DECODE function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Girish Kanakagiri
    New Member
    • May 2007
    • 93

    Issue while inserting through DECODE function

    Code:
    SQL>desc tab_dup;
    
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     CODE                                      NOT NULL VARCHAR2(6)
     BYJE                                               DATE
    
    SQL>  insert into tab_dup (CODE, BYJE) values('ABC',TO_DATE('20120111070154', 'YYYYMMDDHH24MISS'));
    
    1 row created.
    
    SQL>  select to_char(BYJE,'YYYYMMDDHH24MISS') FROM tab_dup WHERE CODE='ABC';
    
    TO_CHAR(BYJE)
    --------------
    20120111070154
    
    
    SQL> delete from tab_dup where CODE='ABC';
    
    1 row deleted.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> insert into tab_dup (CODE, BYJE) values('ABC',DECODE(TO_DATE('20120111070154', 'YYYYMMDDHH24MISS'),'19800101000000', NULL, TO_DATE('20120111070154', 'YYYYMMDDHH24MISS')));
    
    1 row created.
    
    SQL>  select to_char(BYJE,'YYYYMMDDHH24MISS') FROM tab_dup WHERE CODE='ABC';
    
    TO_CHAR(BYJE)
    --------------
    20120111000000
    When inserted at line number 27, using decode function; it is not storing hour minute second & thus they are coming as 000000. I have to use decode because the value from the parent table may be null & in that case this will help but the truncation should not happen because of decode & thus it should work same way when inserted through line 8.

    Please provide the necessary changes to decode function or any other alternative.
    Last edited by Girish Kanakagiri; Jan 18 '12, 06:46 AM. Reason: line number correction
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    First and foremost what database is this, that would greatly help in finding a solution.

    Comment

    • Girish Kanakagiri
      New Member
      • May 2007
      • 93

      #3
      Oracle.
      connect by below string to the ip through putty :
      SQLPLUS userid/password
      Last edited by Girish Kanakagiri; Jan 18 '12, 09:15 AM. Reason: Got right db

      Comment

      Working...