我正在尝试从Oracle SQL Developer中的其他两个表创建一个表:
CREATE TABLE share_stock(
share_id NUMBER(6,0),
share_price NUMBER(10,2),
company_id NUMBER(6,0),
company_name VARCHAR2(50),
ticker_symbol VARCHAR2(4),
AS SELECT share_price.share_price_id, share_price.price, share_price.company_id, company.name, company.ticker_symbol
FROM share_price, company
WHERE share_price.company_id = company.company_id,
CONSTRAINT sh_pk PRIMARY KEY (share_price.share_price_id),
CONSTRAINT sh_pr_fk FOREIGN KEY (share_price.share_price_id) REFERENCES share_price(share_price_id)
);
基本上我正在尝试执行CREATE AS SELECT,但是我收到了这个错误:
命令行错误:294列:28错误报告:SQL错误: ORA-00904 ::无效的标识符 00904. 00000 - “%s:无效标识符”
我试图纠正我的语法,到目前为止我还没有成功, 任何想法都会有所帮助,
提前致谢。
答案 0 :(得分:4)
尝试这种方式:
CREATE TABLE share_stock
AS
SELECT SP.share_price_id as share_id ,
SP.price as share_price, SP.company_id, C.name,
C.ticker_symbol
FROM share_price SP
join company C on SP.company_id = C.company_id;
alter table share_stock
add CONSTRAINT sh_pk PRIMARY KEY (share_id);
alter table share_stock
add CONSTRAINT sh_pr_fk FOREIGN KEY (share_id)
REFERENCES share_price(share_price_id);
答案 1 :(得分:0)
CONSTRAINT sh_pk PRIMARY KEY( share_price.share_price_id ), CONSTRAINT sh_pr_fk FOREIGN KEY(** share_price。** share_price_id)REFERENCES share_price(share_price_id) );
您的代码不起作用,因为ORACLE不知道什么是share_price.shareprice_id ??? 您应该编写share_id,即您希望成为表share_stock的主键的列。
亲切的问候, MJ。