How to create a positive integer column in oracle?

Member

by daisha , in category: MySQL , 3 months ago

How to create a positive integer column in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 3 months ago

@daisha 

To create a positive integer column in Oracle, you can use the following SQL syntax when creating a table:

1
2
3
CREATE TABLE table_name (
    column_name NUMBER(10,0) CHECK (column_name > 0)
);


In this example, column_name is the name of the column, NUMBER(10,0) specifies that the column will store integer values with up to 10 digits (adjust as needed), and the CHECK constraint ensures that only positive integers can be stored in the column.


You can also specify a default value for the column by adding the DEFAULT keyword followed by the desired default value:

1
2
3
CREATE TABLE table_name (
    column_name NUMBER(10,0) DEFAULT 0 CHECK (column_name > 0)
);


Remember to replace table_name and column_name with your actual table and column names.