Home » RDBMS Server » Server Administration » How to see the complete content of trigger_body in user_triggers (DB 8.1.7, OS Windows XP SP2)
How to see the complete content of trigger_body in user_triggers [message #468754] Mon, 02 August 2010 01:52 Go to next message
oracle_user1
Messages: 45
Registered: May 2008
Member
Dear all,

Column Trigger_body in table user_trigger is long data type.
I want to find out the certain 'table name' was using in
trigger.

Below is my sql statement:
select trigger_name
from user_triggers
where TRIGGER_BODY like '%tb_test%' or TRIGGER_BODY like '%TB_TEST%';

then it show me a error :
where TRIGGER_BODY like '%tb_test%'
*
ERROR at line 3:
ORA-00932: inconsistent datatypes

I had set long 32767 before execute above statement

If you have any solution or tip please let me know...

Thanks.

Regards,
oracle user
Re: How to see the complete content of trigger_body in user_triggers [message #468760 is a reply to message #468754] Mon, 02 August 2010 02:00 Go to previous messageGo to next message
ramoradba
Messages: 2456
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Quote:
LONG columns cannot appear in WHERE clauses or in integrity constraints


sriram
Re: How to see the complete content of trigger_body in user_triggers [message #468761 is a reply to message #468754] Mon, 02 August 2010 02:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68653
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You have to query in USER_SOURCE as you cannot apply any operator on LONG column.
If source is less than 32K then you can also create your own PL/SQL function to do it recording the trigger_body column in a variable.

Regards
Michel
Re: How to see the complete content of trigger_body in user_triggers [message #468763 is a reply to message #468754] Mon, 02 August 2010 02:06 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
ALL_SOURCE where TYPE='TRIGGER'

Thanks
Ved

Re: How to see the complete content of trigger_body in user_triggers [message #468939 is a reply to message #468763] Mon, 02 August 2010 09:57 Go to previous messageGo to next message
oracle_user1
Messages: 45
Registered: May 2008
Member
Dear all,

Thanks all your tips, i had try it, but still can't work.
Now i want to sharing the solution with you all.
Actually i get this solution from other website.


CREATE TABLE t1 (
col1 VARCHAR2(20),
col2 VARCHAR2(20));

ALTER TABLE t1
ADD CONSTRAINT cc_t1_col1
CHECK (col1 IN ('Yes', 'No', '?'));

CREATE OR REPLACE TRIGGER BIT_T1
BEFORE INSERT
ON t1
FOR EACH ROW
BEGIN
:NEW.col1 := 'Yes';
END BIT_T1;
/

CREATE TABLE t2 (
col1 VARCHAR2(20),
col2 VARCHAR2(20));

ALTER TABLE t2
ADD CONSTRAINT cc_t2_col1
CHECK (col1 IN ('Yes', 'No', 'X'));

CREATE OR REPLACE TRIGGER BIT_T2
BEFORE INSERT
ON t2
FOR EACH ROW
BEGIN
:NEW.col1 := 'No';
END BIT_T2;
/

SELECT trigger_name, trigger_body
FROM user_triggers;

SELECT constraint_name, search_condition
FROM user_constraints;
We will start our exploration with wild card searches. Lets say we are looking for all of the rows with the value 'Yes'. There should be one of them in USER_TRIGGERS.
desc user_triggers

-- none of these work
SELECT trigger_name, trigger_body
FROM user_triggers
WHERE trigger_body LIKE '%Yes%';

SELECT trigger_name, trigger_body
FROM user_triggers
WHERE TO_CHAR(trigger_body) LIKE '%Yes%';

SELECT trigger_name, trigger_body
FROM user_triggers
WHERE TO_CLOB(trigger_body) LIKE '%Yes%';

SELECT trigger_name, trigger_body
FROM user_triggers
WHERE TO_LOB(trigger_body) LIKE '%Yes%';

DECLARE
c CLOB;
BEGIN
SELECT TO_LOB(trigger_body)
INTO c
FROM user_triggers
WHERE rownum = 1;
END;
/

-- and yet this works
CREATE TABLE tlob (
testcol CLOB);

INSERT INTO tlob
SELECT TO_LOB(trigger_body)
FROM user_triggers;

SELECT * FROM tlob;
So how do we get only those values we want? Adding a WHERE clause with SUBSTR doesn't work. One obvious solution is to put all trigger bodies into a global temporary table and then select from there. For example:
DROP TABLE tlob PURGE;

CREATE GLOBAL TEMPORARY TABLE tlob (
testcol CLOB);

-- Step 1:
INSERT INTO tlob
SELECT TO_LOB(trigger_body)
FROM user_triggers;

-- Step 2:
SELECT *
FROM tlob
WHERE testcol LIKE '%Yes%';

or

DELETE FROM tlob
WHERE testcol NOT LIKE '%Yes%';
But is there a way to do this without inserting into a table? Unfortunately there isn't except under some very special, not general conditions so for our purposes we will say no. You must use LONG to LOB solely for purposes of version. And there is nothing you can do with LONG in a WHERE clause.

Simply put ... if you have a LONG, and you wish to do more than just display it, you must use TO_LOB to convert it during either an INSERT INTO <table> or a CREATE TABLE <table_name> AS. Everything else is just wasting time.



Thanks.

Regards,
oracle user
Re: How to see the complete content of trigger_body in user_triggers [message #468940 is a reply to message #468939] Mon, 02 August 2010 10:00 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>but still can't work.

My car won't work.
Tell me how to make my car go.

It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
Re: How to see the complete content of trigger_body in user_triggers [message #468941 is a reply to message #468940] Mon, 02 August 2010 10:03 Go to previous messageGo to next message
cookiemonster
Messages: 13923
Registered: September 2008
Location: Rainy Manchester
Senior Member
Did you bother looking at all_source as Ved suggested?
Re: How to see the complete content of trigger_body in user_triggers [message #468947 is a reply to message #468939] Mon, 02 August 2010 10:29 Go to previous message
Michel Cadot
Messages: 68653
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.

Explain in what it "does not work".
If you have any error, use SQL*Plus and copy and paste your session.

Regards
Michel
Previous Topic: Undo Management
Next Topic: while creating the index ORA-00603: ORACLE server session terminated by fatal error
Goto Forum:
  


Current Time: Sun May 19 23:35:20 CDT 2024