基础查询及常用函数
1.sql 语句不区分大小写字;
2.oracle9i数据类型;
| 名称 | 含义 |
| Char | 用于描述定长的字符型数据,长度<=2000字节 |
| varchar2 | 用于描述变长的字符型数据,长度<=4000字节 |
| nchar | 用来存储Unicode字符集的定长字符型数据,长度<=1000字节 |
| nvarchar2 | 用来存储Unicode字符集的变长字符型数据,长度<=1000字节 |
| number | 用来存储整型或者浮点型数值 |
| Date | 用来存储日期数据 |
| Long | 用来存储最大长度为2GB的变长字符数据 |
| Raw | 用来存储非结构化数据的变长字符数据,长度<=2000字节 |
| Long raw | 用来存储非结构化数据的变长字符数据,长度<=2GB |
| rowid | 用来存储表中列的物理地址的二进制数据,占用固定的10个字节 |
| Blob | 用来存储多达4GB的非结构化的二进制数据 |
| Clob | 用来存储多达4GB的字符数据 |
| nclob | 用来存储多达4GB的Unicode字符数据 |
| Bfile | 用来把非结构化的二进制数据存储在数据库以外的操作系统文件中 |
| urowid | 用来存储表示任何类型列地址的二进制数据 |
| float | 用来存储浮点数 |
3./*--用""来界定列名称--*/
select ename as "ename" from emp
4./*--用||来进行字符串连接 --*/
select empno||ename as "empno=>ename" from emp
5./*--用distinct去除以某列的重复记录,若为多列,无作用--*/
select distinct e.sex from emp e
6./*-- between...and (包括两端点值,是一个连续区间取值)--*/
select * from emp e where e.sal between 3200 and 5000
7./*-- in (是分散区间取值) --*/
select * from emp e where e.sal in(3200,4500)
8./*-- like --*/
select * from emp e where e.ename like '_h%'
9./*-- order by 默认升序-- 先以empno进行升序排列,然后以sal进行降序排列*/
select * from emp e order by e.empno , e.sal desc
10.函数(单行,多行)
/*-- 字符串函数 --*/
/*-- 大小写转换 lower全部转换为小写,upper全部转换为大写,initcap将首字母转换为大写--*/
select lower(ename),upper(ename),initcap(ename) from emp
/*-- 字符串连接操作 --*/
select concat(ename,birthday) from emp
/*-- substr --注意:合法字符,英文字母,汉字每个都当1处理*/
select substr(ename,1,3) from emp /*-- 从左边开始取值 --*/
select substr(ename,-3,3) from emp /*-- 从右边开始取值,取不到值,返回为null --*/
/*-- lpad左填充,rpad右填充,达到一个固定的长度 --*/
select lpad(sal,10,'*'),rpad(sal,10,'*') from emp /*-- 填充以后失去了数据精度 --*/
/*-- 数字函数 round四舍五入,trunc截取,mod取模--*/
select round(sal,1),trunc(sal,1) from emp e
select mod(1600,300) from dual
select round(45.923,2),round(45.923,0),round(45.923,-1) from dual
select trunc(45.923,2),trunc(45.923,0),trunc(45.923,-1) from dual
/*-- 日期函数 --*/
select (sysdate-birthday)/7 as weeks from emp
select months_between(sysdate,birthday) as months from emp
select add_months(sysdate,2) from dual
/*--select next_day('09-01-2008','FRIDAY') from dual--*/
select last_day(sysdate) from dual
/*-- 类型转换函数 --*/
select to_char(e.birthday,'yyyy-mm-dd') from emp e
select to_char(e.birthday,'year-month-day') from emp e
select to_date('2008-01-09','yyyy-mm-dd') from dual
select to_number('200.25') from dual
select to_char(e.sal,'$0000.00') from emp e
select to_char(e.sal,'$9999.99') from emp e
select to_char(e.sal,'$9,999.99') from emp e /*--千位符--*/
select to_char(e.sal,'l9999.99') from emp e /*-- 本地货币符号 --*/
/*-- 通用函数 --*/
select nvl(e.memo,'unknow') from emp e
select nvl2(e.memo,'有','没有') from emp e /*--相当于一个三元运算符 --*/
select coalesce(e.empno,e.deptno,111) from emp e /*-- 可以为某字段中的值 --*/
/*-- case...when --*/
select e.ename,
case e.sal when 5000.78 then 1.1*e.sal
when 3200.23 then 1.2*e.sal
else e.sal
end as sal
from emp e
/*-- decode --*/
select e.ename,
decode( e.sal, 5000.78, 1.1*e.sal,
3200.23, 1.2*e.sal,
e.sal ) as sal
from emp e
发表评论
- 浏览: 6132 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
我的相册
共 1 张
最近加入圈子
最新评论
-
java.util.Properties类的 ...
[/color]]
-- by devin -
java导入导出excel操作(j ...
请问你到Linux中使用jxl处理Excel文件了吗?不清楚怎么使用不了。:(
-- by xiaoxiao000_000 -
SQL Server中死锁的原因及 ...
长知识,原来一直没用过with这个东西,看来要学习了;
-- by Jatula






评论排行榜