23ai: Create table if not exists

Within 23ai, we can create a table if not exist and we can ignore the error if exists, we are going to check the existing of a table.

SQL> desc tb01
ERROR:
ORA-04043: Object tb01 does not exist.
Help: https://docs.oracle.com/error-help/db/ora-04043/


SQL>

SQL> create table IF NOT EXISTS TB01 (id integer, name varchar2(40));

Table created.

SQL>
SQL> desc TB01
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(40)

SQL>

While the table exists, we are going to recreate the table while changing the size varchar

SQL> create table IF NOT EXISTS TB01 (id integer, name varchar2(20));

Table created.

SQL>
SQL> desc TB01
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(40)

SQL>

Enjoy!

Bookmark the permalink.
Loading Facebook Comments ...

Leave a Reply