|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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, |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Its Easier To Ask! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|