zoukankan      html  css  js  c++  java
  • Chapter 02 Declaring PL/SQL Variables 01

    Objectives

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

    • Recognize valid and invalid identifies.
    • List the uses of variables.
    • Declare and initialize variables.
    • List and descible various data types.
    • Indentify the benefits of using the %TYPE attribute.
    • Declare,use and print bind variables. 

    Use of Vaiables

    Variables can be used for:

    • Temporary storage of data
    • Manipulation of stored values
    • Reusability
    Demo
    DECLARE
    v_fname  VARCHAR2(20);
    v_deptno NUMBER(4);
    BEGIN
    
            SELECT first_name,department_id INTO v_fname,v_deptno
            FROM employees
            WHERE employee_id = 100;
    
            DBMS_OUTPUT.PUT_LINE('The first_name is ' || v_fname);
            DBMS_OUTPUT.PUT_LINE('The department_no is ' || v_deptno);
    
    END;
    /
    
    SQL> @variables.sql
    The first_name is Steven
    The department_no is 90
    
    PL/SQL procedure successfully completed.

    Requirements for Variable Names

    A variable name:

    • Must start with a letter
    • Can include letters or numbers
    • Can include special characters(such as $,_,and #)
    • Must conatin no more than 30 characters
    • Must not include reserverd words

    Handing Variables in PL/SQL

    Variables are:

    • Declared and initialized in the declarative section
    • Used and assigned new values in the executable section
    • Passed as parameters to PL/SQL subprograms
    • Used to hold the output of a PL/SQL subprogram

    Declaring an Initializing PL/SQL Variables

    • Syntax:
    identifier [CONSTRANT] datetype [NOT NULL] [:= | DEFATULT expr];
    • Examples:
    DECLARE
        v_hiredate    DATE;
        v_deptno      NUMBER(2)    NOT NULL    := 10;
        v_location    VARCHAR2(13)             := 'Atlanta';
        v_comm        CONSTANT NUMBER          := 1400;
    Demo 01
    DECLARE
            v_myName        VARCHAR2(20);
    BEGIN
            DBMS_OUTPUT.PUT_LINE('My name is :' || v_myName);
            v_myName := 'ArcerZhang';
            DBMS_OUTPUT.PUT_LINE('My name is :' || v_myName);
    END;
    /
    Demo 02
    DECLARE
            v_myName        VARCHAR2(20) := 'John';
    BEGIN
            v_myName := 'Steven';
            DBMS_OUTPUT.PUT_LINE('My name is : ' || v_myName);
    END;
    /
  • 相关阅读:
    zoj 3697(模拟+dp)
    hdu 2444(二分图最大匹配)
    基础建设者的悲歌
    ANDROID 常用音乐软件 歌曲存放位置
    Winform 类似于WINDOWS的选择文件夹对话框
    我听到过的一个精彩的软件纠错故事
    cs类文件中输出脚本的方法
    NeatUpload的安装使用
    asp.net获取系统已安装字体的方法
    (转载)你真的了解分层架构吗?——写给被PetShop"毒害"的朋友们
  • 原文地址:https://www.cnblogs.com/arcer/p/3027999.html
Copyright © 2011-2022 走看看