Hi,
I've been using Oracle 9i now and want to know if the following is possible. I've got Customer table. I want to create a trigger that, when a new customer is added or update, will output the changes to a text file. For example, if Mr Smith's address is created, it will pick up his name from the Customer table and output the results to a text file in a '0001, Mr Smith, 12, format or similar.
Any examples or guides would be very helpful!!
Thanks in advance.
3 12192
Try to use the UTL_FILE package for the purpose.
Hi,
I've been using Oracle 9i now and want to know if the following is possible. I've got Customer table. I want to create a trigger that, when a new customer is added or update, will output the changes to a text file. For example, if Mr Smith's address is created, it will pick up his name from the Customer table and output the results to a text file in a '0001, Mr Smith, 12, format or similar.
Any examples or guides would be very helpful!!
Thanks in advance.
You can use UTL_FILE as suggested in the above post by either implementing a UTL_FILE operation in the trigger itself or create a seperate procedure and call that procedure from the trigger.
may this coding will be helpful to you. modify it and write under trigger -
-
CREATE OR REPLACE PROCEDURE sal_status
-
(p_filedir IN VARCHAR2, p_filename IN VARCHAR2)
-
IS
-
v_filehandle UTL_FILE.FILE_TYPE;
-
CURSOR emp_info IS
-
SELECT ename, sal, deptno
-
FROM emp
-
ORDER BY deptno;
-
v_newdeptno emp.deptno%TYPE;
-
v_olddeptno emp.deptno%TYPE := 0;
-
BEGIN
-
v_filehandle := UTL_FILE.FOPEN (p_filedir, p_filename,'w');
-
UTL_FILE.PUTF (v_filehandle,'SALARY REPORT: GENERATED ON
-
%s\n', SYSDATE);
-
UTL_FILE.NEW_LINE (v_filehandle);
-
FOR v_emp_rec IN emp_info LOOP
-
v_newdeptno := v_emp_rec.deptno;
-
IF v_newdeptno <> v_olddeptno THEN
-
UTL_FILE.PUTF (v_filehandle, 'DEPARTMENT: %s\n',
-
v_emp_rec.deptno);
-
END IF;
-
UTL_FILE.PUTF (v_filehandle,' EMPLOYEE: %s earns: %s\n',
-
v_emp_rec.ename, v_emp_rec.sal);
-
v_olddeptno := v_newdeptno;
-
END LOOP;
-
UTL_FILE.PUT_LINE (v_filehandle, '*** END OF REPORT ***');
-
UTL_FILE.FCLOSE (v_filehandle);
-
EXCEPTION
-
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
-
RAISE_APPLICATION_ERROR (-20001, 'Invalid File.');
-
WHEN UTL_FILE.WRITE_ERROR THEN
-
RAISE_APPLICATION_ERROR (-20002, 'Unable to write to
-
file');
-
END sal_status;
-
/
-
-
create OR REPLACE DIRECTORY emp_dir as 'c:\';
-
/
-
execute sal_status('EMP_DIR','YY.TXT');
-
/
-
execute sal_status('EMP_DIR','C:\YYY.DOC'); -- ONLY CREATES UNDER THE C:\ DRIVE
-
'
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Terri |
last post by:
I'm using xp_cmdshell to output a text file from a trigger like this
CREATE TRIGGER ON tblApplications
FOR INSERT
AS
DECLARE @FirstName varchar(75)
DECLARE @LastName varchar(75)
Declare...
|
by: Lauren Quantrell |
last post by:
Is there a way to create a text file (such as a Windows Notepad file)
by using a trigger on a table? What I want to do is to send a row of
information to a table where the table: tblFileData has...
|
by: Lauren Quantrell |
last post by:
I have created the following trigger:
CREATE TRIGGER ON OutputTable
FOR INSERT
AS
Declare @filename nvarchar(35)
Declare @filecontents nvarchar(2000)
Declare @strcmdshell varchar(150)
|
by: pr33tz |
last post by:
Hi,
I've been using SQL Server 2000 for a short while now and want to know if the following is possible. I've got two tables, Customer table and an Address table. I want to create a trigger that,...
|
by: Quentin |
last post by:
Any code on how to start write to a new file would be appreciated. In
the example below: How would I start the write to a file on the word
"Recipe" and then write every line beneath it until "End...
| |
by: wugon.net |
last post by:
Hi ,
Anyone know how to monitor db2 trigger activity ?
We suffer some trigger issue , and we try to monitor trigger's
behavior use event monitor and db2audit, but both tools can not get...
|
by: wugon.net |
last post by:
Hi ,
Anyone know how to monitor db2 trigger activity ?
We suffer some trigger issue today and we try to monitor trigger's
behavior use event monitor and db2audit, but both tools can not get...
|
by: bwestover |
last post by:
I am trying to pull data out of an application database and transform it to another medium.
I have direct access to the database, but I cannot alter the program code.
What I want to have happen...
|
by: lenygold via DBMonster.com |
last post by:
I have the following trigger:
--#SET TERMINATOR !
CREATE TRIGGER CROSS_REFF_TRIG
AFTER INSERT ON NEW_CATALOG
REFERENCING NEW AS nnn
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE reason...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |