PL/SQL: 在另一个程序中执行程序
PL/SQL: Execute procedure in another procedure
我正在另一个过程中执行一个过程。
程序 1:
CREATE OR REPLACE PROCEDURE proc_test_status_table(
p_test_description IN VARCHAR2,
p_test_status IN varchar2)
AS
l_sql VARCHAR2(4000);
BEGIN
l_sql := 'insert into test_status_table(test_description, test_status)
values
( '''||p_test_description||''',
'''||p_test_status||''')';
EXECUTE IMMEDIATE (l_sql);
END;
/
程序 2:
overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test) as
l_message varchar2(4000);
l_test_description VARCHAR2(1000);
l_test_status VARCHAR2(100);
begin
l_message := coalesce(a_test.description, a_test.name)||' ['||round(a_test.execution_time,3)||' sec]';
Dbms_Output.Put_Line(a_test.result||'test_result');
--if test failed, then add it to the failures list, print failure with number
if a_test.result = ut_utils.gc_disabled then
self.print_yellow_text(l_message || ' (DISABLED)');
l_test_description := 'DISABLED';
proc_test_status_table(l_message, l_test_description);
elsif a_test.result = ut_utils.gc_success then
self.print_green_text(l_message);
l_test_description := 'PASS';
proc_test_status_table(l_message, l_test_description);
elsif a_test.result > ut_utils.gc_success then
failed_test_running_count := failed_test_running_count + 1;
self.print_red_text(l_message || ' (FAILED - ' || failed_test_running_count || ')');
l_test_description := 'FAIL';
proc_test_status_table(l_message, l_test_description);
end if;
-- reproduce the output from before/after procedures and the test
self.print_clob(a_test.get_serveroutputs);
end;
它不会在 test_status_table table 中存储消息和描述,但是当我打印它们时它会显示出来。
我是不是做错了什么?
您缺少 commit; 声明
After direct path insert: the table cannot be read until the insert is committed.
在程序末尾添加提交以查看插入的记录
可能您只需要在过程中提交记录的消息。
日志记录是自主事务有效的少数情况之一:通常我们希望在不干扰我们正在记录的事务的情况下记录我们的消息。
此外,您不需要在此处使用动态 SQL。只需引用 VALUES 子句中的参数即可。
CREATE OR REPLACE PROCEDURE proc_test_status_table(
p_test_description IN VARCHAR2,
p_test_status IN varchar2)
AS
l_sql VARCHAR2(4000);
PRAGMA autonomous_transaction;
BEGIN
insert into test_status_table(test_description, test_status)
values ( p_test_description, p_test_status);
commit;
END;
/
这里AUTONOMOUS_TRANSACTION的值是多少? OP 似乎正在构建一个测试框架。使用自治事务,我们可以在不影响更广泛的事务(即测试)的情况下保留日志消息。在没有 AUTONOMOUS_TRANSACTION pragma 的情况下提交日志消息可能会产生副作用,这可能会破坏其他测试(例如 ORA-01022、ORA-1555)或者只会使拆卸更加复杂。
您忘记提交了。如果要将每个插入语句存储到 table.
中,则必须在每个插入语句之后提交
我正在另一个过程中执行一个过程。
程序 1:
CREATE OR REPLACE PROCEDURE proc_test_status_table(
p_test_description IN VARCHAR2,
p_test_status IN varchar2)
AS
l_sql VARCHAR2(4000);
BEGIN
l_sql := 'insert into test_status_table(test_description, test_status)
values
( '''||p_test_description||''',
'''||p_test_status||''')';
EXECUTE IMMEDIATE (l_sql);
END;
/
程序 2:
overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test) as
l_message varchar2(4000);
l_test_description VARCHAR2(1000);
l_test_status VARCHAR2(100);
begin
l_message := coalesce(a_test.description, a_test.name)||' ['||round(a_test.execution_time,3)||' sec]';
Dbms_Output.Put_Line(a_test.result||'test_result');
--if test failed, then add it to the failures list, print failure with number
if a_test.result = ut_utils.gc_disabled then
self.print_yellow_text(l_message || ' (DISABLED)');
l_test_description := 'DISABLED';
proc_test_status_table(l_message, l_test_description);
elsif a_test.result = ut_utils.gc_success then
self.print_green_text(l_message);
l_test_description := 'PASS';
proc_test_status_table(l_message, l_test_description);
elsif a_test.result > ut_utils.gc_success then
failed_test_running_count := failed_test_running_count + 1;
self.print_red_text(l_message || ' (FAILED - ' || failed_test_running_count || ')');
l_test_description := 'FAIL';
proc_test_status_table(l_message, l_test_description);
end if;
-- reproduce the output from before/after procedures and the test
self.print_clob(a_test.get_serveroutputs);
end;
它不会在 test_status_table table 中存储消息和描述,但是当我打印它们时它会显示出来。
我是不是做错了什么?
您缺少 commit; 声明
After direct path insert: the table cannot be read until the insert is committed.
在程序末尾添加提交以查看插入的记录
可能您只需要在过程中提交记录的消息。
日志记录是自主事务有效的少数情况之一:通常我们希望在不干扰我们正在记录的事务的情况下记录我们的消息。
此外,您不需要在此处使用动态 SQL。只需引用 VALUES 子句中的参数即可。
CREATE OR REPLACE PROCEDURE proc_test_status_table(
p_test_description IN VARCHAR2,
p_test_status IN varchar2)
AS
l_sql VARCHAR2(4000);
PRAGMA autonomous_transaction;
BEGIN
insert into test_status_table(test_description, test_status)
values ( p_test_description, p_test_status);
commit;
END;
/
这里AUTONOMOUS_TRANSACTION的值是多少? OP 似乎正在构建一个测试框架。使用自治事务,我们可以在不影响更广泛的事务(即测试)的情况下保留日志消息。在没有 AUTONOMOUS_TRANSACTION pragma 的情况下提交日志消息可能会产生副作用,这可能会破坏其他测试(例如 ORA-01022、ORA-1555)或者只会使拆卸更加复杂。
您忘记提交了。如果要将每个插入语句存储到 table.
中,则必须在每个插入语句之后提交