PL/SQL2009.4.21

//author 满晨晨
//time 2009 4 21上午

sql>conn scott/tiger/@oracle
sql>ed 0421sql
upper() 全规范为大写
lower() 全规范为小写

set serveroutput on
declare
    type deptrec//部门表  is record   声明记录类型  部分字段
   (
        v_deptno dept.deptno%type,
        v_dname  dept.dname%type
    );
    deptrec1 deptrec;
begin
   select deptno,dname into  deptrec1 from dept where deptno=30;
   dbms_output.put_line(deptrec1.v_dname);
   dbms_output.put_line(deptrec1.v_deptno);
end;

 


create table t_emp
as
select * from scott.emp
where 1=1 全部复制过来
      
%rowtype

可以使变量获得字段的数据类型 使用%rowtype可以使变量获得整个记录的数据类型
比较两者不同 :变量名 数据表名.列名%type,变量名 数据表名%rowtpye
定义名字为mytable的复合类型变量,与testtable数据表结构相同
set serveroutput on
declare
   mytable testtable%rowtype;
begin
   select * into mytable from tempuser.testtable
where recordnumber=88;
doms_output_put.line(mytable.currentdate);

end;

表类型变量用来表示一维或多维数组

一维表类型

type 表类型 is table of 类型 index by binary_integer;
表变量名 表类型 ; //使用表类型变量
类型可以使前面的类型的定义 ,index by binary_integer子句代表以符号整数为索引,这一访问表类型变量中的数据方法就是


‘表变量名(索引符号整数)’

sqlplusw /nogon

declare
type tabletype1 is table of varchar2(8) index by binary_integer;
type tabletpye2 is table of tempuser.testtable.recordnumber%tpye index  by binary_integer;
table1 tabletype1;
table2 tabletype2;
begin
 table1(1):='大学';
 table1(2):='大专';
  table2(1):=88;
  table2(2):=55;
dbms_output.put_line(table1(1)||table2(1));
dbms_output.put_line(table1(2)||table2(2));

  end;
||使连接字符串的运算符


控制结构
条件结构 if switch
循环结构 loop exit for while
循环结构 goto  null
作业

count first next lasy priror 函数

<1000 显示工资太低
>1000 <3000 显示工资中等
>3000 显示工资较高

实践 从客户端输入一字符
如果字符为A 输出信息‘A的标准是90分以上’
如果字符为B 输出信息‘B的标准是80分至90分之间’
如果字符为C输出信息‘C的标准是60之80分之间’
否则 输出信息 不及格

declare
 v_empno emp.empno%type:=&empno;
 v_ename emp.ename%type;
 begin
select empno, ename into v_empno,v_ename from emp where empno=v_empno;
dbms_output.put_line(v_ename);

exception
 when others then
 dbms_output.put_line(' your empno is null,ename is null');
end;
declare
   v_grade char(1):=upper(&p_grade);
   v_result varchar2(20);

begin
 v_result:=
  case v_grade
  when 'A' then '90 分以上'
  when 'B' then '80分到90分之间'
  when 'C' then '60分到80分之间'
  else '不及格'
end;
dbms_output.put_line('grade'||v_grade||'result'||v_result);
end;

declare
v_name emp.ename%type;
v_sal emp.sal%tpye:=&sal;//显示输入sal的值 &为输入接入点赋给v_sal
v_char varchar2(30);
begin
   select ename,sal into v_name,v_sal from emp  where sal=v_sal;
   if v_sal<1000 then
   v_char:='sal is low';
  elsif  v_sal>=1000 and v_sal<=3000 then
v_char:='sal is normal';
else   v_sal>3000 then
v_char:='sal is high';
else v_char:='lost data';
end if;
dbms_output.put_line('name'||v_name||'sal'||v_char);
end;

 


if then
else
elsif then
end if


case selector
when then
when then
end case;


loop
执行语句
exit when 退出条件

end loop

 


for count in 1..10000  loop
执行语句
end loop;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值