Mail needs to be sent after updating the salary column of emp table

Hi,
we have table test_emp_table, oracle form based application is running on this table...
it conatins salary column, we have requirement that, when every any update to the salary column, a mail needs to be sent to concerned person with new and old salary values..
I did that using the following procedure...
===========
-- Create Temporary Table to hold the Updated values
create table email_parameters
( id number primary key,
oldsal varchar2(10),
newsal varchar2(10),
ename varchar2(100));
--- Create Procedure
CREATE OR REPLACE PROCEDURE send_email_new (
l_job IN NUMBER ) is
l_oldsal varchar2(100);
l_newsal varchar2(100);
l_emp_name varchar2(100);
l_message varchar2(100);
BEGIN
SELECT oldsal
INTO l_oldsal
FROM email_parameters
WHERE ID = l_job;
     SELECT newsal
INTO l_newsal
FROM email_parameters
WHERE ID = l_job;
     SELECT ename
INTO l_emp_name
FROM email_parameters
WHERE ID = l_job;
     l_message:=
'Employee Name= '
|| l_emp_name
|| chr(10)||chr(10)
|| 'Old Salary= '
|| l_oldsal
     || chr(10)||chr(10)
|| 'New Salary= '
|| l_newsal;
send_mail(l_message);
DELETE FROM email_parameters
WHERE ID = l_job;
     EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
END;
--- Create Trigger
create or replace trigger send_email_trg
after update on TEST_EMP_TABLE
for each row
declare
l_job number;
begin
dbms_job.submit (job => l_job,
what => 'send_email_new(job);' );
insert into email_parameters
values (l_job, :old.sal,:new.sal,:new.ename);
end send_email_trg;
-- Create Procedure for Sending Mail
create or replace procedure send_mail(l_message varchar2) is
c utl_smtp.connection;
PROCEDURE send_header(name VARCHAR2, header VARCHAR2) AS
BEGIN
utl_smtp.write_data(c,name ||':'|| header || UTL_TCP.CRLF);
END;
BEGIN
c := utl_smtp.open_connection('192.168.0.18');
utl_smtp.helo(c, 'abc.com');
utl_smtp.mail(c, '[email protected]');
utl_smtp.rcpt(c, '[email protected]');
utl_smtp.open_data(c);
send_header('From', '[email protected]');
send_header('To', '[email protected]');
send_header('Subject', 'Warning: Employee Solary has been updated!');
utl_smtp.write_data(c, UTL_TCP.CRLF || l_message);
utl_smtp.close_data(c);
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error
OR utl_smtp.permanent_error THEN
NULL;
END;
raise_application_error(-20000, SQLERRM);
END;
====================
But I have doubt, if there is any problem with mail server, if user is updating salary column from form based application at same time....
will table trigger allows him to save the new record or not????? or will he get any errors????

thanks justin...
I have written that code..but it works...problem is ...i am not able to understand the flow...what happens in the order, until mail is sent...
i have another code.....
I have written with out dbms_job, i have witten directly in the trigger itself...
Tom suggested the procedure, what i have given above..but not the below procedure....
I am not able to understand, what is the difference between them.....
CREATE OR REPLACE TRIGGER test_emp_table_trg
AFTER UPDATE
ON test_emp_table
FOR EACH ROW
WHEN (NEW.sal <> OLD.sal)
DECLARE
l_employee_name VARCHAR2 (240);
l_old_sal VARCHAR2 (240);
l_new_sal VARCHAR2 (240);
l_message VARCHAR2 (240);
BEGIN
/* Gets the employee full name */
BEGIN
SELECT ename
INTO l_employee_name
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_employee_name := NULL;
END;
/* Gets the old Salary */
BEGIN
SELECT sal
INTO l_old_sal
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_old_sal := 0;
END;
/* Gets the new position name */
BEGIN
SELECT sal
INTO l_new_sal
FROM test_emp_table
WHERE empno= :NEW.empno;
EXCEPTION
WHEN OTHERS
THEN
l_new_sal := 0;
END;
l_message:=
'Employee Name= '
|| l_employee_name
|| 'Old Salary= '
|| l_old_sal
|| 'New Salary= '
|| l_new_sal;
BEGIN
send_mail (l_message);
END;
==========
can you please describe it clearly???
thanks in advance my dear friend????
Edited by: oraDBA2 on Oct 4, 2008 10:26 PM

Similar Messages

  • Mail needs to be sent after submitting XMl publisher report

    HI all,
    I have developed one xml publisher (BI Publisher) report.The requirement is when user submits this report from concurrent program window from his responsibility.mail needs to send one particular mail id.
    Could you please give me any idea...
    Thanks,
    Madhu

    thanks justin...
    I have written that code..but it works...problem is ...i am not able to understand the flow...what happens in the order, until mail is sent...
    i have another code.....
    I have written with out dbms_job, i have witten directly in the trigger itself...
    Tom suggested the procedure, what i have given above..but not the below procedure....
    I am not able to understand, what is the difference between them.....
    CREATE OR REPLACE TRIGGER test_emp_table_trg
    AFTER UPDATE
    ON test_emp_table
    FOR EACH ROW
    WHEN (NEW.sal <> OLD.sal)
    DECLARE
    l_employee_name VARCHAR2 (240);
    l_old_sal VARCHAR2 (240);
    l_new_sal VARCHAR2 (240);
    l_message VARCHAR2 (240);
    BEGIN
    /* Gets the employee full name */
    BEGIN
    SELECT ename
    INTO l_employee_name
    FROM test_emp_table
    WHERE empno = :OLD.empno;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_employee_name := NULL;
    END;
    /* Gets the old Salary */
    BEGIN
    SELECT sal
    INTO l_old_sal
    FROM test_emp_table
    WHERE empno = :OLD.empno;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_old_sal := 0;
    END;
    /* Gets the new position name */
    BEGIN
    SELECT sal
    INTO l_new_sal
    FROM test_emp_table
    WHERE empno= :NEW.empno;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_new_sal := 0;
    END;
    l_message:=
    'Employee Name= '
    || l_employee_name
    || 'Old Salary= '
    || l_old_sal
    || 'New Salary= '
    || l_new_sal;
    BEGIN
    send_mail (l_message);
    END;
    ==========
    can you please describe it clearly???
    thanks in advance my dear friend????
    Edited by: oraDBA2 on Oct 4, 2008 10:26 PM

  • How to update the COST column using another table's column

    Dear All,
    I have table:
    table parts: pno, pname, qoh, price, olevel
    table orders: ono, cno, eno, received, shipped
    table odetails: ono, pno, qty
    view:orders_view: ono, cno, eno, received, shipped,sum(qty*price)order_costview:odetails_view: ono, pno, qty, (qty*price)cost
    after I update the price in parts, I need to update COST and ORDER_COST too. The orders_view does not have pno, qty, and price, the odetails_view does not have price, how can I update the COST and ORDER_COST. Please help and Thanks in advance!!!
    I wrote the update the price in parts:
    create or replace procedure change_price(ppno in parts.pno%type, pprice in parts.price%type) as
    begin
        update parts
        set price = pprice
        where pno = ppno;
    end;
    show errorsthis procedure works fine.
    I wrote the trigger:
    create or replace trigger update_orders_v
    after update of price on parts
    for each row
    begin
        update orders_view
        set order_cost = sum(parts.(:new.price)*parts.qty)
        where parts.pno = :new.pno;
    end;
    show errorsIt gives me:Errors for TRIGGER UPDATE_ORDERS_V:
    LINE/COL ERROR
    3/5 PL/SQL SQL Statement ignored
    4/22 PL/SQL ORA-00934: group function is not allowed hereplease help!

    You could add the columns to the tables and then you would need a trigger to update those columns. However, you could just as easily select the price * qty to get the cost, without creating an additional column or trigger. I have no idea what you might want to do with a global temporary table. I think you need to explain what your purpose is, before any of us can suggest the best method. Since I have already demonstrated an update with a view, I will demonstrate an update with the cost column added to the odetails table and a trigger as you asked about. Notice that you will need triggers on both tables, the one that has qty and the one that has price.
    scott@ORA92> create table parts
      2    (pno    number(5) not null primary key,
      3       pname  varchar2(30),
      4       qoh    integer check(qoh >= 0),
      5       price  number(6,2) check(price >= 0.0),
      6       olevel integer)
      7  /
    Table created.
    scott@ORA92> create table odetails
      2    (ono    number(5),
      3       pno    number(5) references parts,
      4       qty    integer check(qty > 0),
      5       cost   number,
      6       primary key (ono,pno))
      7  /
    Table created.
    scott@ORA92> create or replace procedure change_price
      2    (ppno   in parts.pno%type,
      3       pprice in parts.price%type)
      4  as
      5  begin
      6    update parts
      7    set    price = pprice
      8    where  pno = ppno;
      9  end;
    10  /
    Procedure created.
    scott@ORA92> create or replace trigger update_cost1
      2    after insert or update of price on parts
      3    for each row
      4  begin
      5    update odetails
      6    set    cost = qty * :new.price
      7    where  pno = :new.pno;
      8  end update_cost1;
      9  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> create or replace trigger update_cost2
      2    before insert or update of qty on odetails
      3    for each row
      4  declare
      5    v_price parts.price%type;
      6  begin
      7    select price
      8    into   v_price
      9    from   parts
    10    where  pno = :new.pno;
    11    --
    12    :new.cost := :new.qty * v_price;
    13  end update_cost2;
    14  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> insert into parts values (1, 'name1', 1, 10, 1)
      2  /
    1 row created.
    scott@ORA92> insert into odetails values (1, 1, 22, null)
      2  /
    1 row created.
    scott@ORA92> -- starting data:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         10          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        220
    scott@ORA92> -- update:
    scott@ORA92> execute change_price (1, 11)
    PL/SQL procedure successfully completed.
    scott@ORA92> -- results:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         11          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92> -- select works without extra cost column or trigger:
    scott@ORA92> select o.ono, o.pno, o.qty, (o.qty * p.price) as cost
      2  from   odetails o, parts p
      3  where  o.pno = p.pno
      4  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92>

  • I find Mail under Mavericks to be weird. Are others having this same difficulty. "Upgraded" to Mavericks last week, after updating the firmware to my WD external HD.

    I find Mail under Mavericks to be weird. Are others having this same/similar difficulty? "Upgraded" to Mavericks last week, after updating the firmware to my WD external HD.

    "Weird" needs further explanation.
    Google's highly nonstandard IMAP implementation is weird, if you're using Gmail, though Apple bent over backwards to accomodate it. Other than that, what do you mean by "weird"?

  • Plz hlep my : iso 7  4s /There is a problem in my iPhone device after updating the new version needed to ActiveX wants amyl, bus and my Lord and unfortunately forgot this data, what work Please reply my machine data is

    There is a problem in my iPhone device after updating the new version needed to ActiveX wants amyl, bus and my Lord and unfortunately forgot this data, what work Please reply my machine data is
    Imei: 013055008069758
    SerialNumber:DN*******TC0
    mlbserialNumber: DQ************42D
    plz hlep me
    <Personal Information Edited by Host>

    There is a problem in my iPhone device after updating the new version needed to Active iPhone 4s
    and
    I upgraded to 7.0.3 yesterday and now my battery only lasts about 4 hours with very little active use.
    iOS 7.0.3

  • There is a problem in my iPhone device after updating the new version needed to ActiveX wants amyl, bus and my Lord and unfortunately forgot this data, what work Please reply my machine data is

    There is a problem in my iPhone device after updating the new version needed to ActiveX wants amyl, bus and my Lord and unfortunately forgot this data, what work Please reply my machine data is
    Imei: 013055008069758
    SerialNumber:DN*******TC0
    mlbserialNumber: DQ************42D
    plz plz plz hlep me
    <Edited by Host>

    There is a problem in my iPhone device after updating the new version needed to Active iPhone 4s
    and
    I upgraded to 7.0.3 yesterday and now my battery only lasts about 4 hours with very little active use.
    iOS 7.0.3

  • HT4623 after updating the iOS6 my iPhone 4 is not working

    after updating the iOS6 my iPhone 4 is not working

    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...
    Be sure to Follow ALL the Steps...
    But... if the Device has been Modified... this will Not necessarily work.

  • My mail icon is not working after update ios 6.1.1 ????

    dear sir please give me soluction.
    my mail icon is not working after update of ios 6.1.1

    You can only purchase apps and other media for the county's sore in which yu are located. You account, included payment method, also must be associated with that country.
    Sam applies for updating apps. Note that not all apps are available in all country so y will not be able to update an app if you are in another country and that app is not available in that country or your account is not associated with that country.
    You can change the country and other things by:
    iOS: Changing the signed-in iTunes Store Apple ID account

  • Anyone know of a fix after updating the last ios...ipad keeps restarting or won't stay on.  Very aggravating.

    Anyone know of a fix after updating the last ios...ipad keeps restarting or won't stay on.  Very aggravating.

    Have you tried resetting your iPad? I don't have a lot of confidence that it will work for you, but it's an easy thing to try and a good place to start.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.
    If that doesn't help, you should probably restore the iOS software. You may even need to use recover mode. Both are covered in this in article.
    Use iTunes to restore your iOS device to factory settings

  • I can't back up my phone, they ask me to delete the back up, but I don't want to because I lost everything after updating the iTunes, How can I get back the back up?

    Everytime I try backing up my phone, it says there's something wrong and wants me to delete the back up...But I don't want to delte the back up because I just lost everything after updating the iTunes, Is there any way I could get back everything from the back up?

    Thank you for answering my question. If I reinstall itune, is it mean that I need to install music, apps, video...everything in itune again? also intall everything in my iphone again?

  • Execute a SQL-Insert after update the target

    Hi to All,
    my scenario is   SQL_1 -> XI -> SQL_2, but after update the SQL_2, I need to execute an SQL-insert. Can I do this without BPM?
    Regarts
    Roberto

    Hi Roberto,
    If you want to insert the SQL_2 after updation of SQL_2 then BPM is not required.
    After updating the target you can execute the insert operation. I think , you can go for Stored procedures here.
    But if you want Response back to XI after successful Update, then BPM is required.
    >>You can do this in the stored procedure. For e.g just check this blog-
    /people/siva.maranani/blog/2005/05/21/jdbc-stored-procedures
    Regards,
    Moorthy
    Message was edited by: Krishna Moorthy P

  • S this necessary to keep enabling the 3G in iphone 4s after updating the version?

    s this necessary to keep enabling the 3G in iphone 4s after updating the version?

    If "Enable 3G" is on, you shouldn't need to enable it again after updating.

  • TS1967 After 'updating' the newest iTunes version, I cannot sync my iPod Nano!  It does not show up anymore.

    After 'updating' the newest iTunes version, I cannot sync my iPod Nano!  The 'old' version recognized and showed in icon to sync, but the newest version does not.  Is there a way to sync the older iPods?

    http://support.apple.com/kb/TS1591
    There have been some problems accessing pages on the Apple web site.  If the hyperlink gives you a "We're sorry" message, try again.

  • I have an IPad 4.  After updating the system, when I try to look at picture on Facebook and make it larger, there is just a "circle" in the middle of the page instead of the picture.  Can anyone help me?

    I have an IPad 4.  After updating the system, when I try to look at picture on Facebook and make it larger, there is just a "circle" in the middle of the page instead of the picture.  Can anyone help me?

    Close all open apps by double-tapping the home button, then swiping up and off the screen with the app window (not the smaller icon).
    Reset your device: hold down the home button along with the sleep/wake button until the screen goes black and you see the Apple, then let go. (No data loss)

  • [SOLVED] vi (vim) no longer works properly after updating the system

    After updating the system with pacman -Syu vi stopped working. All syntax colors are gone, and everything is grey. When I press i to enter "insert" mode, editing is not visible. Changes are obscure and you can't tell what you are modifying.  Quitting with :q will still prompt you to use :q! to abort changes, even if no changes were visibly made.
    When scrolling to the beginning or end of a file, the screen flashes with grey glitch like areas.  What happened to my vi!?!?!?!?!?
    This all happened while following the beginner's guide to install arch linux.  I realized this when trying to arbitrarily read a test file I made directly after updating.
    The problems continued to be visible when installing and setting up sudo (those steps are the next steps that require vi)...  I think the sudo installation worked... but my vi is horribly glitchy
    Any ideas?
    Last edited by trusktr (2010-02-19 07:19:55)

    Setting EDITOR does not help in every case. For instance, visudo is by default hard linked to vi. (You can change this, I know. )
    But in fact, vi is only a symlink to ex. So I simply renamed this link and put another symlink to vim (vim-big in my case since I in fact do use the gvim package).
    /usr/bin/vi -> vim-big
    /usr/bin/vi-simple -> ex
    The drawback is that I have to set those links on every vi-update. (But I sure will remember...)
    Last edited by bernarcher (2010-02-19 00:58:57)

Maybe you are looking for

  • LSMW--Create Material master data

    Hi, When I use LSMW to create material master data, I set up all step, but when I go to last step "13 Run Batch Input Session", there is error message like "Select at least one view" in moudle SAPLMGMM, screen 0070, anybody can tell me what is proble

  • Long running select statement and v$session_longops

    Oracle Version: 10.2.0.4 I've a long running sql query that takes the estimated 6 minutes to complete and return the result. While it's running I'd like to observe it into the view v$session_longops. I altered the session that runs the query with   A

  • I desperately need help....i beg you!

    Hi all! this is my first post in this forum. i have to write a program about "Pascal Triangle". this is how it should look like: a program that prints portions of Pascal Triangle.it should ask user to enter number which is going to be the "number of

  • Updating I-tunes from IPad 2

    I have many tunes and videos on my iPad but from an iTunes account that is no longer accessible. How can I sync these back to my iTunes account on my computer?

  • I cant figure out how to download magazines. Can you help me?

    Please tell me how to download a magazine that I've paid for.  I.e. Oprah