Oracle 23.26Data typesLab-verified · 2026-11-30

ORA-00997: illegal use of LONG datatype

A LONG column was used where SQL does not allow it, such as CREATE TABLE AS SELECT or INSERT SELECT.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-00997: illegal use of LONG datatype

Jump to a cause

  1. 01CREATE TABLE AS SELECT the TEXT column of USER_VIEWS
  2. 02INSERT SELECT a LONG column into a CLOB column

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim

LONG is an old datatype with many restrictions. You can select it as is, but copying it with CREATE TABLE ... AS SELECT or INSERT ... SELECT fails with ORA-00997. The * in the error points at the LONG column.

You often meet LONG in the data dictionary, for example USER_VIEWS.TEXT, or in old tables. Below are two cases run on Oracle 26ai Free, each with a fix that actually worked.

01CREATE TABLE AS SELECT the TEXT column of USER_VIEWS

To back up view definitions, CREATE TABLE view_backup AS SELECT view_name, text FROM user_views fails with ORA-00997, and the * points at text.

Checking the dictionary columns showed why: TEXT is LONG, while TEXT_VC is VARCHAR2. Using text_vc instead of text created the table, and SELECT from it showed the view text SELECT id, name FROM emp WHERE dept = 'SALES'.

Setup
Setuprun as lab_a
CREATE TABLE emp (id NUMBER PRIMARY KEY, name VARCHAR2(20), dept VARCHAR2(10));
CREATE VIEW sales_emp AS SELECT id, name FROM emp WHERE dept = 'SALES';
OUTPUT
Table created.


View created.
Reproducerun as lab_a
CREATE TABLE view_backup AS SELECT view_name, text FROM user_views;
✕ ERROR
CREATE TABLE view_backup AS SELECT view_name, text FROM user_views
                                              *
ERROR at line 1:
ORA-00997: illegal use of LONG datatype
Help: https://docs.oracle.com/error-help/db/ora-00997/
Checkrun as lab_a
COLUMN column_name FORMAT A12
COLUMN data_type FORMAT A10
SELECT column_name, data_type FROM all_tab_columns WHERE owner = 'SYS' AND table_name = 'USER_VIEWS' AND column_name IN ('TEXT', 'TEXT_VC');
OUTPUT
COLUMN_NAME  DATA_TYPE
------------ ----------
TEXT         LONG
TEXT_VC      VARCHAR2

2 rows selected.

TEXT_VC exists in USER_VIEWS on this 26ai database. Check ALL_TAB_COLUMNS on your version before relying on it.

After the fixrun as lab_a
CREATE TABLE view_backup AS SELECT view_name, text_vc FROM user_views;
COLUMN view_name FORMAT A10
COLUMN text_vc FORMAT A50
SELECT view_name, text_vc FROM view_backup;
✓ SUCCESS
Table created.


VIEW_NAME  TEXT_VC
---------- --------------------------------------------------
SALES_EMP  SELECT id, name FROM emp WHERE dept = 'SALES'

1 row selected.

02INSERT SELECT a LONG column into a CLOB column

Moving data from an old table (notes_old.body LONG) to a new one (notes_new.body CLOB) with INSERT INTO notes_new SELECT id, body FROM notes_old fails with ORA-00997. Even though the target is a CLOB, the LONG is not converted automatically.

USER_TAB_COLUMNS confirmed NOTES_OLD is LONG and NOTES_NEW is CLOB. Wrapping the column with TO_LOB(body) worked: 2 rows created, and both memos were in the CLOB column.

Setup
Setuprun as lab_a
CREATE TABLE notes_old (id NUMBER PRIMARY KEY, body LONG);
INSERT INTO notes_old VALUES (1, 'first memo');
INSERT INTO notes_old VALUES (2, 'second memo');
COMMIT;
CREATE TABLE notes_new (id NUMBER PRIMARY KEY, body CLOB);
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.


Table created.
Reproducerun as lab_a
INSERT INTO notes_new SELECT id, body FROM notes_old;
✕ ERROR
INSERT INTO notes_new SELECT id, body FROM notes_old
                                 *
ERROR at line 1:
ORA-00997: illegal use of LONG datatype
Help: https://docs.oracle.com/error-help/db/ora-00997/
Checkrun as lab_a
COLUMN table_name FORMAT A10
COLUMN data_type FORMAT A10
SELECT table_name, data_type FROM user_tab_columns WHERE column_name = 'BODY' ORDER BY table_name;
OUTPUT
TABLE_NAME DATA_TYPE
---------- ----------
NOTES_NEW  CLOB
NOTES_OLD  LONG

2 rows selected.
After the fixrun as lab_a
INSERT INTO notes_new SELECT id, TO_LOB(body) FROM notes_old;
COLUMN body FORMAT A20
SELECT id, body FROM notes_new ORDER BY id;
ROLLBACK;
✓ SUCCESS
2 rows created.


        ID BODY
---------- --------------------
         1 first memo
         2 second memo

2 rows selected.


Rollback complete.

FAQ

How do I copy a LONG column to a new table?

Make the target column a CLOB and use INSERT INTO new_table SELECT id, TO_LOB(long_col) FROM old_table. On this page that inserted both rows.

Why does CREATE TABLE AS SELECT from USER_VIEWS fail with ORA-00997?

USER_VIEWS.TEXT is a LONG column. On 26ai, select TEXT_VC (VARCHAR2) instead, and the CTAS works.

How do I check if a column is LONG?

Look at DATA_TYPE in USER_TAB_COLUMNS or ALL_TAB_COLUMNS. The column marked by * in the error message is usually the LONG one.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0