Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2004, 04:36 AM
prg18 prg18 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 13 prg18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 55 sec
Reputation Power: 0
Oracle default column values

Hello everyone. I need to know (and can't find anywhere) how the DEFAULT option on columns works. My problem is I have a table such as:

CREATE TABLE table1 (
id number(6) not null,
field1 varchar(155) not null,
field2 varchar(155) DEFAULT 'something' not null);

Now if I do an insert like this:

INSERT INTO table1 (id,field1) VALUES ('5','somethingelse');

I get an error field2 cannot be null. How can I make the field2 default value be used when a value isn't provided? Thank you!

Reply With Quote
  #2  
Old November 17th, 2004, 12:50 AM
J@oracle J@oracle is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 11 J@oracle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Everything fine with ur query....
I tried the same .....
Check it out...
SQL> CREATE TABLE table1 (
2 id number(6) not null,
3 field1 varchar(155) not null,
4 field2 varchar(155) DEFAULT 'something' not null);

Table created.

SQL> INSERT INTO table1 (id,field1) VALUES ('5','somethingelse');

1 row created.

SQL> select * from table1
2 ;

ID
----------
FIELD1
--------------------------------------------------------------------------------
FIELD2
--------------------------------------------------------------------------------
5
somethingelse
something

Reply With Quote
  #3  
Old November 17th, 2004, 01:18 AM
prg18 prg18 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 13 prg18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 55 sec
Reputation Power: 0
Odd...

How strange. What version of Oracle? I'm using 8.1.7 but I definitely get an error - it won't let me add a record if the field is mandatory and a value isn't specified, even when it has a default value...

Reply With Quote
  #4  
Old November 17th, 2004, 02:42 AM
J@oracle J@oracle is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 11 J@oracle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by prg18
How strange. What version of Oracle? I'm using 8.1.7 but I definitely get an error - it won't let me add a record if the field is mandatory and a value isn't specified, even when it has a default value...



I'm having ORACLE10g db ..

Reply With Quote
  #5  
Old November 17th, 2004, 08:36 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 47 m 32 sec
Reputation Power: 20
I'm also on 8.1.7 (on NT) and your example works just fine.

Reply With Quote
  #6  
Old November 17th, 2004, 08:45 AM
prg18 prg18 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 13 prg18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 55 sec
Reputation Power: 0
Solved (more or less)

OK, I think I know what's going on. I can do it in some tables but not in others. The problem I think is the default value in some cases wasn't defined as 'something', but something instead (no apostrophes). Then it won't let me insert rows if the value isn't specified because the default value is invalid. Thankfully I have to completely overhaul the (inherited) database so I'll be able to repair it. Thanks everyone for your help.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesOracle Development > Oracle default column values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT