sql - 将连接表的值传递给函数参数
问题描述
我想知道是否有一种方法可以使用informix(IDS 12.xx)将参数传递给从连接表值中获取的函数
让我用代码解释一下这种情况:
-- we have 2 tables with some values
create table tab1 (
c1 int,
c2 varchar(10)
);
insert into tab1 values ( 1, 'one' );
insert into tab1 values ( 2, 'two' );
create table tab2 (
c1 int,
c2 varchar(10)
);
insert into tab2 values ( 1, 'one' );
insert into tab2 values ( 2, 'also two' );
然后我们有一个带有 1 个参数的函数
create function myfunc( myarg int )
returning varchar(10);
define ret1 varchar(10);
foreach cur for
select c2 into ret1
from tab2 where c1 <= myarg
return ret1 with resume;
end foreach;
end function;
现在,让我们运行一些查询:
-- we can build this function into a select statment:
select * from table( function myfunc( 3 ) ) as myfunctab2( c2 );
-- we can also join tab1 into this select statment
select * from tab1
join table( function myfunc( 2 ) ) as myfunctab2( c2 ) on myfunctab2.c2 = tab1.c2;
-- but trying to add a column from the joined table as an argument fails
select * from tab1
join table( function myfunc( tab1.c1 ) ) as myfunctab2( c2 ) on myfunctab2.c2 = tab1.c2;
我怎么知道myfunc
从 中获取它的参数值tab1.c1
?
我知道该示例只需将函数参数替换为附加返回值,然后将其添加到ON...
查询部分即可,但因为这只是一个简化示例,所以它不是我的选择。
任何帮助将不胜感激,
谢谢
解决方案
推荐阅读
- python-3.x - Django查询以连接来自两个模型的数据,没有主键或外键
- python - 如何在特定行上执行 if 和语句,如果为 true 以在 Python 中向我的手机发送包含行内容的消息?
- pandas - 数据集中的关系(python、pandas)
- python - 如何使 QPixmap 的大小取决于 QFrame/QLabel 的大小
- python - 如何定义“@client.command”?
- python - 将空度量值写入 AWS Timestream
- javascript - 为什么从此异步函数中删除 console.log 调用会导致它上传黑色图像?
- c++ - 如何重写我的 makefile 以便我可以重构我的项目的目录?
- python - Python String 将最接近的值替换为搜索值
- mysql - MYSQL 的读提交隔离会返回哪个版本的记录