我想在脚本内创建数据库链接,并希望从链接数据库中接收所有表名。如果我是正确的,我需要创建数据库链接才能使用,但 Oracle 不允许我在my_fn或DECLARE部分内创建这样的东西。有什么建议吗?
DECLARE
TYPE tp_col_array IS TABLE OF varchar2(1000);
FUNCTION my_fn(
p_in_dblink_name IN VARCHAR2,
p_in_schema_name IN VARCHAR2)
RETURN varchar2 AS
vr_coll_table tp_col_array;
vr_coll_owner tp_col_array;
BEGIN
create database link "database1"
connect to my_name
identified by "my_password"
using 'database1';
SELECT owner, table_name
bulk collect into vr_coll_owner, vr_coll_table
FROM all_tables@database1
WHERE OWNER NOT IN ('SYS');
RETURN TO_CHAR(vr_coll_owner(1)); //just for temporary
END my_fn;
BEGIN
DBMS_OUTPUT.PUT_LINE(my_fn('link1','schema1'));
END;
编辑 我也尝试了以下,但没有运气:(
Execute immediate q'[create database link "database1"
connect to my_name
identified by "my_password"
using 'database1']';