3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Oracle Database 23cで表やビューの最大列数が4096列になったので試してみた

Last updated at Posted at 2023-04-28

はじめに

Oracle Databaseではこれまで表やビューの最大列数が1000でしたが、Oracle Database 23cから最大4096列に拡張されました。

ということで、早速試してみました。

(ちなみに最大列数が1000になったのはOracle 8からで、Oracle 7.3までは最大列数が255でした。最大列数を1000に引き上げる際に少し関わっていたので、よく覚えています。)

1. 列数が4096の表の作成(1)

Oracle Database 23c Free - Developer Releaseをインストール後のデフォルトの状態で、列数が4096の表tbl4096を以下のようなDDLで作成してみます。

SQL> CREATE TABLE tbl4096 (
  2    col1    number,
  3    col2    number,
  4    col3    number,
  5    col4    number,
  6    col5    number,
  7    col6    number,
  8    col7    number,
  9    col8    number,
<中略>
4089    col4088 number,
4090    col4089 number,
4091    col4090 number,
4092    col4091 number,
4093    col4092 number,
4094    col4093 number,
4095    col4094 number,
4096    col4095 number,
4097    col4096 number);
        col1001 number,
        *
ERROR at line 1002:
ORA-01792: maximum number of columns in a table or view is 1000


SQL>

おっと、表の最大列数は1000までというエラーになりました。
これは、Oracle Database 23cでもデフォルトの設定では表の最大列数が1000になっているためです。

2. 初期化パラメータの変更(1)

表の最大列数を4096列に変更するには、初期化パラメータmax_columnsを変更します。

デフォルトでは、max_columnsの値は「STANDARD」になっています。
これは表の最大列数が、従来通りの1000であることを意味します。

SQL> show parameter max_columns

NAME				                 TYPE	     VALUE
------------------------------------ ----------- ------------------------------
max_columns			                 string	     STANDARD
SQL> 

また、表の最大列数を4096に変更するには、初期化パラメータcompatibleが23.0.0.0以上である必要があります。
念の為、compatibleの値を確認します。

SQL> show parameter compatible

NAME				                 TYPE	     VALUE
------------------------------------ ----------- ------------------------------
compatible			                 string	     23.0.0
noncdb_compatible		             boolean	 FALSE
SQL> 

compatibleが23.0.0ですので、このままで表の最大列数を変更できることが確認できました。

表の最大列数を4096にするには、ALTER SYSTEM文でmax_columnsを「EXTENDED」に設定します。
max_columnsは動的に変更できないため、SCOPEにspfileを指定してALTER SYSTEM文を実行し、PDBを再起動します。

SQL> ALTER SYSTEM SET max_columns = EXTENDED SCOPE=spfile;

System altered.

SQL>
SQL> shutdown immediate
Pluggable Database closed.
SQL> startup
Pluggable Database opened.
SQL> 

max_columnsの値がEXTENDEDに変更されていることを確認します。

SQL> show parameter max_columns

NAME				                 TYPE	     VALUE
------------------------------------ ----------- ------------------------------
max_columns			                 string	     EXTENDED
SQL>

3. 列数が4096の表の作成(2)

再度、列数が4096の表を作成してみます。

SQL> CREATE TABLE tbl4096 (
  2    col1    number,
  3    col2    number,
  4    col3    number,
  5    col4    number,
  6    col5    number,
  7    col6    number,
  8    col7    number,
  9    col8    number,
<中略>
4089    col4088 number,
4090    col4089 number,
4091    col4090 number,
4092    col4091 number,
4093    col4092 number,
4094    col4093 number,
4095    col4094 number,
4096    col4095 number,
4097    col4096 number);

Table created.

SQL>

今度は問題なく作成できました。

4. 列数が4096の表へのデータのINSERT

表が作成できたので、データをINSERTしてみます。

SQL> INSERT INTO tbl4096 VALUES (
  2  1,
  3  2,
  4  3,
  5  4,
  6  5,
  7  6,
  8  7,
  9  8,
 10  9,
<中略>
4089  4088,
4090  4089,
4091  4090,
4092  4091,
4093  4092,
4094  4093,
4095  4094,
4096  4095,
4097  4096);

1 row created.

SQL>

問題なくデータをINSERTできました。

2. 初期化パラメータの変更(2)

4096列を持つ表がある状態で、ALTER SYSTEM文でmax_columnsを「STANDARD」に戻してみます。

SQL> ALTER SYSTEM SET max_columns=STANDARD SCOPE=spfile; 
ALTER SYSTEM SET max_columns=STANDARD SCOPE=spfile
*
ERROR at line 1:
ORA-32017: failure in updating SPFILE
ORA-60471: max_columns can not be set to STANDARD as there are one or more
objects with more than 1000 columns


SQL> 

データベース内に列数が1000を超えるオブジェクトがあるためSTANDARDに変更できないというエラーが発生しました。

4096列を持つ表を削除します。

SQL> DROP TABLE tbl4096;

Table dropped.

SQL>

再度、ALTER SYSTEM文でmax_columnsを「STANDARD」に戻してみます。

SQL> ALTER SYSTEM SET max_columns=STANDARD SCOPE=spfile;

System altered.

SQL>

問題なく変更ができ、表の最大列数が1000に戻りました。

参考情報

Oracle Database 23c New Features:Increase Column Limit
Oracle Database 23c Database Reference:MAX_COLUMNS

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?