oracle -plsqly语句

本文通过实例展示了PL/SQL中变量声明、记录类型及表类型的使用方法,并介绍了如何进行条件判断和选择结构的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

/*开启控制台输出*/
set serveroutput on;
set verify off;

 declare
 v_pi number(3,2):=3.14;
 v_r number(3,2):=2;
  v_area number(4,2);
  begin
  select v_r*v_r*v_pi into v_area from dual;
  dbms_output.put_line('面积是:'||v_area);
  end;

/**与数据库类型相对应*/
   declare
   v_eno  emp3.ename%type;/*和数据库相对应*/
   begin
   select ename into v_eno from emp3 where emp3.empno = &empno;
   dbms_output.put_line('用户名是:'||v_eno);
     exception
    when no_data_found then dbms_output.put_line('输入错误');
   end;

   /*record 类型*/
   declare
   type dept_record_type is record(
   v_deptno dept3.deptno%type,
   v_dname dept3.dname%type,
   v_loc dept3.loc%type
   );
   dept_record dept_record_type;
    begin
    select * into dept_record from dept3 where deptno = &no;
    dbms_output.put_line('部门编号:'||dept_record.v_deptno);
    exception
    when no_data_found then
     dbms_output.put_line('输入有误');
     end;
    
    
    /*table 类型*/
    
    declare
    type dept_table is table of dept3%rowtype index by binary_integer;
    dept_t dept_table;
    begin
    select * into dept_t(0) from dept3 where deptno =&no;
    dbms_output.put_line('部门名称'||dept_t(0).dname);
    end;
    
    
/*判断数据相等与否,直接使用 dept_t(0).dname='ACCOUNTING' */    
/*   if----elsif    else  */
 declare
    type dept_table is table of dept3%rowtype index by binary_integer;
    dept_t dept_table;
    begin
    select * into dept_t(0) from dept3 where deptno =&no;
    if dept_t(0).dname='ACCOUNTING' then dbms_output.put_line('ACCOUNTING');
    elsif
       dept_t(0).dname='RESEARCH' then dbms_output.put_line('RESEARCH');
       elsif
       dept_t(0).dname='SALES' then dbms_output.put_line('SALES');
       elsif
       dept_t(0).dname='OPERATIONS' then dbms_output.put_line('OPERATIONS');
     else
       dbms_output.put_line('输入有误');
    end if;
 end;
 
 /*  case -- when */
 declare
  v_dept emp%rowtype ;
  begin
  select * into v_dept from emp3 where emp3.empno= &empno;
   case v_dept.ename
   when 'WARD'  then dbms_output.put_line('ward');
   when 'FORD'  then dbms_output.put_line('FORD');
   else dbms_output.put_line('不存在该编号');
 
   end case;
 end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值