Documente Academic
Documente Profesional
Documente Cultură
htm
Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.
www.destructor.de
Advantages
Parts of code only implemented once: client applications get smaller and less complicated to implement and
mantain.
Easier Maintenance: Client applications don't need to be recompiled and redistributed
Increased performance because of reduced network traffic
(In and Out parameters of a Stored Procedure are used like variables)
SET TERM
Every command in a script must be terminated by a semi-colon, the procedure itself, too. To distinguish the
semi-colons in the procedure from the terminating semi-colon, there must be another terminator for the end of the
procedure. This is done with SET TERM:
SET TERM !! ;
CREATE PROCEDURE x AS BEGIN ... END !!
SET TERM ; !!
The first "SET TERM" replaces the terminator semi-colon with the terminator double-exclamation. The procedure
declaration contains the usual semi-colons after each command. The procedure itself is terminated by the "new"
terminator !!. After that, the terminator symbol is set back to a semi-colon.
1 av 3 06.08.10 16:59
Firebird Stored Procedures http://www.destructor.de/firebird/storedproc.htm
Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.
Alter: ALTER PROCEDURE name ... (the rest is like CREATE PROCEDURE)
Create or Alter, depending on existance of proceudure: CREATE OR ALTER ...
Drop: DROP PROCEDURE name. Can only be done by the owner of the procedure.
You can only drop procedures, which are not used by other procedures, triggers or views.
Exceptions
Create: CREATE EXCEPTION name “message“
Alter: ALTER EXCEPTION name “message“
Drop: DROP EXCEPTION name
Examples
/* --- Returning a single value –----------------------------------- */
CREATE PROCEDURE Mul (a INTEGER, b INTEGER)
RETURNS (Result INTEGER)
AS BEGIN
Result = a * b;
END
Commands
Command Description Version
BEGIN <statements> END Compound Statement like in PASCAL
variable = expression Assignment. "variable" can be a local variable, an
"in" or an "out" parameter.
compound_statement A single command or a BEGIN/END block
select_statement Normal SELECT statement. The INTO clause must
be present at the end of the statement. Variable
names can be used with a colon preceding them.
Example
SELECT PRICE FROM ARTICLES
WHERE ARTNO = :ArticleNo
INTO :EPrice
/* Comment */ Comment, like in C
-- Comment Single line SQL comment 1.5.0
DECLARE VARIABLE name datatype [= startval] Variable declaration. After AS, before the first 1.5.0
BEGIN. (startval)
EXCEPTION Re-fire the current exception. Only makes sense in 1.5.0
WHEN clause
EXCEPTION name [message] Fire the specified exception. Can be handled with 1.5.0
WHEN. (message)
EXECUTE PROCEDURE name arg, arg Calling a procedure. arg's must be local variables.
RETURNING_VALUES arg, arg Nesting and recursion allowed.
2 av 3 06.08.10 16:59
Firebird Stored Procedures http://www.destructor.de/firebird/storedproc.htm
Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only.
EXIT Leaves the procedure (like in PASCAL)
FOR select_statement DO Executes "compound_statement" for every line that
compound_statement is returned by the SELECT statement
IF (condition) IF statement, like in PASCAL
THEN compound_statement
[ELSE compound_statement]
This documentation is licensed under (choose your favorite): GPL, LGPL, CC, IDPL, GFDL, BSD, (did I forget one?)
3 av 3 06.08.10 16:59