简体   繁体   English

Sybase-用户定义的函数

[英]Sybase -User Defined Functions

I have 2 user defined functions which return a table: Lets say them UDF1 and UDF2 我有2个用户定义的函数,它们返回一个表:可以说它们是UDF1和UDF2

select * from UDF1(param1) -> returns 1 result select * from UDF1(param1) ->返回1个结果

select * from UDF2(param2) -> returns 1 result select * from UDF2(param2) ->返回1个结果

The problem is when i do 问题是我什么时候做

select * from UDF1(param1) union all select * from UDF2(param2) -returns only 1 result. select * from UDF1(param1) union all select * from UDF2(param2) -仅返回1个结果。

Ideally it should return 2 results as its a union all. 理想情况下,它应返回2结果作为其所有并集。

Can someone help me why this behaviour is observed in sybase? 有人可以帮助我为什么在sybase中观察到此行为吗?

The exact code is as follows: Created function as below: 确切的代码如下:创建的函数如下:

EXEC SQL. 
CREATE FUNCTION "ZCHECK_4" ( 
  @COL3_VAL smallint 
) 
RETURNS TABLE ( 
  "COL1" varchar(000030), 
  "COL2" varchar(000030), 
  "COL3" smallint 
) AS RETURN SELECT 
  "ZTESTFUNC"."COL1", 
  "ZTESTFUNC"."COL2", 
  "ZTESTFUNC"."COL3" 
FROM "ZTESTFUNC" "ZTESTFUNC" 
WHERE "ZTESTFUNC"."COL3" = @COL3_VAL 
ENDEXEC.

Final Sql view ->Which is returing only 1 row 最终的SQL视图->仅重现1行

CREATE VIEW "ZCHECK_5" AS SELECT 
  "ZCHECK_4"."COL1", 
  "ZCHECK_4"."COL2", 
  "ZCHECK_4"."COL3" 
FROM "ZCHECK_4"( 
  CAST( 
    20 AS TINYINT
  ) 
) "ZCHECK_4" 
UNION ALL SELECT 
  "ZCHECK_4"."COL1", 
  "ZCHECK_4"."COL2", 
  "ZCHECK_4"."COL3" 
FROM "ZCHECK_4"( 
  CAST( 
    10 AS TINYINT
  ) 
) "ZCHECK_4"

Note : the underlying table(ZTESTFUNC) has 2 records which I cross validated. 注意:基础表(ZTESTFUNC)有2条记录,我已对其进行交叉验证。

Apparently for a UDF(User Defined Function) ,syntax after a select statement of a function would be ignored by the Sybase compiler. 显然,对于UDF(用户定义函数),Sybase编译器将忽略函数的select语句后的语法。

Consider the below sceanrio: 考虑下面的sceanrio:

Select F1 UNION ALL F2 . 选择F1 UNION ALL F2 F1 and F2 being UDF with parameters, the highlighted text wouldn't be compiled in Sybase. F1和F2是带有参数的UDF,突出显示的文本不会在Sybase中编译。 It might be a limitation of Sybase. 这可能是Sybase的局限性。

Note :This is not a case with tables or views where Union all works perfectly fine. 注意:在表或视图中,Union都可以正常工作的情况并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM