1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Default Value

Discussion in 'SQL PL/SQL' started by jagadekara, May 28, 2014.

  1. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    Hi All,

    i have a table test3 which has two columns. ename varchar2(100),sal number

    If i insert ename and sal values it's fine. If i gave ename and i didn't gave sal then i need 5000 in sal column.

    So i need default value 5000 for sal column.

    Give suggestions....
     
  2. rajenb

    rajenb Forum Expert

    Messages:
    361
    Likes Received:
    114
    Trophy Points:
    655
    Location:
    Mauritius
    Hi,
    The simplest is to alter table:

    alter table test3 modify sal default 5000;

    You can also use a database trigger (before insert trigger).
     
    jagadekara likes this.
  3. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    Thank you Rajen,

    Actually I created table with default for sal column, but while inserting i did like this...

    insert into test3 values('Jagan');

    So it shows error...

    Later i find my mistake...

    insert into test3(ename) values('Jagan');

    not it's inserted fine...

    select * from test3;

    ename sal
    Jagan 5000