Home » SQL & PL/SQL » SQL & PL/SQL » Inserting default value during insert (oracle 10g)
Inserting default value during insert [message #349903] Tue, 23 September 2008 07:53 Go to next message
ravi214u
Messages: 153
Registered: February 2008
Location: CANADA
Senior Member
hi,

I need to insert default value when the row return null .
e.g all colums have datatype number
insert into master( col1,col2,col3)
select col1,case when col2 is null then 999 else col2 end,
col3 from slave;


i can set the default value while creating the table.
But i want to capture this at insert time.Is there any other
way to do so.

Thanks in advance.

Re: Inserting default value during insert [message #349907 is a reply to message #349903] Tue, 23 September 2008 08:01 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
By "at insert time" do you mean insert into master or insert into slave?

I don't see a problem with the way you are doing it (except use of case instead of nvl), although I don't like what you are trying to do (not just storing the null as is).

[Updated on: Tue, 23 September 2008 08:03]

Report message to a moderator

Re: Inserting default value during insert [message #349908 is a reply to message #349903] Tue, 23 September 2008 08:06 Go to previous message
Ronald Beck
Messages: 121
Registered: February 2003
Senior Member
I'd probably do this with a trigger, if you're not going to set the default value.

Ron
Previous Topic: fetch insert and delete record + stored procedure
Next Topic: Trigger Information
Goto Forum:
  


Current Time: Sun Dec 11 08:02:38 CST 2016

Total time taken to generate the page: 0.03921 seconds