Sql oracle过程-获取编译警告
我已经检查了前面类似的问题,没有一个与我的问题相匹配。 编译代码后,我得到警告:执行已完成,警告我试图运行Show errors;,但是什么都没有。然后我运行代码 更新日期:2014-07-15美国东部时间上午9:54Sql oracle过程-获取编译警告,sql,oracle,stored-procedures,Sql,Oracle,Stored Procedures,我已经检查了前面类似的问题,没有一个与我的问题相匹配。 编译代码后,我得到警告:执行已完成,警告我试图运行Show errors;,但是什么都没有。然后我运行代码 更新日期:2014-07-15美国东部时间上午9:54 execute buy_ball('Soccer Ball', 1); 我得到以下错误 Error starting at line 1 in command: execute buy_ball('Soccer Ball', 1); Error report: ORA-0655
execute buy_ball('Soccer Ball', 1);
我得到以下错误
Error starting at line 1 in command:
execute buy_ball('Soccer Ball', 1);
Error report:
ORA-06550: line 1, column 7:
PLS-00905: object SYSMAN.BUY_BALL is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line%s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation Error
代码如下:
CREATE OR REPLACE PROCEDURE buy_ball(aProductnm in VARCHAR2,
aNumber in number)
AS
qtyoh NUMBER;
BEGIN
SELECT quantityonhand
INTO qtyoh
FROM inventory
WHERE productname = aProductnm;
IF qtyoh > 0
THEN
UPDATE inventory
SET quantityonhand = (qtyoh – aNumber)
WHERE Productname = aProductnm;
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (sysdate,
'Soccer Ball purchased',
aNumber,
aProductnm);
ELSE
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (sysdate,
'Out of Stock',
aNumber,
aProductnm);
END IF;
COMMIT;
END;
显示错误运行,但不显示任何内容。只有按照上面的execute命令执行命令时,才会出现错误。使用此版本--
create or replace
procedure buy_ball(aProductnm in Varchar2, aNumber in number)
AS
qtyoh number(5) ;
Begin
select quantityonhand into qtyoh from inventory where productname = aProductnm;
if qtyoh > 0 then
update inventory set quantityonhand = (qtyoh - aNumber) where Productname - aProductnm;
insert into purchase_record (orderdate, orderstatus, quantitypurchase, productname)
values
(sysdate, 'Soccer Ball Purchased', aNumber, aProductnm);
else
insert into purchase_record (orderdate, orderstatus, quantitypurchase, productname)
values
(sysdate, 'Out of Stock', aNumber, aProductnm);
end if;
commit;
end;
我假设在下面提到的语句中,您的意思是“=”而不是“--->
从清单中选择quantityonhand到qtyoh,其中productname-aProductnm 在声明参数和函数返回类型时,不要包含精度或刻度。只能通过先声明变量,然后将其作为参数传递给函数来限制它。您的过程未编译,因此出现错误,必须使用条件运算符,如%、=,使用赋值运算符时处于where条件下的IN等 请尝试使用以下代码
CREATE OR REPLACE PROCEDURE buy_ball (aProductnm IN VARCHAR2,
aNumber IN NUMBER)
AS
qtyoh NUMBER;
BEGIN
SELECT quantityonhand
INTO qtyoh
FROM inventory
WHERE productname = aProductnm;
IF qtyoh > 0
THEN
UPDATE inventory
SET quantityonhand = (qtyoh - aNumber)
WHERE Productname = aProductnm;
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (SYSDATE,
'Soccer Ball Purchased',
aNumber,
aProductnm);
ELSE
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (SYSDATE,
'Out of Stock',
aNumber,
aProductnm);
END IF;
COMMIT;
END;
谢谢你的评论和帮助。我已经设法使代码正常工作,我在这里附上了最终版本。在这里或那里更改空间10个小时,添加光标和删除光标等等。你们都知道这是怎么回事
CREATE OR REPLACE PROCEDURE BUY_BALL (I_Productnm VARCHAR2, I_Number NUMBER)
AS
qtyoh NUMBER(10,0);
BEGIN
SELECT quantityonhand
INTO qtyoh
FROM inventory
WHERE productname = I_Productnm;
IF qtyoh > 0 THEN
UPDATE inventory
SET quantityonhand = qtyoh - I_Number
WHERE Productname = I_Productnm;
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (sysdate,
'Soccer Ball purchased',
I_Number,
I_Productnm);
ELSE
INSERT INTO purchase_record (orderdate,
orderstatus,
quantitypurchase,
productname)
VALUES (sysdate,
'Out of Stock',
I_Number,
I_Productnm);
END IF;
COMMIT;
END;
/
我认为我发现的一个问题是,我看到一篇关于使用大写字母作为过程名称的帖子——这是2012年的一个已知错误,由于我使用的是Oracle 11g,我怀疑它在我的版本中可能仍然存在。当我改变这一点时,程序编译得很干净,执行得很好。
再次感谢 是的,我的意思是等号。但是我尝试了你的更新代码,仍然得到了完全相同的错误。谢谢-是的,我的意思是等号。但是,我尝试了您更新的代码,但仍然得到了完全相同的错误。编译过程时得到的错误是什么?就您的代码而言,存在一些问题,如create或replace语句之后的declare语句,declare通常与匿名块一起使用。在begin之前选择语句,直到它不是游标为止,不要在begin之外使用它。C在提到存储过程中的参数时,您只需要提供数据类型,而不是您正在使用的数据类型的大小。由于update语句,我的版本出现错误。请使用我的版本中当前编写的update语句替换此语句。更新库存集quantityonhand=qtyoh-其中Productname=aProductnm的编号;如果更换后仍然出现错误,请附上日志。谢谢-我删除了所有精度和刻度,但仍然出现完全相同的错误。任何其他建议将不胜感激!编译过程时会出现什么错误?重新编译程序并使用show error。@Nitish-错误与我的原始帖子中描述的完全相同。编译时,我会收到警告,只有在执行时才会收到错误。谢谢-但是-运行上面的代码会在执行时产生完全相同的警告和错误。@Drew你的意思是说你收到的错误与你在问题中提到的完全相同?是的,根据我的第一篇文章。我相信这很容易被忽略……代码本身是直接的,各个命令都是正确的。我甚至尝试过重新启动服务…@虽然有点偏离主题,但在SYSMAN模式中创建数据库对象并不是一个好主意。始终为您的对象创建一个非数据库模式的模式,如SYS、SYSTEM、SYSMAN等@draw,您从何处尝试执行buy_ball'Soccerball',1;?来自SQL Plus、TOAD、SQLDeveloper等。?