欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle中的pl/sql编程的数据类型

程序员文章站 2024-01-22 09:56:46
...

pl编程的数据类型:1.标量类型 (scalar)2.复合类型 (composite)3.参照类型 (reference)4.lob(large object)--------------

pl编程的数据类型:
1.标量类型 (scalar)
2.复合类型 (composite)
3.参照类型 (reference)
4.lob(large object)
----------------------------------------------------------
定义标量的案例
1.定义一个变长字符串
v_ename varchar2(10)
2.定义一个小数 范围-9999.99到9999.99
v_sal number(6,2)
3.定义一个小数并给一个初始值为5.4 := 是pl/sql的赋值号
v_sal2 number(6,2):=5.4
4.定义一个日期类型的数据
v_hiredate date;
5.定义一个布尔变量,不能为空,,初始值为false
v_valid boolean not null default false;
----------------------------------------------------------

复合变量
用于存放多个值的变量
1.pl/sql 记录
2.pl/sql 表
3.嵌套表
4.varray

----------------------------------------------------------

参照变量
分为:游标变量和对象变量

案例1
请使用pl/sql编写一个块,可以输入部门号并显示所有

declare
--定义一个游标类型
type chenchuang_emp_cursor is ref cursor;
--定义一个游标变量
test_cursor chenchuang_emp_cursor
--定义变量
v_ename emp.name%type
v_sal emp.sal%type
begin
--执行
--把test_cursor 和一个select结合
open testr_cursor for select ename,sal from emp where

deptno=&no;
--循环取出
loop
fetch test_cursor into v_ename,v_sal;
--判断testr_cursor是否为空
exit when testr_cursor%notfound;
dbms_output.put_line('名字'||v_name||'工资'||v_sal);
end loop;

end;

Oracle中的pl/sql编程的数据类型