Oracle PL/SQL:在另一个过程中执行过程
我正在另一个过程中执行一个过程 程序1:Oracle PL/SQL:在另一个过程中执行过程,oracle,unit-testing,stored-procedures,plsql,procedure,Oracle,Unit Testing,Stored Procedures,Plsql,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_stat
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;
它不会将消息和描述存储在测试状态表表中,但当我打印它们时,它会显示出来
我做错什么了吗?你缺少陈述
直接路径插入后:在提交插入之前无法读取表
在过程结束时添加提交以查看插入的记录您可能只需要提交过程中记录的消息 日志记录是自治事务有效的少数情况之一:通常我们希望在不干扰正在记录的事务的情况下记录消息 此外,这里不需要使用动态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;
/
在这里,自主交易的价值是什么?OP似乎正在构建一个测试框架。通过自主事务,我们可以持久化日志消息,而不会影响更广泛的事务,即测试。在没有自治事务pragma的情况下提交日志消息可能会产生副作用,这可能会破坏其他测试(如ORA-01022、ORA-1555),或者只会使拆卸更加复杂 您忘记提交了。如果要将每个insert语句存储到表中,则在每个insert语句之后必须有commit。您已经得到了答案(由user7294900发布)。然而,为什么在proc\u test\u status\u table过程中使用动态SQL?这里面没有什么动态。@successhrestha-当然你有权选择你接受的答案。但我认为你应该解释为什么你不接受我的答案,而只接受我答案的一部分。