0
点赞
收藏
分享

微信扫一扫

oracle数据类型


1、基本数据类型(一般用来创建表、函数、PL/SQL)和PL/SQL数据类型(创建过程 PL/SQL)

2、char(4)    12   4bytes

     varchar2(4)   12   2bytes

3、CLOB  4gb   文本大对象

NUMBER(N,M)   N:整数位加小数位位数    M:小数位数

BLOB   二进制大对象   4g  存音频、视频

4、to_date

insert into emp (empno,ename,hiredate) values(1009,'张三丰',to_date('2015年02月03日','yyyy'"年"MM"月"dd"日"'));

insert into emp (empno,ename,hiredate) values(1009,'张三丰',to_date('2015-02-03','yyyy-MM-dd'));

5、英文(半角)单引号引起来的内容为SQL文本常量,如果其内容中包含单引号字符,则需要在常量中使用两个连续性的单引号进行转义。

    在SELECT语句中,可以使用别名来重命名目标表,以及查询结果中的字段(或表达式),以增强可读性。如果别名中使用特殊字符、或者是强制其大小写敏感,则需要使用双引号将别名括起来。

6、substr(char,start[,size])

截取指定字符串的子串并返回。参数char用于指定源字符串,start用于指定子串的起始位置(首字符下标为1),size用于指定子串长度。

select substr('hello world',4,3) from dual;//lo 

查询出所有姓张的员工信息

select * from emp where substr( ename , 1 , 1 ) = '张';

查询出公司里面三个字的员工信息
select * from emp where length(ename) = 3;

instr()返回指定的子串在母串中出现的位置

查询出所有姓张的员工信息
select * from emp where instr( ename , '张' ) = 1;
select lpad(ename,10,' ') , job from emp;//左侧填充字符,将之扩充到指定的长度
select  trim('    张三丰    ') from dual;
avg--求平均值
select  round(avg(sal),2)  from emp; --求公司所有员工的平均工资
select last_day(sysdate) from dual; --求这一个月的最后一天的日期
将一个数据类型的数据转换成字符串类型( 日期,数值)
select   to_char( sysdate , 'yyyy-MM-dd')   from dual;
求1980年入职的员工
select * from emp where to_char(hiredate,'yyyy') = '1980'

将数值类型转换成字符串类型
select to_char( 8956.265 , '999,999,999.99' ) from dual;
select to_char( 8956.265 , 'L999,999,999.99' ) from dual;

将字符串转换成数值
select to_number( '¥8,956.27'  , 'L999,999,999.99') from dual;

NVL( express , 值 ) 用于将空值转换成指定的具体值。先计算参数、表达式exp1d的值,如果其值bull,则返回exp2的值,否则返回exp1的值。

select empno,ename,sal,comm,sal+nvl(comm,0) from emp;
NVL2( express , 值1 ,值2 ) ==> 用于实现条件表达式功能。如果这个表达式为NULL,则返回值2,否则返回值1
 

7、decode(col|expression,search1,result1[,search2,result2,......][,default])

select empno,ename,sal,decode(deptno,10,'财务部',

                          20,'研发部',

                          30,'销售部',

                          '未知部门') AS 部门

from emp;

 

举报

相关推荐

0 条评论