存储过程中的选择计数(*),并在if语句中使用计数
我正在Oracle数据库中创建一个存储过程,该过程导致错误” ORA-01858:在预期数字的情况下找到了一个非数字字符”。
我的过程如下:
create or replace procedure testProc(
id IN VARCHAR2,
user IN VARCHAR2,
sender IN VARCHAR2
)
as
vCount number;
begin
select count(*) into vCount from table1 where id='12345'
if vCount=0
insert into table1 (id, user, sender, status) values (id, user, partner, status);
else
update table1 set status='ERR' where id='12345'
end if;
end procedure;
错误:ORA-01858:发现了一个非数字字符,而我尝试替换数字
我尝试替换vcount作为int无济于事。还尝试在Varchar2中的发件人下方声明VCOUNT。
有人可以告诉什么是正确使用上述过程的正确方法。
I am creating a stored procedure in Oracle database that's resulting in error "ORA-01858: a non-numeric character was found where a numeric was expected".
My procedure is as below:
create or replace procedure testProc(
id IN VARCHAR2,
user IN VARCHAR2,
sender IN VARCHAR2
)
as
vCount number;
begin
select count(*) into vCount from table1 where id='12345'
if vCount=0
insert into table1 (id, user, sender, status) values (id, user, partner, status);
else
update table1 set status='ERR' where id='12345'
end if;
end procedure;
Error: ORA-01858: a non-numeric character was found where a numeric was expected
I tried replacing vCount as int that did not help. Also tried declaring vCount below sender IN VARCHAR2.
Can someone please tell what is correct way to use the above procedure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
Merge
语句,然后您可以在单个语句中执行(而不是选择
,然后是insert
或update>更新
>):db<> fiddle
Use a
MERGE
statement then you can do it in a single statement (rather thanSELECT
followed by eitherINSERT
orUPDATE
):db<>fiddle here
此代码无法返回您指定的错误,因为
用户
,因为它是关键字,保留用于当前记录用户)因此,不可能帮助您解决您所说的错误。否则,请考虑不要命名过程的参数与列名相同,因为这会导致各种问题。
像这样的东西会起作用,但与您遇到的错误无关。
示例表:
过程:
测试:
This code can't possibly return error you specified because
USER
because it is a keyword, reserved for currently logged user)Therefore, it is impossible to help you with error you stated. Otherwise, consider NOT naming procedure's parameters the same as column names because that leads to various problems.
Something like this would work, but it is not related to error you got.
Sample table:
Procedure:
Testing: