Добро пожаловать, Гость
Логин: Пароль: Запомнить меня
Администрирование Oracle Database:
- Установка и настройка базы данных
- Обновление, применение патчей
- Оптимизация, настройка производительности
- Обучение, подготовка персонала, оптимизация
  • Страница:
  • 1
  • 2
  • 3

ТЕМА:

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3983

Решение есть, но у меня не работает на 11.2.0.1.

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Последнее редактирование: от Piston.

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3984

Well, I understand the idea, but it will never work if table name matches some or part of some text within other SQL issued by session. Like T in my case. And for the life of it I have not a slightest idea why FOR EACH ROW. So I modified trigger in that example:
SQL> select  *
  2    from  v$version
  3  /

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

create or replace
  trigger trg
    before insert
    on t
    declare
        v_text varchar2(1000);
        cursor c1
          is
            select  ltrim(sq.sql_text)
              into  v_text
              from  v$sql sq,
                    v$session se,
                    v$open_cursor oc
              where sq.sql_id = oc.sql_id
                and se.saddr = oc.saddr
                and se.sid = oc.sid
                and se.audsid = SYS_CONTEXT('userenv','sessionid')
              order by oc.LAST_SQL_ACTIVE_TIME desc;
    begin
        open c1;
        loop
          fetch c1
            into v_text;
          exit when c1%notfound;
          if regexp_like(v_text,'INSERT +INTO +T( |\()','i')
            then
              dbms_output.put_line(v_text);
              exit;
          end if;
        end loop;
        close c1;
end;
/

Trigger created.

SQL> set serveroutput on
SQL> insert into t values ('michel');
insert into t values ('michel')

1 row created.

SQL>

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3985

OK. FOR cursor LOOP executes in own context. That's why the above doesn't see any open cursors while
open c1;
        loop
          fetch c1
            into v_text;
          exit when c1%notfound;
          if regexp_like(v_text,'INSERT +INTO +T( |\()','i')
            then
              dbms_output.put_line(v_text);
              exit;
          end if;
        end loop;
        close c1;
does. So MetaLink example can be simplified:
create or replace
  trigger trg
    before insert
    on t
    declare
        v_text varchar2(1000);
        cursor c1
          is
            select  sql_text
              from  v$open_cursor
              where sid = sys_context('USERENV','SID');
    begin
        open c1;
        loop
          fetch c1
            into v_text;
          exit when c1%notfound;
          if regexp_like(v_text,'INSERT +INTO +T( |\()','i')
            then
              dbms_output.put_line(v_text);
              exit;
          end if;
        end loop;
        close c1;
end;
/

Trigger created.

SQL> set serveroutput on
SQL> insert into t values ('michel');
insert into t values ('michel')

1 row created.

SQL>

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Последнее редактирование: от Super.

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3986

Стоить добавить
create or replace
  trigger trg
    before insert
    on t
    declare
        v_text varchar2(1000);
        cursor c1
          is
            select  sql_text
              from  v$open_cursor
               where SID=sys_context('USERENV','SID') and sql_exec_id is not null order by sql_exec_id desc;
    begin
        open c1;
        loop
          fetch c1
            into v_text;
          exit when c1%notfound;
          if regexp_like(v_text,'INSERT +INTO +T( |\()','i')
            then
              dbms_output.put_line(v_text);
              exit;
          end if;
        end loop;
        close c1;
end;
/

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3987

Super пишет: OK. FOR cursor LOOP executes in own context. That's why the above doesn't see any open cursors while

Все прозаично
5 declare
6 sql_text varchar2(1000);
7 begin
8 for v_rec in (
9 select sql_text
10 from v$open_cursor
11 ) loop
12 dbms_output.put_line(sql_text);
13 end loop;
14 end;

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Последнее редактирование: от Piston.

Re: V$SESSION.SQL_ID behavior change in 11G 12 года 3 мес. назад #3988

А в моём случае - я делал insert, а триггер был before update

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

  • Страница:
  • 1
  • 2
  • 3
Время создания страницы: 0.209 секунд