This topic describes how to use CREATE TABLE AS SELECT (CTAS) to write query results into a new table while creating it, and how to combine it with the direct load hint and default_load_mode.
Data sources can be internal tables, external tables, or SELECT statements with FILES(...).
Direct load modes (full/incremental)
The CREATE TABLE AS SELECT statement specifies the direct load mode by using the DIRECT() hint. If this hint is not specified, the default behavior can be controlled by the default_load_mode parameter.
Syntax
CREATE /*+ [APPEND | DIRECT(need_sort,max_error,{'full'|'inc'|'inc_replace'})] parallel(N) */ TABLE table_name [AS] select_sentence
For more information about the CREATE TABLE AS SELECT syntax, see CREATE TABLE (MySQL-compatible mode) and CREATE TABLE (Oracle-compatible mode).
Parameter description:
Parameter |
Description |
||
|---|---|---|---|
| APPEND \ | DIRECT() | Use hints to enable the direct load feature.
|
inc_replace: Indicates the two modes of incremental direct load.
NoticeWhen |
| parallel(N) | The degree of parallelism for loading data. This parameter is required and must be an integer greater than 1. |
Examples
Use direct load to import data from table tbl1 into other tables.
Create table
tbl1and write test data into it.obclient [test]> CREATE TABLE tbl1(c1 int); obclient [test]> INSERT INTO tbl1 VALUES (1),(2),(3); obclient [test]> SELECT * FROM tbl1;Use
CREATE TABLE AS SELECTto import data intotbl2.Full mode:
obclient [test]> CREATE /*+ direct(true, 0, 'full') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;Incremental mode:
obclient [test]> CREATE /*+ direct(true, 0, 'inc') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1; obclient [test]> CREATE /*+ direct(true, 0, 'inc_replace') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;Optional: Use
APPEND(equivalent toDIRECT(true, 0)):obclient [test]> CREATE /*+ append parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;
If no hint is specified, you can control the default mode by using the configuration item:
obclient [test]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE'; obclient [test]> CREATE TABLE tbl2 AS SELECT * FROM tbl1;or:
obclient [test]> ALTER SYSTEM SET default_load_mode ='INC_DIRECT_WRITE'; obclient [test]> CREATE TABLE tbl2 AS SELECT * FROM tbl1;
Use direct load to import data from table tbl1 into other tables.
Create table
tbl1and write test data into it.obclient [SYS]> CREATE TABLE tbl1(c1 int); obclient [SYS]> INSERT INTO tbl1 VALUES (1),(2),(3); obclient [SYS]> SELECT * FROM tbl1;Use
CREATE TABLE AS SELECTto import data intotbl2.Full mode:
obclient [SYS]> CREATE /*+ direct(true, 0, 'full') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;Incremental mode:
obclient [SYS]> CREATE /*+ direct(true, 0, 'inc') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1; obclient [SYS]> CREATE /*+ direct(true, 0, 'inc_replace') parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;Optional: Use
APPEND(equivalent toDIRECT(true, 0)):obclient [SYS]> CREATE /*+ append parallel(4) */ TABLE tbl2 AS SELECT * FROM tbl1;
If no hint is specified, you can control the default mode by using the configuration item:
obclient [SYS]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE'; obclient [SYS]> CREATE TABLE tbl2 AS SELECT * FROM tbl1;or:
obclient [SYS]> ALTER SYSTEM SET default_load_mode ='INC_DIRECT_WRITE'; obclient [SYS]> CREATE TABLE tbl2 AS SELECT * FROM tbl1;