通过在指定的表空间上连接多个表来创建单个表

时间:2013-08-05 14:50:22

标签: oracle

我正在尝试通过在指定的表空间tbspUser1上连接4个表来创建单个表。

我使用了以下声明:

CREATE TABLE SingleTable AS(
SELECT customer.c_id AS Customer_ID, 
customer.c_uname AS CUSTOMER_UName, 
ORDERS.o_id AS Order_ID, 
ORDER_LINE.ol_i_id As Order_Item_ID, 
ITEM.I_TITLE AS Item_Title
FROM customer INNER JOIN orders ON customer.C_ID=orders.O_C_ID
INNER JOIN order_line ON orders.o_id=order_line.ol_o_id
INNER JOIN item ON order_line.ol_i_id=item.i_id) TABLESPACE tbspUser1;

我收到了错误:

Error starting at line 1 in command:
CREATE TABLE SingleTable AS(
SELECT customer.c_id AS Customer_ID, 
customer.c_uname AS CUSTOMER_UName, 
ORDERS.o_id AS Order_ID, 
ORDER_LINE.ol_i_id As Order_Item_ID, 
ITEM.I_TITLE AS Item_Title
FROM customer INNER JOIN orders ON customer.C_ID=orders.O_C_ID
INNER JOIN order_line ON orders.o_id=order_line.ol_o_id
INNER JOIN item ON order_line.ol_i_id=item.i_id) TABLESPACE tbspUser1
Error at Command Line:9 Column:50
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

我一直在调试并检查我的代码有什么问题,并自行运行我的select语句:

SELECT customer.c_id AS Customer_ID, 
customer.c_uname AS CUSTOMER_UName, 
ORDERS.o_id AS Order_ID, 
ORDER_LINE.ol_i_id As Order_Item_ID, 
ITEM.I_TITLE AS Item_Title
FROM customer INNER JOIN orders ON customer.C_ID=orders.O_C_ID
INNER JOIN order_line ON orders.o_id=order_line.ol_o_id
INNER JOIN item ON order_line.ol_i_id=item.i_id;

它返回包含以下字段的记录,没有错误:

CUSTOMER_ID CUSTOMER_UNAME         ORDER_ID ORDER_ITEM_ID ITEM_TITLE                                                 
----------- -------------------- ---------- ------------- ------------------------------------------------------------

如果有人可以通过在指定的表空间语句中连接4个表来指导我创建单个表的错误,我将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

这与连接无关。错误消息指向第9行第50列,它是关键字TABLESPACE的开头,而不是查询的一部分。您的TABLESPACE子句位置错误:

CREATE TABLE SingleTable
TABLESPACE tbspUser1
AS
SELECT customer.c_id AS Customer_ID, 
customer.c_uname AS CUSTOMER_UName, 
ORDERS.o_id AS Order_ID, 
ORDER_LINE.ol_i_id As Order_Item_ID, 
ITEM.I_TITLE AS Item_Title
FROM customer INNER JOIN orders ON customer.C_ID=orders.O_C_ID
INNER JOIN order_line ON orders.o_id=order_line.ol_o_id
INNER JOIN item ON order_line.ol_i_id=item.i_id;

documentation for create table非常复杂,但relational tables的部分显示physical properties - 其中包含segment attributes,其中包含TABLESPACE子句 - 来自之前table properties - 包括AS subquery子句。这是声明的最后部分。

创建一个包含其他四个数据的表似乎很奇怪;听起来你想要一个视图或者一个物化视图,否则对原始四个表的更改将不会反映在singletable中。