我试图弄清楚如何显示用户输入的insert语句。我希望它在“请更新插入语句”文本打印后显示。通过在线阅读大量内容,我发现您可以通过输入“/”符号显示上一个在oracle上输入的命令,还可以通过运行此查询来显示'SELECT * FROM gv $ sql WHERE SQL_ID = IDENT_CURRENT('gv $ SQL ')'。我尝试使用dbms_output.put_line(/)并使用t0_char('/');在查询中,如下所示。有什么提示吗?
set serveroutput on
CREATE or REPLACE trigger before_insert_t
before insert on reservations
for each row
DECLARE
rooms_remaining number(5,2);
BEGIN
select roooms_rem into rooms_remaining from reservations where roomno=:new.roomno;
if rooms_remaining = 0 then
dbms_output.put_line('Insertion now allowed because room ' || :new.roomno || ' is booked!' );
dbms_output.put_line('Please update the insert statement');
-- to_char('/');
dbms_output.put_line('insert into reservations values ' || :new.roomno );
-- EXECUTE IMMEDIATE sql_stmt;
end if;
END;
/
show errors
insert into reservations values (99,9);
答案 0 :(得分:0)
CREATE or REPLACE trigger before_insert_t
before insert on TEST_TAB1
for each row
DECLARE
sql_insert varchar2(1000);
BEGIN
select sql_text into sql_insert
from (select sql_text
from v$sql
where upper(sql_text) like 'INSERT INTO TEST_TAB1%'
order by first_load_time desc)
where rownum=1;
dbms_output.put_line('Inserting into table SQL is '||sql_insert);
END;
/
SQL> set serveroutput on
SQL> insert into TEST_TAB1 values ('Hello');
1 rows inserted.
Inserting into table SQL is insert into TEST_TAB1 values (:"SYS_B_0")
按FIRST_LOAD_TIME
排序并按降序排序,如果有多个INSERT
,则选择第一行作为最新的INSERT
语句。