|
数值型 number:最高精度38位 日期时间型 date:精确到ss timestamp:秒值精确到小数点后6位 函数 sysdate,systimestamp返回系统当前日期,时间和时区。 更改时间的显示 alter session set nls_date_language=’american’; alter session set nls_date_format=’yyyy-mm-dd’; Oracle中的伪列 像一个表列,但没有存储在表中 伪列可以查询,但不能插入、更新和修改它们的值 常用的伪列:rowid和rownum rowid:表中行的存储地址,可唯一标示数据库中的某一行,可以使用该列快速定位表中的行。 rownum:查询返回结果集中的行的序号,可以使用它来限制查询返回的行数。 3.数据定义语言 用于操作表的命令 create table alter table truncate table drop table 修改表的命令 alter table stu_table rename to stu_tbl;--修改表名 alter table stu_tbl rename column stu_sex to sex;--修改列名 alter table stu_tbl add (stu_age number);--添加新列 alter table stu_tbl drop(sex);--删除列 alter table stu_tbl modify(stu_sex varchar2(2));--更改列的数据类型 alter table stu_tbl add constraint pk_stu_tbl primary key(id);--添加约束 4.数据操纵语言 select,insert 利用现有的表创建表 create table stu_tbl_log as select id,stu_name,stu_age from stu_tbl;-- 选择无重复的行 select distinct stu_name from stu_tbl;-- 插入来自其他表中的记录 insert into stu_tbl_log select id,stu_age from stu_tbl; 5.数据控制语言 grant,revoke 6.事务控制语言 commit,rollback 7.SQL操作符 算术操作符:L+-*/ 比较操作符:L=,!=,<>,>,<,>=,<=,between-and,in,like,is null等 逻辑操作符:Land,or,not 集合操作符:Lunion,union all,intersect,minus 连接操作符:L|| 示例中stu_tbl_log中的数据如下: ID STU_NAME STU_AGE ---------- -------------------- ---------- 1000 李华 20 1001 accp 20 1003 nimda 3 stu_tbl中的数据如下: ID STU_NAME ST STU_AGE ---------- -------------------- -- ---------- 1000 李华 男 20 1001 accp 男 20 1002 admin 男 30 示例: select (3+2)/2 from dual;--算术操作符,结果:2.5 select * from stu_tbl where stu_age>=20;--比较操作符 select * from stu_tbl where stu_name like ‘%a%‘;--比较操作符:like select * from stu_tbl where stu_name like ‘a___‘;--比较操作符:like select * from stu_tbl where stu_age in(20,30);--比较操作符:in select * from stu_tbl where stu_age between 20 and 30;--比较操作符:between select stu_name from stu_tbl union all select stu_name from stu_tbl_log;--集合操作符:union all,测试结果具体如下: STU_NAME ----------- 李华 accp admin 李华 accp nimda
已选择6行。 select stu_name from stu_tbl union select stu_name from stu_tbl_log;--集合操作符:union,测试结果具体如下: STU_NAME --------- accp admin nimda 李华 select stu_name from stu_tbl intersect select stu_name from stu_tbl_log;--集合操作符:intersect,测试结具体如下: STU_NAME ---------- accp 李华 select stu_name from stu_tbl minus select stu_name from stu_tbl_log;--集合操作符:minus,测试结果如下: STU_NAME ---------- Admin 从中可以看出: minus是获取第一张表独有的数据 intersect是获取两张表中都有的数据 union是整合两张表的数据,都有的只显示一次 union all是纯粹的两张表数据整合 select id,stu_name||‘ ‘||stu_sex as name_sex,stu_age from stu_tbl;--连接操作符||,测试结果具体如下: ID NAME_SEX STU_AGE ---------- ----------------------- ---------- 1000 李华 男 20 1001 accp 男 20 1002 admin 男 30
(编辑:PHP编程网 - 湛江站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|