0% found this document useful (0 votes)
32 views

PLSQL Introduction

PL/SQL is Oracle's procedural language extension to SQL. It allows programmers to define blocks of code that include variable declarations, conditional logic, and exception handling. The basic structure of a PL/SQL block includes a declaration section, a begin-end block, and an optional exception section. Variables must be declared before use and constants cannot be changed after declaration. PL/SQL code can run on either the database server or Oracle client depending on needs.

Uploaded by

rashidmehmood
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

PLSQL Introduction

PL/SQL is Oracle's procedural language extension to SQL. It allows programmers to define blocks of code that include variable declarations, conditional logic, and exception handling. The basic structure of a PL/SQL block includes a declaration section, a begin-end block, and an optional exception section. Variables must be declared before use and constants cannot be changed after declaration. PL/SQL code can run on either the database server or Oracle client depending on needs.

Uploaded by

rashidmehmood
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Oracle SQL & PL/SQL: PL/SQL Introduction

Page 1 of 3

Share

Report Abuse

Next Blog

Create Blog

Sign In

Oracle SQL & PL/SQL


RSS Feed
Ads by Google
Oracle PL SQL Jobs Oracle SQL PL SQL Course SQL PLSQL Training PLSQL

Oracle SQL & PL/SQL


Oracle SQL SQL Introduction SQL Syntax SQL Select SQL Insert SQL Update SQL Delete SQL Joins SQL Group By SQL Group By Examples SQL Having SQL - IN SQL - NULLs SQL SubQueries SQL Views Insert, Update, Delete Views SQL Join Views SQL Inline Views SQL - Nth Highest Salary SQL Second Highest Salary SQL - Difference Truncate / Delete SQL - Difference Truncate / Drop SQL - Difference HAVING / WHERE SQL - Difference CAST / CONVERT SQL - Difference NOT IN / NOT EXIST SQL - Difference IN / EXISTS SQL - Difference UNION / UNION ALL SQL - REPLACE SQL - TOP SQL - LIKE SQL - SELECT INTO SQL - CREATE TABLE SQL - CREATE TABLE (More Examples) SQL - ALTER TABLE SQL - Difference views / Materialized views SQL Count SQL Update SQL Clustered / Non-Clustered Indexes SQL - Delete Duplicate Records SQL - Difference Unique/Primary Key SQL - GETDATE() SQL - DATEDIFF() SQL - DATEADD() SQL - DATEPART() SQL - Convert() SQL - SUM() SQL - AVG() SQL - MIN() SQL - MAX() SQL - Insert Into Select SQL - Insert Multiple Values In Table SQL - Referential Integrity SQL - Not Null Constraint SQL - Unique Constraint SQL - Primary Key Constraint SQL - Foreign Key Constraint SQL - Default Constraint SQL - Check Constraint

PL/SQL Introduction
PL/SQL stands for Procedural Language/SQL. PL/SQL is Oracle's Procedural Language extension to SQL. PL/SQL expands SQL by adding constructs found in procedural languages, resulting in a structural language that is more powerful than SQL. Basically it runs on the database server, but a few Oracle products such as Developer/2000 also contain a PL/SQL engine that resides on the client. Thus, you can run your PL/SQL code on either the client or the server depending on which is more suitable for the task at hand. Unlike SQL, PL/SQL is procedural, not declarative. A declarative (non-procedural) programming language is a language that allows the programmer to state the task to be accomplished without specifying the procedures needed to carry it out. A Procedural programming language is a language in which programs largely consist of a series of commands to assign values to objects. The basic unit in PL/SQL is a block. All PL/SQL programs are made up of blocks, which can be nested within each other. Typically, each block performs a logical action in the program. PL/SQL is Block Structured. The Syntax of a PL/SQL Block DECLARE Variable_declarations BEGIN Program_code EXCEPTION Exception_handlers END; Below is the basic structure of the PL/SQL program: Set serveroutput on Var1 varchar2(20);

http://sql-plsql.blogspot.com/2007/03/plsql-introduction.html

10/29/2010

Oracle SQL & PL/SQL: PL/SQL Introduction

Page 2 of 3

Begin Var1 := Hello World; Dbms_output.put_line(var1); Exception When others then Dbms_output.put_line(It is an exception); End; / After going through the above code following points are worth remembering: 1. 2. 3. 4. 5. In the declaration section all the variables and constants are defined. In PL/SQL all the errors are handled in the Exception block. Begin and End are mandatory statements indicating begin and end of the PL/SQL Block. Variables and Constants must be declared first before they can be used. The declaration of variables and constants are alike, but constant definitions must contain the keyword CONSTANT and must be assigned a value as part of the definition. Later on any attempts to assign a value to a constant will result in an error message. Values can be assigned to variables directly using the := assignment operator, by way of a SELECT ... INTO statement or When used as OUT or IN OUT parameter from a procedure.

SQL - ROLLUP SQL - CUBE SQL Interview Questions Oracle PL/SQL PL/SQL Introduction PL/SQL Collections PL/SQL Records PL/SQL Table Based Records PL/SQL Programmer Defined Records PL/SQL Cursor Based Records PL/SQL Tables PL/SQL Varrays PL/SQL Nested Tables PL/SQL Triggers PL/SQL Cursors PL/SQL Implicit Cursors PL/SQL Explicit Cursors PL/SQL REF Cursors PL/SQL Cursor For Loop PL/SQL Cursors with Parameters PL/SQL Where Current Of and For Update Examples of PL/SQL Cursors PL/SQL Interview Questions SQL PL/SQL Sitemap

6.

Declaring PL/SQL variables and constants. Example of declaring Variables: Var1 varchar2(100); Hire_date Date; Var2 number default 5; Var3 number not null := 2; Not Null means a value may change but it can never be assigned Null. Var4 varchar2(20) := Null; Var5 varchar2(20) default Null; Example of declaring Constants: Var_constant constant number := 100; Constants cannot be changed. You must initialize constants at the time of declaration. %TYPE and %ROWTYPE %TYPE is used to declare a variable that is of the same type as a specified tables column. Emp_number emp.empno%type; %ROWTYPE is used to declare a record (variable that represents the entire row of a table). Emp_record emp%rowtype; Another example of declaring variable: Declare name varchar2(30); Select ename into name from emp where empno = 20; Begin Null; End; Any DML statements should be after Begin statement;

http://sql-plsql.blogspot.com/2007/03/plsql-introduction.html

10/29/2010

Oracle SQL & PL/SQL: PL/SQL Introduction

Page 3 of 3

Begin Delete from emp where empno = 29; Commit; End;

Home

http://sql-plsql.blogspot.com/2007/03/plsql-introduction.html

10/29/2010

You might also like