【问题标题】:sybase user defined function - "non deterministic" or "illegal built-in function" errorsybase 用户定义函数 - “非确定性”或“非法内置函数”错误
【发布时间】:2010-01-08 17:32:15
【问题描述】:

尝试在 sybase 15+ 上创建用户定义函数 (UDF) 时,您可能会收到以下错误: “标量 SQL 函数中的非法内置函数语句” 这是 b/c “非确定性”函数,例如 getdate()、rand()、newid(),在 UDF 中是不允许的。

有没有办法绕过这个限制?

请注意,我计划在这里回答我自己的问题。

【问题讨论】:

    标签: function sybase user-defined-functions


    【解决方案1】:

    解决办法是创建一个视图如:

    create view vGetDate as select getdate() as gtdt
    

    然后在 UDF 中从该视图中选择:

    create function udf_getdate
    returns datetime
    as
    declare @gd datetime
    select @gd=gtdt from vGetDate
    return @gd
    go
    

    现在调用函数:

    select dbo.udf_getdate()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 2010-10-17
      • 2013-05-26
      相关资源
      最近更新 更多