Posts under - SQL Serever / Oracle / PLSQL 
Blog Home
  Oracle/PLSQL: Drop a Trigger

The syntax for a dropping a Trigger is:

DROP TRIGGER trigger_name;

For example:

If you had a trigger called orders_before_insert, you could drop it with the following command:

DROP TRIGGER orders_before_insert; 

From www.techonthenet.com

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: AFTER DELETE Trigger

An AFTER DELETE Trigger means that Oracle will fire this trigger after the DELETE operation is executed.

The syntax for an AFTER DELETE Trigger is:

CREATE or REPLACE TRIGGER trigger_name
AFTER DELETE
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create an AFTER trigger on a view.
You can not update the :NEW values.
You can not update the :OLD values.
For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2)
);


We could then create an DELETE UPDATE trigger as follows:

CREATE... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: BEFORE DELETE Trigger

A BEFORE DELETE Trigger means that Oracle will fire this trigger before the DELETE operation is executed.

The syntax for an BEFORE DELETE Trigger is:

CREATE or REPLACE TRIGGER trigger_name
BEFORE DELETE
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create a BEFORE trigger on a view.
You can update the :NEW values.
You can not update the :OLD values.
For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2)
);

We could then create a BEFORE DELETE trigger as follows:

CREATE... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: AFTER UPDATE Trigger

An AFTER UPDATE Trigger means that Oracle will fire this trigger after the UPDATE operation is executed.

The syntax for an AFTER UPDATE Trigger is:

CREATE or REPLACE TRIGGER trigger_name
AFTER UPDATE
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create an AFTER trigger on a view.
You can not update the :NEW values.
You can not update the :OLD values.
For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2)
);


We could then create an AFTER UPDATE trigger as follows:

CREATE... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: BEFORE UPDATE Trigger

A BEFORE UPDATE Trigger means that Oracle will fire this trigger before the UPDATE operation is executed.

The syntax for an BEFORE UPDATE Trigger is:

CREATE or REPLACE TRIGGER trigger_name
BEFORE UPDATE
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create a BEFORE trigger on a view.
You can update the :NEW values.
You can not update the :OLD values.

 

For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2),
 updated_date date,
 updated_by varchar2(10)
);... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: AFTER INSERT Trigger

An AFTER INSERT Trigger means that Oracle will fire this trigger after the INSERT operation is executed.

The syntax for an AFTER INSERT Trigger is:

CREATE or REPLACE TRIGGER trigger_name
AFTER INSERT
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create an AFTER trigger on a view.
You can not update the :NEW values.
You can not update the :OLD values.
For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2)
);

We could then create an AFTER INSERT trigger as follows:

CREATE... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle/PLSQL: BEFORE INSERT Trigger

A BEFORE INSERT Trigger means that Oracle will fire this trigger before the INSERT operation is executed.

The syntax for an BEFORE INSERT Trigger is:

CREATE or REPLACE TRIGGER trigger_name
BEFORE INSERT
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

trigger_name is the name of the trigger to create.

Restrictions:

You can not create a BEFORE trigger on a view.
You can update the :NEW values.
You can not update the :OLD values.
For example:

If you had a table created as follows:

CREATE TABLE orders
( order_id number(5),
 quantity number(4),
 cost_per_item number(6,2),
 total_cost number(8,2),
 create_date date,
 created_by... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle Triggers

What is a trigger?

A trigger is a special case of stored procedure that is fired during an event rather than being explicitly executed. A function or a procedure can be called from a command line or from within a different calling program. A trigger is called automatically when an event is fired.

In Oracle, a trigger can have the procedural code embedded in the body of the trigger, you can call out to another existing function or procedure, or a combination of both. The code in a trigger is generally the same as any procedure or function. You are allowed to create Java triggers but I see this rarely in live systems.

You cannot execute transaction control statements with in a trigger. That means no commits or rollbacks. If you need to rollback a transaction due to logic in a trigger, raise an exception and allow the calling program to take the appropriate action. As for commits, the calling application should always commit or rollback as needed.

Technically,... Read Full Post

Posted by Rajiv on Friday, February 27, 2009 at 08:31-AM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Sending content-type: html e-mail from an Oracle database with utl_smtp

If you're running Oracle 10g or later, you can use the nice modern utl_mail package to send e-mails from your PL/SQL applications. Even though the application I maintain is now running on Oracle 10g, it was built back on an Oracle 8i database, so it sends e-mails via the older (and more complicated) utl_smtp package.

Code Syntax to send Content Type HTML emails using Oracle database:

utl_smtp.write_data(c, 'Content-Type: text/html' || utl_tcp.crlf);

To begin, the utl_smtp package has to be installed (in the SYS schema, naturally). If it wasn't part of your install, you can find the utlsmtp.sql script in your ORACLE_HOME\RDBMS\admin directory. You'll also need utl_tcp; again, if it's not already loaded, the utltcp.sql script for that is in the same location as the utlsmtp.sql. Finally, you will need to know the URL for your corporate SMTP server. (Note: This example won't work with secured SMTP servers like Gmail.)

The spec for our little... Read Full Post

Posted by Rajiv on Saturday, February 21, 2009 at 01:56-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Send email from Oracle Database

Introduction
This code shows how to send email using Oracle PL/SQL / Oracle Database.

Language and Platform
Oracle9i database server

Code
create or replace package mail_pkg
    as
            type array is table of varchar2(255);
 
            procedure send( p_sender_email in varchar2,
                            p_from         in varchar2,
                            p_to           in array default array(),
                           ... Read Full Post

Posted by Rajiv on Saturday, February 21, 2009 at 12:45-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  Oracle Create Sequence

The oracle docs note the syntax for the Oracle CREATE SEQUENCE function as follows:

CREATE SEQUENCE [ schema. ]sequence
   [ { INCREMENT BY | START WITH } integer
   | { MAXVALUE integer | NOMAXVALUE }
   | { MINVALUE integer | NOMINVALUE }
   | { CYCLE | NOCYCLE }
   | { CACHE integer | NOCACHE }
   | { ORDER | NOORDER }
   ]
     [ { INCREMENT BY | START WITH } integer
     | { MAXVALUE integer | NOMAXVALUE }
     | { MINVALUE integer | NOMINVALUE }
     | { CYCLE | NOCYCLE }
     | { CACHE integer | NOCACHE }
     | { ORDER | NOORDER }
     ]... ;

Let's look at this example for using the Oracle CREATE SEQUENCE:

Read Full Post

Posted by Rajiv on Saturday, February 21, 2009 at 12:35-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  How to Find and Replace Text in MySQL Database using SQL

MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

MySQL reference describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string. text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.

For example:

update... Read Full Post

Posted by Rajiv on Friday, February 20, 2009 at 03:14-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  How to Escape Characters in Oracle PL/SQL Queries

Oracle databases reserve some special characters with specific meaning and purpose within Oracle environment. These reserved characters include _ (underscore) wild card character which used to match exactly one character, % (percentage) which used to match zero or more occurrences of any characters and ‘ (apostrophe or quotation mark) which used to mark the value supplied. These special characters will not be interpreted literally when building SQL query in Oracle, and may caused error in results returned especially when performing string search with LIKE keyword. To use these characters so that Oracle can interpret them literally as a part of string value instead of preset mean, escape character has to be assigned.

Oracle allows the assignment of special escape characters to the reserved characters in Oracle can be escaped to normal characters that is interpreted literally, by using ESCAPE keyword.

For example, to select the name of guests with _ (underscore) in it, use... Read Full Post

Posted by Rajiv on Friday, February 20, 2009 at 03:14-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


  How to create an Oracle PL/SQL package body

There are many benefits to encapsulating PL/SQL functions and stored procedures into packages:

Better PL/SQL performance. Oracle stored procedures load once into the shared pool and remain there unless they become paged out.
 
Coupling of data with methods. DBAs can use naming conventions with Oracle packages to couple tables with the PL/SQL associated with a table, essentially using Oracle stored procedures as "methods".
 
Isolation of PL/SQL code. Since all PL/SQL anonymous blocks are moved out of the external programs and into the Oracle stored procedures, the application programs become nothing more than calls to stored procedures. As such, it becomes very simple to swap out one database and swap in another one.
One of the foremost reasons PL/SQL packages function faster than traditional code is related to caching in the Oracle... Read Full Post

Posted by Rajiv on Thursday, February 19, 2009 at 04:29-PM under SQL Serever / Oracle / PLSQL
Post Comments (0) Back to Top


Recent Blog Posts
Show All Posts



© Copyright 2009 All rights reserved, Rajiv Sharma
Home | Contact Me | Sitemap | Privacy Notice & Disclaimer
Visitor's IP Address:
44.192.79.149