微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

过程返回True或False

如何解决过程返回True或False

我需要在firebird 3.0中使用存储过程来返回True,False或1,0结果 检查此人或记录是否存在于数据库中。如果存在,则过程应返回true,如果不返回False,则返回1,如果不返回0,则返回

这是我的过程,但给我一个错误

https://i.ibb.co/HLZQY59/Capture.jpg

无效的令牌。
动态sql错误
sql错误代码= -104
令牌未知-第10行,第1列。
结束。

我想通过检查名字,姓氏和出生日期来检查记录是否存在。

create procedure aa(
v varchar(20),g varchar(20),dd date)
as 
begin
select fname,lname,bday from STUDENT
where not exists (select fname,bday from STUDENT  where fname=:v and lname=:g and bday=:dd)
end

解决方法

您的存储过程不起作用,因为1)它没有RETURNS clause,因此它不能返回true或false,以及2)在PSQL中进行选择需要使用INTO clause来放置值放入变量或返回参数。

根据您的代码,可以完成您想要的存储过程:

create procedure aa(
  v varchar(20),g varchar(20),dd date)
  returns (student_exists boolean)
as 
begin
  student_exists = exists (select * from STUDENT where fname=:v and lname=:g and bday=:dd);
end

根据您需要实现的目标,function可能更合适:

create procedure aa(
  v varchar(20),dd date)
  returns boolean
as 
begin
  return exists (select * from STUDENT where fname=:v and lname=:g and bday=:dd);
end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。