Firebird:使用全局变量 [英] Firebird: Using global variable

查看:165
本文介绍了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

也可以.

这篇关于Firebird:使用全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆