KETTLE设置变量
一、kettle变量类型
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921171-2146193743.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921499-158645048.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921765-1147750045.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000922296-706516781.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000922515-2016653878.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923030-1892039971.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923265-1938121044.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923640-908002722.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000924171-929331723.png)
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000924905-1146954978.png)
kettle变量分为:
1.环境变量
通过 set variables组件设置变量,范围可以是:JVM变量、作业变量、父作业变量、根作业变量。使用时通过${var}或 %%var%%变量方式引用变量
2.属性文件变量
在.kettle目录下的kettle.property文件中设置,可kettle中可以引用
3.命令行参数(相当于位置参数)
命令行参数是指用pan执行转换时传入的参数,在sql中用可以用?占位,也叫位置参数
注意:
不管哪种参数都可以在sql中用${var}或者%%var%%表示
二、设置变量
1.设置环境变量
job:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921171-2146193743.png)
编辑设置变量组件:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921499-158645048.png)
转换:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000921765-1147750045.png)
表输入:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000922296-706516781.png)
2.设置属性文件变量
编辑C:\Users\用户名\.kettle目录下的kettle.properties文件,写入:
customerNumber=124
然后重启spoon(kettle)
转换:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000922515-2016653878.png)
表输入:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923030-1892039971.png)
3.设置命令行参数变量
转换:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923265-1938121044.png)
获取系统信息:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000923640-908002722.png)
表输入:
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000924171-929331723.png)
三、变量作用范围
要注意一点:如果用转换封装变量,选择valid in the root job,则在job中无法使用这些变量。如果改成在JVM中生效则可以使用。
![](https://images2017.cnblogs.com/blog/645664/201708/645664-20170831000924905-1146954978.png)