gpt4 book ai didi

sql-server - 不带 [dbo] 的用户标量值函数。部分

转载 作者:行者123 更新时间:2023-12-03 08:58:36 32 4
gpt4 key购买 nike

我正在开发一个使用多种类型数据库(Postgresql、Sql Server、Oracle)的报告工具(基于 JasperReports)。所有平台共享一个公共(public) Jasper 域,其中一些域需要公共(public)脚本化 sql select 查询(例如 select blah from table xxx ..)

在一个特定的脚本中,我需要引用在所有平台上创建的用户函数。

问题是,对于脚本,我可以将此函数引用为

select my_func(col1, col2) from some_table 

在 PostgreSQL 和 Oracle 安装上。但同一查询无法在 SQL Server 上运行,因为出现 get 'my_func 不是可识别的内置函数名称。' 错误消息。为了使其工作,我必须使用 dbo. 来限定该函数,即

select dbo.my_func(col1, col2) from some_table

但是这当然不适用于 Oracle 和 Postgresql。

所以我的问题是,无论如何在 SQL Server 上创建这个函数,以便能够调用它,而不必使用 dbo. 部分对其进行限定。

最佳答案

我认为 SQL Server 不可能。

Scalar-valued functions can be invoked where scalar expressions are used. This includes computed columns and CHECK constraint definitions. Scalar-valued functions can also be executed by using the EXECUTE statement. Scalar-valued functions must be invoked by using at least the two-part name of the function. For more information about multipart names, see Transact-SQL Syntax Conventions (Transact-SQL). Table-valued functions can be invoked where table expressions are allowed in the FROM clause of SELECT, INSERT, UPDATE, or DELETE statements. For more information, see Execute User-defined Functions.

已添加强调

参见:

您可以省略架构,并引用数据库名称:

[database]..[object]

关于sql-server - 不带 [dbo] 的用户标量值函数。部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52953159/

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