Oracle 11g – Check constraint with RegEx

A check constraint follows the same syntax rules as conditions for a WHERE clause: alter table foo add constraint check_email check (REGEXP_LIKE(email,’your_regex_goes_here’,’I’)); More details in the manual: for Oracle 11 – http://docs.oracle.com/cd/E11882_01/server.112/e41084/conditions007.htm#SQLRF52141 for Oracle 12 – https://docs.oracle.com/database/121/SQLRF/conditions007.htm#SQLRF52141 Edit: There are however some restrictions on what you can actually use in a check constraint: Oracle 11 … Read more

How can I describe a table in Oracle without using the DESCRIBE command?

You’re looking for USER_TAB_COLUMNS – all the columns, and their descriptions in the schema the query is executed in – or ALL_TAB_COLUMNS – the same except for all tables that user has permission to view. A typical query might be: select * from user_tab_columns where table_name=”MY_TABLE” order by column_id column_id is the “order” of the … Read more

Display names of all constraints for a table in Oracle SQL

You need to query the data dictionary, specifically the USER_CONS_COLUMNS view to see the table columns and corresponding constraints: SELECT * FROM user_cons_columns WHERE table_name=”<your table name>”; FYI, unless you specifically created your table with a lower case name (using double quotes) then the table name will be defaulted to upper case so ensure it … Read more