0% found this document useful (0 votes)
56 views11 pages

PL/SQL Block Has The Following Structure

The document discusses the structures and syntax of various PL/SQL programming elements including blocks, procedures, functions, triggers, and sequences. It provides examples of how to declare variables and write executable code within blocks, procedures and functions. It also demonstrates how to create triggers to log data changes and sequences to generate unique numbers.

Uploaded by

virusyadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views11 pages

PL/SQL Block Has The Following Structure

The document discusses the structures and syntax of various PL/SQL programming elements including blocks, procedures, functions, triggers, and sequences. It provides examples of how to declare variables and write executable code within blocks, procedures and functions. It also demonstrates how to create triggers to log data changes and sequences to generate unique numbers.

Uploaded by

virusyadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

PL/SQL block has the following structure:

DECLARE Declaration statements BEGIN Executable statements EXCETION Exception-handling statements END ;

DECLARE v_first_name VARCHAR2(35) ; v_last_name VARCHAR2(35) ; v_counter NUMBER := 0 ; BEGIN SELECT first_name, last_name INTO v_first_name, v_last_name FROM student WHERE student_id = 123 ; DBMS_OUTPUT.PUT_LINE (Student name : || v_first_name || || v_last_name); END;

Syntax OF the Procedure CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters] IS/AS Declaration section BEGIN Execution section EXCEPTION Exception section END;

Example of PROCEDURE CREATE OR REPLACE PROCEDURE employer_details IS V_id number(3); V_name varchar(10); V_sal number(3); BEGIN V_id:=&V_id; Select name,sal into V_name,V_sal from emp Where id=V_id; dbms_output.put_line(V_name || ' ' ||v_sal); END;

Syntax of FUNCTION CREATE [OR REPLACE] FUNCTION function_name [parameters] RETURN return_datatype; IS Declaration_section BEGIN Execution_section Return return_variable; EXCEPTION exception section Return return_variable; END;

Example of function CREATE OR REPLACE FUNCTION employer_details return number(3); IS V_id number(3); V_name varchar(10); V_sal number(3); BEGIN V_id:=&V_id; Select name,sal into V_name,V_sal from emp Where id=V_id; RETURN v_sal; dbms_output.put_line(function ); END;

Syntax of TRIGGER. CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE | AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] | DELETE} [OF col_name] ON table_name [REFERENCING OLD AS o NEW AS n] [FOR EACH ROW] WHEN (condition) BEGIN --- sql statements END;

CREATE TABLE product_price_history (product_id number(5), product_name varchar2(32), supplier_name varchar2(32), unit_price number(7,2) ); CREATE TABLE product (product_id number(5), product_name varchar2(32), supplier_name varchar2(32), unit_price number(7,2) );

CREATE or REPLACE TRIGGER price_history_trigger BEFORE UPDATE OF unit_price ON product FOR EACH ROW BEGIN INSERT INTO product_price_history VALUES (:old.product_id, :old.product_name, :old.supplier_name, :old.unit_price); END;

create [or replace] [public] synonym [schema .] synonym_name for [schema .] object_name [@ dblink];

CREATE SEQUENCE sequence_name [ INCREMENT BY value START WITH value MINVALUE value MAXVALUE value CYCLE/NOCYCLE ORDER/NOORDER CACHE value/NOCACHE];

You might also like