Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check for not null column constraint in oracle sql?

How do i check if a column in a table has a not null constraint in an oracle db? Can it be checked with the data dictionary?

like image 864
serpiente Avatar asked Mar 02 '12 01:03

serpiente


People also ask

Is NOT NULL constraint in Oracle?

An Oracle NOT NULL constraint specifies that a column cannot contain NULL values. The Oracle NOT NULL constraints are inline constraints which are typically used in the column definition of the CREATE TABLE statement. It is possible to add a NOT NULL constraint to an existing table by using the ALTER TABLE statement.

IS NOT NULL in Oracle where clause?

Here is an example of how to use the Oracle IS NOT NULL condition in a SELECT statement: SELECT * FROM customers WHERE customer_name IS NOT NULL; This Oracle IS NOT NULL example will return all records from the customers table where the customer_name does not contain a null value.

IS NOT NULL column level constraint?

A NOT NULL> constraint specifies that a column cannot contain a null value. All table updates must specify values in columns with this constraint. You can set a NOT NULL constraint on columns when you create a table, or set the constraint on an existing table with ALTER TABLE.


1 Answers

SELECT nullable
  FROM all_tab_cols
 WHERE owner = <<owner of table>>
   AND table_name = <<name of table>>
   AND column_name = <<name of column>>

will work assuming the column is marked NOT NULL rather than, say, having a CHECK constraint that checks that it is non-NULL.

like image 85
Justin Cave Avatar answered Sep 18 '22 16:09

Justin Cave