Skip to content
Advertisement

Cannot create new procedure in SQL manager lite

I am working with SQL manager lite for Interbase/Firebird application. I have downloaded firebird database, successfully connected to that database and its host, but now I want to create procedure.

I couldn’t done it via tutorials, so I decided to just click New->Procedure and do that automatically. But doing this way I still have errors.

My code what I have tried without clicking New->Procedure:

CREATE PROCEDURE MyProc
AS
  SELECT M_DOKUMENTY.NDZIEN FROM M_DOKUMENTY WHERE M_DOKUMENTY.SRODZAJ = '1234'
GO;

The code which was generated using New->Procedure wizard:

CREATE PROCEDURE SHOW_ALL
AS
BEGIN
  /* Procedure body */
  SELECT 
    M_DOKUMENTY.NDZIEN,
    M_DOKUMENTY.CKIERUNEK,
    M_DOKUMENTY.CMEDIUM FROM M_DOKUMENTY WHERE M_DOKUMENTY.SRODZAJ = '1234'
  SUSPEND;
END;

But when I am clicking that lightning icon (compile) it complains about error:

Dynamic SQL Error.

SQL error code = -104.

Token unknown – line 9, column 3.

SUSPEND.

How to fix that?

Screenshot of error in SQL Manager lite

Advertisement

Answer

The problem is that your syntax is wrong. You need to define the output parameters, and you need to use either select ... into <list of variables> to select a single row, or for select ... into <list of variables> do to loop over multiple rows.

Your stored procedure should be something like:

CREATE PROCEDURE SHOW_ALL
  RETURNS (NDZIEN varchar(50), CKIERUNEK varchar(50), CMEDIUM varchar(50))
AS
BEGIN
  /* Procedure body */
  for SELECT 
        M_DOKUMENTY.NDZIEN,
        M_DOKUMENTY.CKIERUNEK,
        M_DOKUMENTY.CMEDIUM 
      FROM M_DOKUMENTY 
      WHERE M_DOKUMENTY.SRODZAJ = '1234'
      into :NDZIEN, :CKIERUNEK, :CMEDIUM 
  do
    SUSPEND;
END

If your select only produces a single row, then you could also consider using

CREATE PROCEDURE SHOW_ALL
  RETURNS (NDZIEN varchar(50), CKIERUNEK varchar(50), CMEDIUM varchar(50))
AS
BEGIN
  /* Procedure body */
  SELECT 
      M_DOKUMENTY.NDZIEN,
      M_DOKUMENTY.CKIERUNEK,
      M_DOKUMENTY.CMEDIUM 
    FROM M_DOKUMENTY 
    WHERE M_DOKUMENTY.SRODZAJ = '1234'
    into :NDZIEN, :CKIERUNEK, :CMEDIUM;
  SUSPEND;
END

Notice the ; after the into clause. In this case you could also leave out the SUSPEND;. That will make the stored procedure executable instead of selectable. Depending on how you want to use it, that could be a better choice.

See the Firebird documentation on created stored procedures and its procedural SQL language for more information.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement