Firebird:使用全局变量
我想为firebird的sql代码中使用的变量分配一个值. MySQL代码将是:
I would like to assign a value to a variable which is used in an sql code in firebird. The MySQL-Code would be:
SET @x = 1;
SELECT @x;
对应的Firebird代码是什么?
What is the correspondent Firebird-Code?
感谢您的帮助.
要在Firebird中定义用户定义的特定于会话的变量,您可以使用
To define a user-defined session-specific variable in Firebird you can use rdb$set_context.
与您的MySql示例相对应的Firbird代码为:
The correspondent Firbird-code for your MySql-example would be:
select rdb$set_context('USER_SESSION', 'x', 1) from rdb$database
select rdb$get_context('USER_SESSION', 'x') from rdb$database
注释:
1.)请注意,变量名称区分大小写.
1.) Be aware that variable names are case-sensitive.
2.)内部变量值是使用数据类型存储的 VARCHAR(255)
并因此强制转换为VARCHAR(255)
!!
2.) Internally variable values are stored with datatype VARCHAR(255)
and thus casted to VARCHAR(255)
!!
3.)变量的最大数量为1000.
3.) The maximum number of variables is 1000.
4.)您无需参考rdb$database
:
select rdb$get_context('USER_SESSION', 'x') from some_table_name
也可以.