有没有办法使用**相同的**sysdate执行多个sql语句?

Ger*_*rat 1 sql oracle

我有一个执行sql语句的程序.在一个事务中,我想使用相同的 sysdate 更新几个表.例如.(在事务中运行以下3个语句)

update table1 set some_col = 'updated' where some_other_col < sysdate;
delete from table2 where some_col < sysdate;
insert into table3 (col1, col2) select c1, c2 from table4 where some_col < sysdate;
Run Code Online (Sandbox Code Playgroud)

如果在事务中执行这3个语句,则每个正在使用的"sysdate"将是当前正在运行此语句时的任何时间戳,而不是在事务开始时.

可以创建一个存储过程并最初使用PL/SQL将sysdate选择为变量,但我更喜欢从外部程序运行sql语句.

tbo*_*one 5

我可以创建一个存储过程并最初使用PL/SQL将sysdate选择为变量,但我更喜欢从外部程序运行sql语句

使用匿名块而不是存储过程,类似于(未经测试):

declare
  v_sysdate date := sysdate;
begin
  update table1 set some_col = 'updated' where some_other_col < v_sysdate;
  delete from table2 where some_col < v_sysdate;
  insert into table3 (col1, col2) select c1, c2 from table4 where some_col < v_sysdate;
  commit;
exception
  when others then 
  rollback;
  raise;
end;
Run Code Online (Sandbox Code Playgroud)