zoukankan      html  css  js  c++  java
  • test4

     
    create or replace procedure testp
    is
    begin
    dbms_output.put_line('aaaa');
    end;
    /
     
    declare
    i number(2) :=10;
    ena emp.ename%type;
    begin
    dbms_output.put_line(i);
    select ename into ena from emp where empno=1002;
    dbms_output.put_line(ena);
    end;
    /
     
    存储一整条(一行)记录:
    declare
    i number(2) :=10;
    ena emp.ename%type;
    emprow emp%rowtype;
    begin
    dbms_output.put_line(i);
    select ename into ena from emp where empno=1002;
    dbms_output.put_line(ena);
    select * into emprow from emp where empno=1002;
    dbms_o
    utput.put_line(emprow.ename || '工作为' || emprow.job);
    end;
    /
     
    10
    黛绮丝
    黛绮丝工作为销售员
    PL/SQL procedure successfully completed.
     
    ---- 输出emp表中所有员工姓名
     
    declare
    cursor c1 is select * from emp;
    emprow emp%rowtype;
    begin
    open c1;
    loop
    fetch c1 into emprow;
    exit when c1%notfound;
    dbms_output.put_line(emprow.ename);
    end loop;
    close c1;
    end;
    /
     
    declare
    cursor c2(eno emp.deptno%type)
    is select empno from emp where deptno = eno;
    en emp.empno%type;
    begin
    open c2(10);
    loop
    fetch c2 into en;
    exit when c2%notfound;
    update emp set sal=sal+100 where empno=en;
    commit;
    end loop;
    close c2;
    end;
    /
    执行后查询:
    select sal from emp where deptno =10;
     
    // 存储过程:
    create or replace procedure p1(eno emp.empno%type)
    is
    begin
    update emp set sal=sal+100 where empno=eno;
    commit;
    end;
    /
     
    select sal from emp where empno = 1002;
    --- 测试存储过程调用:
    declare
     
    begin
    p1(1002);
    end;
    /
    select * from emp where empno = 1002;

    存储函数:

    create or replace function f_diff(eno emp.empno%type) return number

    is
    s number(10);
    begin
    select sal*12+nvl(comm, 0) into s from emp where empno = eno;
    return s;
    end;
    /
    测试
    declare
    s number(10);
    begin
    s :=f_diff(1002);
    dbms_output.put_line(s);
    end;
    /

  • 相关阅读:
    实验三
    第六七章读后感
    0415评论
    0414-复利计算
    实验8 201306114104彭得源
    实验7 201306114104彭得源
    实验6 201306114104彭得源
    android实验五201306114104彭得源
    android实验四201306114104彭得源
    实验五 04彭得源
  • 原文地址:https://www.cnblogs.com/mixiu26/p/11410236.html
Copyright © 2011-2022 走看看