易截截图软件、单文件、免安装、纯绿色、仅160KB

北大青鸟oracle学习笔记17

数据类型使用
1.声明:
a.格式:Variable_name [constant] databyte [not null] [:=default expression]
b.变量与常量声明基本一致,使用constant声明的为常量,不使用为变量,并且赋值只能在DECLARE区域赋值;
c.使用%TYPE和%ROWTYPE声明可以使变量的类型与表中字段类型或整个记录类型保持一致;
2.赋值:
a.使用“:=”赋值;
b.使用“select into” 或 “fetch into”赋值;
c.使用“&str”从键盘输入赋值;
DECLARE
eno VARCHAR(10):='0';
ename VARCHAR(20);
isValid BOOLEAN := TRUE;
empName CONSTANT VARCHAR(10):='pf';
BEGIN
eno:='1';
ename:='name1';
dbms_output.put_line('eno:'||eno);
dbms_output.put_line('ename:'||ename);
-- dbms_output.put_line('isValid:'||to_char(isValid));
dbms_output.put_line('empName:'||empName);

select stu_id, stu_name into eno,ename from student where stu_id = '1';
dbms_output.put_line('eno:'||eno);
dbms_output.put_line('ename:'||ename);
END; 
匿名pl/sql程序块
无法再oracle中存储,每次执行都需编译
属性
为pl/sql变量和常量引用数据库中的数据类型和对象
变量名 表名.字段名%type  引用数据库列
变量名 表名%rowtype      代表表中的行 访问时采用 变量名.表中列名
declare
stuid student.stu_id%type;
stuname student.stu_name%type;
sturow student%rowtype;
begin
select stu_id,stu_name into stuid,stuname from student where stu_id = '1';
select * into sturow from student where stu_id = '2';
dbms_output.put_line('stuid:'||stuid);
dbms_output.put_line('stuname:'||stuname);
dbms_output.put_line('sturow stu_id:'||sturow.stu_id);
dbms_output.put_line('sturow stu_name:'||sturow.stu_name);
end; 
逻辑比较
数值比较
运算符
含义
示例
=
等于
a = 123
!=
不等于
c != 123

小于
a < 1

大于
b > 4
<=
小于等于
a <= b
>=
大于等于
a >= c
字符比较
运算符
含义
示例
=
等于
name = 'pf'
!=
不等于
name != 'pf'

字母顺序排在其前
n


相关文档:

在Oracle中使用自动递增列

在Oracle中使用自动递增列
Oracle 沒有類似 MS-SQL 可以直接修改欄位屬性,設定成自動編號欄位,所以我們必須透過 Sequence 物件的 nextval 方法,取得其下一個值,然後將此值新增至 TABLE 中,製造出有自動編 ......

oracle 之系统表 点滴 积累

查看正在执行的sql语句
SELECT osuser, username, sql_text from v$session a, v$sqltext b where a.sql_address =b.address order by address, piece;
捕捉运行很久的SQL
 select username,sid,opname, round(sofar*100 / totalwork,0) || '%' as progress, time_remaining,sql_text from v$session_longops , v$ ......

Oracle高级技巧

1.在删除一个表中的全部数据时,须使用TRUNCATE TABLE 表名;因为用DROP TABLE,DELETE * from 表名时,TABLESPACE表空间该表的占用空间并未释放,反复几次DROP,DELETE操作后,该TABLESPACE上百兆的空间就被耗光了。
  
  2.having 子句的用法
  
  having 子句对 group by 子句所确定的行组进行控制,having 子 ......

oracle里的extend的意思

oracle里的extend的意思
扩展已知的数组空间,例:
DECLARE
TYPE CourseList IS TABLE OF VARCHAR2(10);
courses CourseList;
BEGIN
-- 初始化数组元素,大小为3
courses := CourseList( 'Biol 4412 ', 'Psyc 3112 ', 'Anth 3001 ');
-- 为数组增加一个元素,数组大小为4,末尾的元素为NULL
courses.EXTEN ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号