如何将变量与字符串连接起来以在存储过程的 FROM 子句中创建 Oracle 表名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1234792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I concatenate variables with a string to create an Oracle table name in a FROM clause in a stored procedure?
提问by geekzspot
e.g.
例如
select *
from v_schema || '.tbl_a@' || abc.world
回答by tuinstoel
You can use dynamic sql:
您可以使用动态sql:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/dynamic.htm.
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/dynamic.htm。
To protect against sql injection you can use dbms_assert:
为了防止 sql 注入,您可以使用dbms_assert:
http://www.oracle-base.com/articles/10g/dbms_assert_10gR2.php
http://www.oracle-base.com/articles/10g/dbms_assert_10gR2.php
回答by geekzspot
-- Dynamic SQL
-- 动态 SQL
execute immediate 'select * from ' || v_schema || '[email protected]';
立即执行 'select * from ' || v_schema || '[email protected]';

