一般问题:如何将表名作为参数传递给Oracle APEX中的过程?例如,假设我想运行以下SQL语句:
SELECT SOME_VALUE FROM A_TABLE
执行此操作的最简单,最愚蠢的代码是什么?我是SQL初学者,基本上只看了PL / SQL。
更详细地说,我从高级教程中有以下过程允许我从自定义表中下载BLOB,但是指定要从中下载的表的代码位是硬编码的。我不必为每个要存储BLOB的表创建一个新过程。
CREATE OR REPLACE PROCEDURE download_my_file(p_file in number) AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000);
Lob_loc BLOB;
BEGIN
SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
INTO v_mime,lob_loc,v_file_name,v_length
FROM oehr_file_subject
WHERE id = p_file;
--
-- set up HTTP header
--
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );
end download_my_file;
谢谢!
答案 0 :(得分:0)
将动态SQL与execute immediate一起使用,它接受查询作为参数。所以,在你愚蠢的例子中,它将是:
使用l_column;
从'|| p_tablename执行立即'select acolumn
此处的详细信息和示例: http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm