oracle - 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;
解决方案
删除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
而不仅仅是一行。
推荐阅读
- asp.net-core - Neo4j 4 和 .NET Core 身份框架
- firebase - 如何从 Firebase 云存储中删除图像
- ruby-on-rails - Ruby ActiveRecord has_many 没有运行 Join
- java - 如何在引用外部组件时将“$ref”中的 http url 设置为动态的 URL 引用和特定于环境的 swagger yaml 文件?
- python - 加载 psycopg2 模块时出错:导入 _psycopg 时 DLL 加载失败:找不到指定的模块
- html - IE 中的 object-fit 属性的 html/css 问题
- php - 当 div #firstpage 设置为隐藏时,为什么我的 div #firstpage 显示在我的 div #lastpage 上?
- python - 如何更改 create_initial_grid 函数,以便单元格的第一个位置由坐标列表而不是随机函数决定
- python - 在python中进行样条插值的更快方法
- azure - Azure Function v1 中的 Azure 服务总线会话支持