How to set context variable from database

只愿长相守 提交于 2019-12-11 16:27:38

问题


I'm trying to set a context variable from a row in a oracle database. I have the table in the database already set up like so:

key     | variable
name    | BigDecimal

I also have created a BigDecimal context variable. How do I link the context variable to the database so it can be used in a SQL query?


回答1:


If you have a table with schema (variable_name, variable_value) and each row id dedicated to a single job, then I recommand you to add a third column so it will be (variable_name, variable_value, job_name), then with simple single query you will get the row of the current job:

select variable_name, variable_value from context_table where job_name = '"+jobName+"';
--jobName is varibale global exists in each Talend by defaults

If your table is not modeled to serve context, but you need a specefic value from that table to be loaded into context, you have to execute the query using TOracleRow and pass the result to tJavaRow that have the code below:

context.myVariable = input_row.myColumn

If you want to use that context variable in other queries, your query will be like this:

"select a, b, c from table1 where a = '"+context.myVariable+"'"


来源:https://stackoverflow.com/questions/31384867/how-to-set-context-variable-from-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!