微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql – Azure数据仓库中的表变量

sql Server数据库中,可以使用如下表变量:
declare @table as table (a int)

在Azure数据仓库中,会引发错误.

Parse error at line: 1,column: 19: Incorrect Syntax near ‘table’

在Azure数据仓库中,您可以使用临时表:

create table #table (a int)

但不是内部功能.

Msg 2772,Level 16,State 1,Line 6 Cannot access temporary tables
from within a function.

来自微软的This document说,

◦Must be declared in two steps (rather than inline): ◾CREATE TYPE
my_type AS TABLE …;,then ◾DECLARE @mytablevariable my_type;.

但是当我尝试这个时:

create type t as table (a int);
drop type t;

我明白了:

Msg 103010,Line 1 Parse error at line: 1,column:
8: Incorrect Syntax near ‘type’.

我的目标是在Azure数据仓库中使用一个使用临时表的函数.它可以实现吗?

编辑从这里开始

请注意,我不是在寻找其他方法来创建一个特定的功能.我实际上已经这样做了并继续前进.我是一名资深程序员,但是Azure数据仓库的新手.我想知道是否可以在Azure数据仓库功能中加入一些临时表的概念.

解决方法

不,你不能.无法在用户定义函数(UDF)中创建对象.请改用表变量.

如果您希望使用用户定义的类型,请首先在UDF外部创建它,并将其用作UDF中的变量类型.

-- Create the data type
CREATE TYPE TestType AS TABLE 
(
    Id INT NOT NULL,Col1 VARCHAR(20) NOT NULL)
GO

-- Create the tabled valued function
CREATE FUNCTION TestFunction
()
RETURNS 
@Results TABLE 
    (Result1 INT,Result2 INT)
AS
BEGIN
    -- Fill the table variable with the rows for your result set
    DECLARE @Var1 TestType;

    RETURN 
END
GO

原文地址:https://www.jb51.cc/mssql/76683.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐