我想从远程数据库中的表中选择数据,我在变量中有数据库链接,我该怎么做?
我的查询是这样的:
select `table_column` form any_table@:any_variable_1 where any_column= :any_variable_2;
注意: any_variable_1是一个字符串变量,包含数据库链接的名称 any_variable_2是一个字符串变量,包含用于过滤的字符串 *此代码将在powerbuilder 8或9中执行 *我连接的数据库是oracle 11 g
答案 0 :(得分:0)
试试这个:
DECLARE
l_var number(10); -- data type you are expecting from the table_column column
l_cursor sys_refcursor;
l_any_variable_1 varchar2(50) := 'YOUR_DBLINK_HERE';
l_any_variable_2 varchar2(50);
BEIGN
open l_cursor for 'select table_column from any_table@ '||
l_any_variable_1 ||
' where any_column = :any_variable_2'
using l_any_variable_2;
loop
fetch l_cursor into l_var;
exit when l_cursor%NOTFOUND;
DBMS_OUTPUT.put_line(l_var);
end loop;
close l_cursor;
END;
答案 1 :(得分:0)
string ls_sql
ls_sql="Select column_name from table_name@"+var_db_link_name+""+&
" where column_name='"+var_value+"' and another_column_name='"+another_var+"'"
DECLARE var_cursor DYNAMIC CURSOR FOR SQLSA ;
PREPARE SQLSA FROM :ls_sql ;
OPEN DYNAMIC var_cursor ;
FETCH var_cursor INTO :another_var ;//another_var holds the result of the cursor
CLOSE var_cursor;