首页 > 解决方案 > PLS-00103:尝试使用序列递增值时遇到符号 DECLARE/EOF

问题描述

我正在开发一个过程,该过程将声明一个变量,从一个递增的过程中获取值,并将该值与其他参数一起插入到表中。我以为我已经解决了所有问题,但后来我遇到了 PLS-00103:遇到符号“DECLARE”和遇到符号“文件结尾”。我觉得我很接近,所以任何帮助将不胜感激!谢谢!

create or replace procedure Order_Create(date_order string, cust_id char, total float, employ_id number)
is
DECLARE NewKey;
BEGIN
NewKey := order_auto_inc.nextval;
UPDATE Progressive_Keys set Order_Limit = NewKey;
insert into ORDERS VALUES (Progressive_Keys.Order_Limit, to_date(date_order, 'yyyy-mm-dd'), cust_id, total, employ_id);
commit;
END;

标签: oracleplsqlpls-00103

解决方案


删除declare存储过程中不需要的(如手册中所述)。

变量声明需要数据类型。

由于参数order_date应该是日期,因此应该使用该类型声明。

您无法访问order_limit使用该表的语句之外的列,progressive_keys因此您还需要在插入语句中使用该变量。

始终在 INSERT 语句中列出目标列也是一种很好的编码习惯(请注意,我刚刚为orders表发明了一些列名,您必须调整它们以反映表中的真实名称)

create or replace procedure Order_Create(date_order date, cust_id varchar, total float, employ_id number)
is
  NewKey number;
BEGIN
  NewKey := order_auto_inc.nextval;
  UPDATE Progressive_Keys set Order_Limit = NewKey;
  insert into ORDERS (some_key, order_date, customer_id, total, employee_id)
  VALUES (newkey, date_order, cust_id, total, employ_id);
  commit;
END;

UPDATE 看起来有点奇怪,因为它会更新thable 中的所有行,progressive_keys而不仅仅是一行。


推荐阅读