Kettle table input使用变量替换in中的条件
来源:互联网 发布:遛99遛弯淘宝区怎么样 编辑:程序博客网 时间:2024/05/21 15:55
1. 问题描述
今天在使用kettle从PostgreSQL数据库表中导出数据到文本文件时,用到了in查询,原始的sql是下面这样的:
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') as checkin_time, '${personType}' as bd_type, 'AA.AA.AA.AA' as checkin_window_ip from compare_result where from_station in ('QTP','CTH','CLP','BDP','BEP','SHD') or to_station in ('QTP','CTH','CLP','BDP','BEP','SHD')
在Kettle的table input中使用变量替换的方式传入from_station和to_station的值,一开始的写法是这样的:
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') as checkin_time, '${personType}' as bd_type, 'AA.AA.AA.AA' as checkin_window_ip from compare_result where board_station in (${fromStationCode}) or to_station in (${toStationCode})
执行后发现有语法错误,意识到变量引用应该放到单引号里面,于是,改成了下面这样:
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') as checkin_time, '${personType}' as bd_type, 'AA.AA.AA.AA' as checkin_window_ip from compare_result where board_station in ('${fromStationCode}') or to_station in ('${toStationCode}')
这样解析出来的SQL是有问题的,in里面的值最外面多了一层单引号:
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') as checkin_time, '${personType}' as bd_type, 'AA.AA.AA.AA' as checkin_window_ip from compare_result where from_station in (''QTP','CTH','CLP','BDP','BEP','SHD'') or to_station in (''QTP','CTH','CLP','BDP','BEP','SHD'')
于是,想到了各种转义,包括在table input步骤的sql中对单引号转义和对参数里面的单引号进行转义,结果都无效。
2. 解决方法
查看Kettle的使用说明,发现变量的引用方式有两种,一种是我们上面使用的${}的方式,这种方式使用的时候外面一般都要套上一层单引号;另外一种是在变量名两边都加上另个%%的方式,这种方式不需要再加单引号,于是,把我们的查询改成了下面这样的:
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') as checkin_time, '${personType}' as bd_type, 'AA.AA.AA.AA' as checkin_window_ip from compare_result where board_station in (%%fromStationCode%%) or to_station in (%%toStationCode%%)
再次执行Kettle作业,发现作业被成功执行了,问题解决。
阅读全文
0 0
- Kettle table input使用变量替换in中的条件
- Kettle中的传递变量
- kettle数据库连接使用变量
- Kettle变量使用
- shell中的条件判断、参数以及变量替换
- shell中的条件判断、参数以及变量替换
- shell中的条件判断、参数以及变量替换
- shell中的条件判断、参数以及变量替换
- 线程中的条件变量的使用
- kettle替换jar包中的class文件
- WML 中的变量替换
- shell中的变量替换
- Kettle 参数、变量和全局变量(kettle.properties)使用
- 《黑马程序员》 使用反射替换类中的变量的值
- 使用manifestPlaceholders替换变量
- 使用manifestPlaceholders替换变量
- kettle变量
- Makefile中的变量及条件判断的使用
- Android如何高效的加载图片(4)--- 图片占用内存的管理
- 返回的json(siteList)在数据库没有一条记录,siteList冒号后的值跟[]
- tensorflow下的局部响应归一化函数tf.nn.lrn
- JAVA java.sql.Date、java.util.Date与数据库中的Date字段的转换方法
- webpack 脚手架搭建
- Kettle table input使用变量替换in中的条件
- $.ajax()方法详解
- 李洋疯狂C语言之编程实现统计某年某月份的天数
- webpack模块化打包,结合react-route实现分文件打包,按需加载
- 运行、调试Web项目
- 记录Redis存储对象的问题
- 【量亿数据-股票数据】利用简单指标,建立交易系统
- CentOS 7下SSH远程登录服务器详解
- 牛客网---2016---去哪儿二分查找