PL/SQL编程

1、基本块结构
DECLARE
         /* Declarative section - PL/SQL variables, types, cursors,
            and local subprograms go here. */
         BEGIN
             /* Executable section - procedural and SQL statements go here.
               This is the main section of the block and the only one
                that is required. */
         EXCEPTION
              /* Exception-handling section - error-handling statements go
                  here. */
          END;
2、变量定义
DECLARE
    v_name  varchar(20);     --姓名
    v_id         integer;            --编号
BEGIN
    BEGIN
         select name, id into v_name, v_id
         from t_staff
         where rownum < 2;
    EXCEPTION
        WHEN OTHERS THEN
             NULL;
    END;    
END;
引用
create table t_staff
(
     id integer primary key not null,
     name varchar(20) not null
)


如果定义的字符型变量,如果只和具体的表字段相关联,最好定义为以下形式:
v_name t_staff.name%type;

你可能感兴趣的:(pl/sql)