错误 ORA-06550 ORA-00933

发布于 2024-08-03 04:11:06 字数 1134 浏览 5 评论 0原文

我有一个销售表:

    Name         Null?      Type  
SALE_ID         NOT NULL  NUMBER(4)  
SALE_DATE                 DATE  
NO_OF_PRODS               NUMBER(4)  
PROD_ID         NOT NULL  NUMBER(4)  
CUST_ID         NOT NULL  NUMBER(4)  
DESP_ID         NOT NULL  NUMBER(4)  
SALE_RECEIPT    NOT NULL  NUMBER(5) 

我试图将随机生成的数据插入到销售表中。我正在使用 iSQL plus for oracle。这只是我必须创建的测试数据。 我运行以下脚本来生成数据:

begin
insert into sales
select sale_id_seq.nextval,
       sysdate,
       trunc(dbms_random.value(000,999)),
       p.prod_id, c.cust_id 
       FROM dba_xy.product p, dba_xy.customer c,
       desp_id_seq.nextval,
           trunc(dbms_random.value(0000,9999));

end; /

但是当我这样做时,出现以下错误消息:

trunc(dbms_random.value(0000,9999));
                *

ERROR at line 9: ORA-06550: 第 9 行,第 21 列: PL/SQL: ORA-00933: SQL 命令未正确结束 ORA-06550: 第 2 行,第 2 列: PL/SQL:SQL 语句被忽略。

我做错了什么?

我刚刚意识到 DESP_ID 是销售表中的外键,但目前发送表是空的,当我尝试将数据插入任一表时,我无法导致一个表需要另一个表中的数据。我最终收到此错误消息:

PL/SQL: ORA-02289: sequence does not exist 

I have a sales table:

    Name         Null?      Type  
SALE_ID         NOT NULL  NUMBER(4)  
SALE_DATE                 DATE  
NO_OF_PRODS               NUMBER(4)  
PROD_ID         NOT NULL  NUMBER(4)  
CUST_ID         NOT NULL  NUMBER(4)  
DESP_ID         NOT NULL  NUMBER(4)  
SALE_RECEIPT    NOT NULL  NUMBER(5) 

I am trying to insert randomly generated data into the sales table. I am using iSQL plus for oracle. This is just test data that I have to create.
I run the following script to generate the data:

begin
insert into sales
select sale_id_seq.nextval,
       sysdate,
       trunc(dbms_random.value(000,999)),
       p.prod_id, c.cust_id 
       FROM dba_xy.product p, dba_xy.customer c,
       desp_id_seq.nextval,
           trunc(dbms_random.value(0000,9999));

end;
/

But when I do, the following error message appears:

trunc(dbms_random.value(0000,9999));
                *

ERROR at line 9:
ORA-06550: line 9, column 21:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 2, column 2:
PL/SQL: SQL Statement ignored.

What have I done wrong?

I just realised that the DESP_ID is a foreign key within the sales table, but currently the despatch table is empty and when I try to insert data into either tables, I'm not able to cause one table needs the data from the other table. I end up getting this error message:

PL/SQL: ORA-02289: sequence does not exist 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2024-08-10 04:11:06

您无法选择 FROM

FROM dba_xy.product p, dba_xy.customer c,
   desp_id_seq.nextval,
       trunc(dbms_random.value(0000,9999));

Try:

insert into sales
(select 
   sale_id_seq.nextval,
   sysdate,
   trunc(dbms_random.value(000,999)),
   p.prod_id, 
   c.cust_id, 
   desp_id_seq.nextval,
   trunc(dbms_random.value(0000,9999))
   FROM dba_xy.product p, dba_xy.customer c;

顺便说一句,您确定要在这里使用笛卡尔积吗?也许错过了某些连接?

You cannot select FROM

FROM dba_xy.product p, dba_xy.customer c,
   desp_id_seq.nextval,
       trunc(dbms_random.value(0000,9999));

Try:

insert into sales
(select 
   sale_id_seq.nextval,
   sysdate,
   trunc(dbms_random.value(000,999)),
   p.prod_id, 
   c.cust_id, 
   desp_id_seq.nextval,
   trunc(dbms_random.value(0000,9999))
   FROM dba_xy.product p, dba_xy.customer c;

BTW, are you sure that you want an Cartesian product here, maybe some join is missed ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文