inserting data into table, help??
I have a table that I set a column's default to 000. The idea of doing this is that, when that column is left blank during an insert, the 000 will automatically fill that column.
After that altering the table, the developers inserted data into the table using a front end tool, but when we checked the table, the column(that was set to default, 000) that was supposed to be 000 was still empty. Do you have an idea? This is exactly what I did:
SQL>alter table emp modify(
sal number default 000);
The idea of doing this is that, when that column is left blank during an insert, the 000 will automatically fill that column.
So, when the developers inserted data from the fron end, and querried the table, the column was still empty instead of that column being 000.
Does anyone have an idea what's going on?
P.S sal is the name of the column.
I am running oracle 8i(8.1.5) on unix
[Edited by charity on 12-11-2000 at 08:02 PM]
default will not prevent users to insert NULL.
So since I want the default for that column to be 000, can you please show me an example of how to do that with the column being defaulted to 000?
Hmmm - I think that default on a column only works when the column isn't specified in the insert statement - sometimes it's easier to take care of this in the front end code.
it is not possible if u r giving default value
and u r not insearting any record in that column then it will take the default value
so make sure that what the frontend is passing into that column
and one more thing if the datatype of that column is number
and if u r giving 000 it will take only 0
nut if u r having varchar datatype then give like this '000'
Okay,I think the assumption that I used in my expalnation was not clear cut. It's quite different from the actual scenario. I was thinking that it will be the same.
Okay this is the exact scenario:
I have a table called EMP and has a column called activity_id.
I did a desc on the table and I got this for activity_id
NAME NULL? TYPE
Okay now I want to alter the table so that, the default value for activity_id to be 000, if nothing is entered
in the activity_id column.
I'm sure it's clear now, any help?
CREATE OR REPLACE TRIGGER TI_EMP__ACTIVITY_ID
BEFORE INSERT ON EMP
FOR EACH ROW
IF :NEW.ACTIVITY_ID IS NULL THEN :NEW.ACTIVITY_ID:='000'; END IF;
Creating a before insert and update trigger is the better soluction.
For inserting default value , trigger is not a correct solution.
Ensure that the INSERT Statement does not have NULL value for that column.
solution with trigger is good for option that u do not need to change the application!
Click Here to Expand Forum to Full Width