gpt4 book ai didi

stored-procedures - 有什么办法可以在Firebird存储的proc内创建本地表变量?

转载 作者:行者123 更新时间:2023-12-04 08:59:06 25 4
gpt4 key购买 nike

在MS SQL Server中,可以声明任何原始类型或表类型的局部变量。该表是一个普通表,您可以像其他表一样在其上运行SELECTINSERTUPDATEDELETE,只是它是一个局部变量,而不是数据库本身的一部分。

我正在尝试在Firebird中执行相同的操作,但是它似乎不喜欢该语法。

declare variable value int; --works fine
declare variable values table (value int); --Error: "Token unknown (table)"

有什么办法吗? (并且在任何人说“使用可选的存储过程”之前,这是行不通的。我需要可以动态运行 INSERTSELECT的东西。)

最佳答案

Firebird不像SQL Server那样支持表变量。

您可以使用的最接近的东西是Global Temporary Tables(需要Firebird 2.1或更高版本)

(v.2.1) Global temporary tables (GTTs) are tables that are stored in the system catalogue with permanent metadata, but with temporary data. Data from different connections (or transactions, depending on the scope) are isolated from each other, but the metadata of the GTT are shared among all connections and transactions.

There are two kinds of GTT:

with data that persists for the lifetime of connection in which the specified GTT was referenced; and

with data that persists only for the lifetime of the referencing transaction.



您必须事先创建GTT。
CREATE GLOBAL TEMPORARY TABLE
...
[ON COMMIT <DELETE | PRESERVE> ROWS]

关于stored-procedures - 有什么办法可以在Firebird存储的proc内创建本地表变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13789607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com