![](/img/trans.png)
[英]How can you tell if a PL/SQL Package, Procedure, or Function is being used?
[英]How can a PL/SQL procedure tell if it is being run from a concurrent program?
我想編寫一個過程,當從並發程序運行時將輸出記錄到 Oracle 並發管理器日志,但在“獨立”運行時寫入 dbms_output。
PL/SQL 有沒有辦法檢查我的代碼是否正在從並發請求中運行? 我能找到的最好方法是
select * from fnd_concurrent_requests
where oracle_session_id = userenv('SESSIONID');
但這很慢。 是否有我可以查詢的函數或表可以更有效地為我提供信息?
向過程添加一個布爾標志參數,您可以使用該參數告訴它在調用過程時要登錄到的位置,然后從兩個不同的(並發/非並發)程序傳遞不同的標志:
CREATE PROCEDURE my_proc(
i_value1 IN NUMBER,
i_use_concurrent_logging IN BOOLEAN DEFAULT FALSE
)
IS
-- Helper function so you only check the flag in one place.
PROCEDURE log(value IN VARCHAR2)
IS
BEGIN
IF i_use_concurrent_logging THEN
-- put your concurrent logging code here.
NULL;
ELSE
DBMS_OUTPUT.PUT_LINE(value);
END IF;
END;
BEGIN
-- Do stuff.
log('Stuff done');
-- Do other stuff
log('Other Stuff done');
END;
/
如果您想在程序中使用一次支票,則可以使用:
CREATE OR REPLACE PROCEDURE my_proc(
i_value1 IN NUMBER
)
IS
v_use_concurrent_logging BOOLEAN := FALSE;
PROCEDURE log(value IN VARCHAR2)
IS
BEGIN
IF v_use_concurrent_logging THEN
-- put your concurrent logging code here.
NULL;
ELSE
DBMS_OUTPUT.PUT_LINE(value);
END IF;
END;
BEGIN
DECLARE
v_exists INT;
BEGIN
SELECT 1
INTO v_exists
FROM fnd_concurrent_requests
WHERE oracle_session_id = userenv('SESSIONID')
AND ROWNUM = 1;
v_use_concurrent_logging := TRUE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_use_concurrent_logging := FALSE;
END;
-- Do stuff.
log('Stuff done');
-- Do other stuff
log('Other Stuff done');
END;
/
db<> 在這里擺弄
您可以像我們在閃電戰報告代碼中那樣最好地使用 fnd_global.conc_request_id:
procedure write_log(p_text in varchar2, p_log_level in number default 1) is
begin
if fnd_global.conc_request_id>0 then
fnd_file.put_line(fnd_file.log,p_text);
else
fnd_log.string(p_log_level,'XXEN',p_text); --or your dbms_output.put_line() call
end if;
end write_log;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.