根据列类型声明变量类型

发布于 2024-08-29 12:40:23 字数 165 浏览 4 评论 0原文

在 Oracle 的 PL-SQL 中,您可以声明一个变量并根据表列定义其类型:

declare var1 table.column%TYPE;

Is it possible to do some things in MS SQL Server?

In Oracle's PL-SQL, you can declare a variable and define its type based on a table column:

declare var1 table.column%TYPE;

Is it possible to do something similar in MS SQL Server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2024-09-05 12:40:23

不,你不能这样做。最接近的等效项是用户定义的数据类型。这将为您提供一个可能有帮助的抽象层,但它与从列派生类型不同。

No you can't do this. The closest equivalent is User-Defined Data Types. This will give you a layer of abstraction that may help, but it is not the same as deriving a type from a column.

堇色安年 2024-09-05 12:40:23

“欺骗”一点。

Select *
INTO #tmp
From MyTable
Where 1 = 0

它可能会回避真正的问题,但您可以通过“将自动创建一个包含具有正确数据类型的所有列的临时表”来

It may skirt the real issue, but you can "cheat" a little bit by

Select *
INTO #tmp
From MyTable
Where 1 = 0

Will automatically create a temp table with all columns with correct data types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文