Forum Stats

  • 3,752,284 Users
  • 2,250,483 Discussions
  • 7,867,783 Comments

Discussions

Make column NULL

EricDBA/EDQ
EricDBA/EDQ Member Posts: 374
edited Jan 2, 2018 4:08PM in SQLcl

Is it possible to make a column NULL if another column is a specific value?

Tagged:

Best Answer

  • Gary Graham-Oracle
    Gary Graham-Oracle Member Posts: 3,256 Bronze Crown
    edited Jan 2, 2018 2:51PM Accepted Answer

    Two columns are no problem.  Here is my initial example rewritten for CASE and for DECODE...

    UPDATE EMPLOYEES  SET COMMISSION_PCT =     (CASE JOB_ID WHEN 'SA_REP' THEN COMMISSION_PCT                  WHEN 'SA_MAN' THEN COMMISSION_PCT                  ELSE NULL     END)WHERE COMMISSION_PCT IS NOT NULL; 

    and

    UPDATE EMPLOYEES  SET COMMISSION_PCT =     DECODE( JOB_ID, 'SA_REP', COMMISSION_PCT,             DECODE( JOB_ID, 'SA_MAN', COMMISSION_PCT, NULL)           )WHERE COMMISSION_PCT IS NOT NULL;

    But remember:  the other forum space is where you will get faster, better responses for these general issues.

Answers