How to create a positive integer column in oracle?

Member

by daisha , in category: MySQL , 10 months ago

How to create a positive integer column in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 10 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.

Related Threads:

How to compare the seconds between two dates to an integer in oracle?
How to fill empty column from another table in oracle?
How to extract a substring from column in oracle?
How to update a column using oracle trigger?
How to find column as exception cause in oracle?
How to read a very long blob column in oracle?