您的位置:首页 > 数据库 > Oracle

oracle学习总结---record

2017-01-18 20:57 309 查看
--记录变量学习

--基本语法

--type 记录型变量的名称 is record (

--变量名 变量类型,

--变量名 变量类型。

--);

--实例:创建一个过程,用于参数出入员工编号,运用记录型变量打印员工姓名和薪资

create or replace procedure pro2(v_in_empno in emp.empno%type)

is 

--定义记录型变量

type recordNo is record (

v_name emp.ename%type,

v_sal emp.sal%type

);

rn recordNo;

begin

  

select ename,sal into rn.v_name,rn.v_sal from emp where empno = v_in_empno;

dbms_output.put_line('name='||rn.v_name || '  sal ='||rn.v_sal);

  end;

  

  

--创建块,用于调用过程

declare

begin

  pro2(7839);

  end;

  

  

  

--pl/sql表变量学习

--基本语法

--type pl/sql表变量类型 is table of 参考字段 index by binary_integer;

--实例:创建一个幻术用于参数输入员工编号,用pl/sql变量参数答应员工名。

create or replace function fun1(v_in_empno in emp.empno%type) 

return emp.ename%type

is

--定义pl/sql表类型

type chen_table is table of emp.ename%type index by binary_integer;

--定义pl/sql表变量

v_chen_table chen_table;

begin

  

select ename into v_chen_table(1) from emp where empno = v_in_empno;

dbms_output.put_line('name is ' ||v_chen_table(1));

return v_chen_table(1);

end;

--创建一个块,用于创建调用fun1

declare

v_name emp.ename%type;

begin

  v_name := fun1(7369);

  end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 函数