Home » SQL & PL/SQL » SQL & PL/SQL » Best Data Dictionary table to use in a trigger
Best Data Dictionary table to use in a trigger [message #38289] Mon, 08 April 2002 07:27 Go to next message
Anthony
Messages: 48
Registered: September 2000
Member
Hi All,

I need to write a trigger that will take the contents of a table and write it to another table. The trouble the data is going to a field of length 2000.

The information from the table could be larger than this, so I would like to create some sort of cursor which would access a Data Dictionary table which held the names of the columns of my table (about 100), get the information from the field and add it to the field if there is enough space.

My question is, what is the best table to use for this type of query? are there any tables which shouldnīt be used etc. etc. Anything that I should be aware of before doing this?

Thanks in advance

Anthony
Re: Best Data Dictionary table to use in a trigger [message #38297 is a reply to message #38289] Mon, 08 April 2002 12:19 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
user_tab_columns will give you the column lengths. If you are going to concatenate strings with "dates" and "numbers" then all then the data dictionary isn't goin to help.

In pl/sql, create your new temp string as varchar2(32767) or something else big, then just test the length of the temp result. e.g.
v_str varchar2(4000) := char_field||' '||date_field||' '||number_field;
if length(v_str) > 2000 then
-- trim it down and put some ... on the end
v_str := substr(v_str, 1, 1997)||'...';
-- OR raise an exception
raise_application_error();
Re: Best Data Dictionary table to use in a trigger [message #38301 is a reply to message #38297] Tue, 09 April 2002 00:48 Go to previous messageGo to next message
Anthony
Messages: 48
Registered: September 2000
Member
Thanks, I think that table is pretty much the one I need.

My next question is, Can I access the values from user_tab_columns.column_name (using some sort of indirection) and use them in the trigger so that I could have the line.

v_long_str = v_long_str||'#'||:new.user_tab_columns.column_name ?

I am using Oracle 8.0.6. (use DBMS_SQL package here for indirection?)

Thinking about it, I donīt see how I can, but it would be great if I could, as the table in question has over a 100 fields and will very probably have more added in the future.

TIA
DMBS_SQL package in a trigger [message #38302 is a reply to message #38297] Tue, 09 April 2002 01:29 Go to previous messageGo to next message
Anthony
Messages: 48
Registered: September 2000
Member
Iīve been thinking that in this case I would need to execute the PL/SQL statement using DBMS_SQL package

v_str := v_str||'#'||new.||user_tab_columns.column_name

But this is not a simple sql select, update or delete. I would like to execute the above statement, be able to get the value of v_str returned so I can examine it.

Can this be done? What is the order of statements I need to call in the package, something like

open cursor
bind_variable
execute
variable_value
close_cursor

I imagine.

TIA
Re: DMBS_SQL package in a trigger [message #38309 is a reply to message #38302] Tue, 09 April 2002 11:56 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
See the following link:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:235814350980

It will be much better to create a hardcoded pl/sql trigger than run dynamic sql if you want this to be as fast as possible. You can still use jist of that code to build the trigger script for you. If you make a sqlplus script to create the trigger, you can use code like "PROMPT create or replace trigger...". For something to run from TOAD or similar tool you can use "dbms_output.put_line('create or replace trigger...');"
Re: DMBS_SQL package in a trigger - Thanks [message #38316 is a reply to message #38302] Wed, 10 April 2002 00:56 Go to previous message
Anthony
Messages: 48
Registered: September 2000
Member
Thanks!
Previous Topic: Creating a Read-Only User
Next Topic: Re: To delete a file
Goto Forum:
  


Current Time: Sat May 04 20:11:19 CDT 2024