Chapter -01 Introduction to PL/SQL

Objectives

After completing this lesson,you should be able to do the following:

  • Explain the need for PL/SQL
  • Explain the benefits of PL/SQL
  • Indentify the different types of PL/SQL blocks
  • Out messages in PL/SQL

About PL/SQL

  • Stands for "Procedural Language extension to SQL".
  • Is Oracle Corporation`s standard data access language for relatinal databases.
  • Seamlessly integrates procedureal constructs with SQL.
  • Provides a block structure for executable units of code.
    • Maintenance of code is moade easier such a well-defined structure.
  • Provides procedure constructs such as:
    • -Variables,constants,and data types
    • -Control structures such as conditional statements and loops
    • -Reusable program units that are written once and executed mamy times.

PL/SQL Environment

 

Benefits of PL/SQL

  • Integration of procedural constructs with SQL
  • Improved performance   

 

Select Specific Columns

  • Modularized program development
  • Integration with Oracle tools
  • Portablity
  • Exception handing

PL/SQL Block Structure

  • DECLARE(optional)
    • -Variables,cursors,user-defined exceptions
  • BEGIN(mandatory)
    • -SQL statements
    • -PL/SQL statements
  • EXCEPTION(optional)
    • -Actions to perform when erros occur
  • END; (mandatory)

 

Block Types

  • Anonymons
[DECLARE]


BEGIN

    --statements    

[EXCEPTION]

END;
  • Procedure
PROCEDURE name
IS


BEGIN

    --statements

[EXCEPTION]

END;
  • Function
FUNCTION name
RETURN datatype
IS
BEGIN
    --statements

    RETURN value;

END;
  • Procedure 与 Function的区别
    • Procedure不需要有返回值,Function一定要有返回值.
    • Anonymous不会存储在Oracle Database中,而Procedure与Function则存储在Oracle Database.

Program Constructs

Create an Anonymous Block

Simple Demo With PL/SQL
 1 DECLARE
 2         v_fname VARCHAR2(20);
 3 BEGIN
 4         SELECT first_name INTO v_fname
 5         FROM employees
 6         WHERE employee_id = 100;
 7         
 8         DBMS_OUTPUT.PUT_LINE(v_fname);
 9 
10 END;
Execute Results
SQL> l
  1  DECLARE
  2     v_fname VARCHAR2(20);
  3  BEGIN
  4     SELECT first_name INTO v_fname
  5     FROM employees
  6     WHERE employee_id = 100;
  7
  8     DBMS_OUTPUT.PUT_LINE(v_fname);
  9
 10* END;
SQL> /
Steven

PL/SQL procedure successfully completed.

SUMMARY

In this lesson,you should have learned how to:

  • Interate SQL statement with PL/SQL program constructs
  • Descibe the benefits of PL/SQL
  • Differentiate between PL/SQL block typs
  • Output messages in PL/SQL

 

 

转载于:https://www.cnblogs.com/arcer/archive/2013/04/18/3027986.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值