Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a firebird SP, SELECT * FROM "TABLE"?

I'm migrating from SQL Server to Firebird.

In SQL Server

CREATE PROCEDURE Departments_GetAll
AS
    SELECT * FROM Departments

I try in Firebird

CREATE PROCEDURE DEPARTMENTS_DELETEALL
AS 
BEGIN
  SELECT * FROM "Departments";
END^

SET TERM ; ^

But that doesn't work.

It returns an error "SQL Code -104"

like image 369
zeqk Avatar asked Nov 23 '09 13:11

zeqk


People also ask

How do I create a SP query for select?

Right click on stored procedure in the Object Explorer and select Refresh. You will see the SP is created. Now, Right click on SP name and select Execute stored procedure…. Provide the input values and execute.

Can we use SP in select query?

We can not directly use stored procedures in a SELECT statement.

How do I select SP in SQL?

Expand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.


1 Answers

A stored procedure needs return parameters and the suspend command in order to return multiple rows.

CREATE PROCEDURE DEPARTMENTS_GET_ALL
returns(id integer, name varchar(100))
AS 
BEGIN
  FOR SELECT id, name
  FROM "Departments"
  into :id, :name do
  BEGIN
    SUSPEND;
  END
END^

SET TERM ; ^
like image 170
Douglas Tosi Avatar answered Nov 12 '22 09:11

Douglas Tosi