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

Reply
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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old May 7th, 2004, 06:28 AM
macuser55 macuser55 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 19 macuser55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Its Easier To Ask!

Hi All,

I have columns in my tables that must contain integers greater than or equal to zero. I could add a constraint to the column, but I suspect there is a data type that automatically includes this constraint (such as POSINT, or similar).

What is the Oracle data type, and parameters, that I should use? Or do I just have to manually add the constraints?

Thanks

Chris

Reply With Quote
  #2  
Old May 7th, 2004, 08:49 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
No, I dont think so that oracle provides such a datatype, the only way just to write a constraint, In the following example column no_2 is set to 0 (zero) as default, in case of ignoring this column in INSERT statement then oracle automatically store 0 (zero), as well as check that given value is greater than or egual to 0 (zero), if given value is less than 0 (zero) than a constraint error will be prompt:


CREATE TABLE num_test (
no_1 NUMBER (3),
no_2 NUMBER (3) DEFAULT 0 NOT NULL
CHECK (no_2>=0))
/

INSERT INTO num_test (no_1) values (100) -- store 0 as default in no_2
/

INSERT INTO num_test values (200,-10) -- constraint error
/

If you find anything better this example , let me know also.

Regards,

Reply With Quote
  #3  
Old May 7th, 2004, 10:45 PM
macuser55 macuser55 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 19 macuser55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cheers Shafique,

It got me on the right track. Implementing CHECK in the create table statement generated errors for me, however adding the constraints separately did not.

ALTER TABLE orders ADD CONSTRAINT numberO_C
CHECK (numberO >= 0);

Cheers

Chris

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Its Easier To Ask!


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 4 hosted by Hostway