plsql
pl/sql程序化扩展语言比如往表里面插入100万行数据就需要plsqldeclare 变量声明begin 程序主体exception 例外处理end; 程序结束select 语句必须接into,且结果只允许返回单条记录,为空或为多条均报错标识符就是一个对象,比如constant常量,variable变量,exception异常,cursor游标指针,可以存
pl/sql
程序化扩展语言
比如往表里面插入100万行数据就需要plsql
declare 变量声明
begin 程序主体
exception 例外处理
end; 程序结束
select 语句必须接into,且结果只允许返回单条记录,为空或为多条均报错
标识符就是一个对象,比如constant常量,variable变量,exception异常,cursor游标指针,可以存放多列的变量
program name:procedure,function,package,object type,trigger etc.
label reserved word
一个简单的plsql
create table emp as select * from scott.emp;
declare
ename varchar2(10):='KING';
begin
delete emp where ename=ename;
end;
select * from emp;
但会发现什么都没有,这就是plsql的一个特点:列名优先于变量名,它会先认为是列,所以全部删除了,而不是变量king
variable scope
get varscope.sql
declare
v_sal number(7,2):=80000; 7位数字,两位小数
v_comm number(7,2):=v_sal * 0.2
v_message varchar2(255):='No commission';
begin
declare
v_sal number(7,2):=60000;
v_comm number(7,2):=0;
v_total_comp number(7,2):=v_sal + v_common;
begin
v_message:='From internal block'||v_message;
dbms_output.put_line(v_total_comp);
dbms_output.put_line(v_message); 输出字符类型的就用dbms_output.put_line()
end;
v_message:='From outer block'||v_message;
dbms_output.put_line(v_message);
end;
还有一点需要注意的,下面语句中的commision_pct是奖金,奖金可能是null,所以我们要用到nvl
select avg(salary*nvl(commission_pct,0)) from hr.employees;
还有很多东西。。。在实际工作中,是开发人员应用的,dba用不到,慢慢再看吧。。
更多推荐



所有评论(0)