CREATE TABLE AS 中文man頁面
NAME
CREATE TABLE AS - 從一條查詢的結果中創建一個新表
SYNOPSIS
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name [ (column_name [, ...] ) ] AS query
DESCRIPTION 描述
CREATE TABLE AS 創建一個表并且用來自 SELECT 命令計算出來的數據填充該表。 該表的字段和 SELECT 輸出字段的名字及類型相關。 (只不過你可以通過明確地給出一個字段名字列表來覆蓋 SELECT 的字段名)。
CREATE TABLE AS 和創建視圖有點象, 不過兩者之間實在是有比較大差異:它創建一個新表并且只對 SELECT 計算一次來填充這個新表。 新表不能跟蹤 SELECT 的源表隨后做的變化。 相比之下,每次做查詢的時候,視圖都重新計算定義它的 SELECT 語句。
PARAMETERS 參數
- TEMPORARY or TEMP
如果聲明了這個選項,則該表作為臨時表創建。 參閱 CREATE TABLE [create_table(7)] 獲取細節。- table_name
要創建的表名(可以是用模式修飾的)。- column_name
字段的名稱。如果沒有提供字段名字,那么就從查詢的輸出字段名中獲取。 如果表是一個 EXECUTE 命令創建的, 那么當前就不能聲明字段名列表。- query
一個查詢語句(也就是一條 SELECT 命令或者一條運行準備好的 SELECT 命令的 EXECUTE 命令),請分別參考 SELECT [select(7)] 或者 EXECUTE [execute(l)] 獲取可以使用的語法的描述。
NOTES 注意
這條命令從功能上等效于 SELECT INTO [select_into(7)], 但是我們更建議你用這個命令,因為它不太可能和 SELECT ... INTO 語法的其它方面的使用混淆。
COMPATIBILITY 兼容性
這條命令是根據 Oracle 的一個特性制作的。 在 SQL 標準中沒有功能相等的命令。不過, 把 CREATE TABLE 和 INSERT ... SELECT 組合起來可以通過略微多一些的工作完成同樣的事情。
SEE ALSO 參見
CREATE TABLE [create_table(7)], CREATE VIEW [create_view(l)], EXECUTE [execute(l)], SELECT [select(l)], SELECT INTO [select_into(l)]
#p#
NAME
CREATE TABLE AS - create a new table from the results of a query
SYNOPSIS
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name [ (column_name [, ...] ) ] AS query
DESCRIPTION
CREATE TABLE AS creates a table and fills it with data computed by a SELECT command or an EXECUTE that runs a prepared SELECT command. The table columns have the names and data types associated with the output columns of the SELECT (except that you can override the column names by giving an explicit list of new column names).
CREATE TABLE AS bears some resemblance to creating a view, but it is really quite different: it creates a new table and evaluates the query just once to fill the new table initially. The new table will not track subsequent changes to the source tables of the query. In contrast, a view re-evaluates its defining SELECT statement whenever it is queried.
PARAMETERS
- TEMPORARY or TEMP
- If specified, the table is created as a temporary table. Refer to CREATE TABLE [create_table(7)] for details.
- table_name
- The name (optionally schema-qualified) of the table to be created.
- column_name
- The name of a column in the new table. If column names are not provided, they are taken from the output column names of the query. If the table is created out of an EXECUTE command, a column name list can currently not be specified.
- query
- A query statement (that is, a SELECT command or an EXECUTE command that runs a prepared SELECT command). Refer to SELECT [select(7)] or EXECUTE [execute(l)], respectively, for a description of the allowed syntax.
NOTES
This command is functionally equivalent to SELECT INTO [select_into(7)], but it is preferred since it is less likely to be confused with other uses of the SELECT ... INTO syntax.
COMPATIBILITY
This command is modeled after an Oracle feature. There is no command with equivalent functionality in the SQL standard. However, a combination of CREATE TABLE and INSERT ... SELECT can accomplish the same thing with little more effort.
SEE ALSO
CREATE TABLE [create_table(7)], CREATE VIEW [create_view(l)], EXECUTE [execute(l)], SELECT [select(l)], SELECT INTO [select_into(l)]