一時テーブルの作成¶
以下の表に、一時テーブルを作成するための構文を示します。
CREATE TEMPORARY TABLE ステートメントの構文¶
CREATE TEMPORARY TABLE <name:identifier>
(
<VDP type field> [, <VDP type field> ]*
| <SQL type field> [, <SQL type field> ]*
)
[ FOLDER = <literal> ]
[ <primary key> ]
<VDP type field> ::=
<name:identifier> : <Virtual DataPort data type>
[ ( <property list> ) ]
<Virtual DataPort data type> ::= (see Figure 1)
<SQL type field> ::= <name:identifier> <SQL type>
[ ( <property> [, <property> ]+ ) ]
<SQL type> ::=
| BIT ( <integer> )
| BIT VARYING ( <integer> )
| BLOB
| BOOLEAN
| CHAR ( <integer> )
| CHARACTER ( <integer> )
| CHARACTER VARYING ( <integer> )
| DATE
| DECIMAL
| DECIMAL ( <integer>, <integer> )
| DOUBLE
| DOUBLE PRECISION
| FLOAT
| INT
| INTEGER
| LONG
| NCHAR ( <integer> )
| NUMERIC
| NUMERIC ( <integer> , <integer> )
| NVARCHAR ( <integer> )
| REAL
| SMALLINT
| TEXT
| TIMESTAMP
| TIMESTAMP WITH TIME ZONE
| VARCHAR ( <integer> )
CREATE TEMPORARY TABLE <name:identifier>
[ ( <field without type> [, <field without type> ]* ) ]
AS <select>
<field without type> ::= <name:identifier> [ ( <property list> ) ]
<property list> ::=
<property name:identifier> [ = <value:identifier> ]
[, <property name i:identifier> [ = <value i:identifier> ] ]*
<primary key> ::=
[ CONSTRAINT <name:literal> ]
PRIMARY KEY ( <field name:literal> [, <field name:literal> ]* )
<select> ::= (「 SELECT ステートメントの構文 」を参照)
フィールドの型を指定するために、ネイティブ VQL データ型または SQL データ型のいずれかを使用できます。SQL データ型は変換されます。
以下に例を示します。
CREATE TEMPORARY TABLE の例¶
CREATE TEMPORARY TABLE employee (
ssn : text
, first_name : text
, surname : text
)
CONSTRAINT 'primary_key_employee' PRIMARY KEY ('ssn');
この例では、「ssn」フィールドをプライマリキーとして一時テーブルが作成されます。Virtual DataPort では、ビューのプライマリキーは強制されません。このフィールドには重複する値を挿入しないようにする必要があります。
クエリの結果から一時テーブルを作成する例¶
CREATE TEMPORARY TABLE employee_dept_10 AS SELECT * FROM employee
WHERE dept_no = 10;
一時テーブルの作成後は、通常のビューと同様にデータを挿入でき、同じステートメントで複数の行を挿入することもできます。
以下に例を示します。
一時テーブルにデータを挿入する方法の例¶
INSERT INTO employee (first_name, surname, ssn)
VALUES ('Emma', 'Smith', '987-65-4321');
INSERT INTO employee (SELECT 'Robert', 'Brown', '123-45-6789' from
Dual());
INSERT INTO employee (first_name, surname, ssn) VALUES
('Emma', 'Smith', '987-65-4321')
, ('Elizabeth', 'Brown', '987-65-4322');
INSERT
句の詳細については、「 INSERT ステートメント 」を参照してください。
必要な権限¶
一時テーブルを作成するユーザーは、少なくとも以下のいずれかの権限を持っている必要があります。
データベースに対する
CREATE
権限。データベースに対する
CREATE_VIEW
権限。create_temporary_table
ロール。このロールを持つユーザーは、任意のデータベースから一時テーブルを作成できます。