0

I need a stored procedure in firebird 3.0 to return True, False or 1,0 result to check if this person or the record exists in database. If exists the procedure should return true, if not return False, or return 1, if not return 0

This is my procedure but it gives me an error: https://i.ibb.co/HLZQY59/Capture.jpg

Invalid token.
Dynamic SQL Error.
SQL error code = -104
Token unknown - line 10, column 1.
end.

I want to check if the record is exist or not by checking the first name last name and day of birth.

create procedure aa(
v varchar(20),
g varchar(20),
dd date)
as 
begin
select fname,lname,bday from STUDENT
where not exists (select fname,lname,bday from STUDENT  where fname=:v and lname=:g and bday=:dd)
end
8
  • Also, explain exactly what you are trying to achieve (eg under what conditions should it return true?), because besides its obvious syntax errors, this procedure doesn't attempt in any way to return a boolean value, so it is not really obvious how to fix this procedure beyond fixing the syntax errors. Commented Aug 16, 2020 at 7:21
  • I want to check if this record is exist or not check it with the first naame LastName Day of birth
    – Sahat
    Commented Aug 16, 2020 at 13:06
  • And the error you get? And please add details in an edit to your question. Don't add them in the comments. Commented Aug 16, 2020 at 13:12
  • i edited my question post the database do not save my procedure what i i want is check if this person or the record exist in database
    – Sahat
    Commented Aug 16, 2020 at 20:44
  • Do you have programming experience in classic imperative languages (C, Java, Pascal, Basic) ? Problem is, your code does not have a specific error, it just has no sense... Like few random commands copy-pasted from random places without understanding how and why they even do work. You may read the Procedural SQL chapter of the docs - but it assumes you have a basic understanding of imperative languages programming and it adapts your generic skills to PSQL specifics, but if you don't have those it will not help you. Commented Aug 17, 2020 at 0:27

1 Answer 1

1

Your stored procedure doesn't work because 1) it doesn't have a RETURNS clause so it cannot return true or false, and 2) a select in PSQL requires an INTO clause to put the values into a variable or return-parameter.

Based on your code, a stored procedure that does what you want would be:

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

Depending on what you're need to achieve, a function might be more appropriate:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.