0

我正在尝试通过在分配的表空间 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 个表来指导我创建单个表有什么问题,我将不胜感激。

谢谢!

4

1 回答 1

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;

文档create table非常复杂,但关系表部分显示物理属性- 包括段属性,包括TABLESPACE子句 - 位于表属性- 包括AS subquery子句之前。这是声明的最后一部分。

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

于 2013-08-05T15:07:17.743 回答