When should the colon (:) character be used in procedure or trigger code?

The colon character should only be used to prefix variables in SQL statements. It is not needed to use it for simple assignments, and sometimes even not desirable. It is never used for 'new.' and 'old.' values in triggers as 'new' and 'old' are relations valid in both SQL and PSQL expression evaluation. Example:

create procedure p1 ( x integer )
declare variable y integer;
select emp_id from employee where emd_id = :x into :y;
if (y > 20) then y = x * 12;
update t1 set my_num = :y where id = :x;

Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.

All contents are copyright © 2007-2023 FirebirdFAQ.org unless otherwise stated in the text.

Links   Firebird   News   FlameRobin   Powered by FB: Home Inventory   Euchre  
Add content   About  

 Installation and setup
 Backup and restore
 Connectivity and API
 Errors and error codes