Mr.Abner

博客园 首页 联系 订阅 管理
1、concat
CONCAT(字串1, 字串2, 字串3, ...): 将字串1、字串2、字串3,等字串连在一起。
例如:
Geography 表格
region_name     store_name
East        Boston
East           New York
West         Los Angeles
West         San Diego

例子1:

MySQL/Oracle:
SELECT CONCAT(region_name,store_name) FROM Geography
WHERE store_name = 'Boston';

结果:

'EastBoston'
 

 
2、oracel中to_date函数的用法 ,用来查询时间段。
sql="select * from managedate where  aaa_date>="&2005-11-1&"and aaa_date<="&2005-11-20&"
 
to_date('2011-8-22 09:00:00','yyyy-mm-dd hh24:mi:ss')
 

3、trunc函数的用法
--Oracle trunc()函数的用法
/**************日期********************/
1.select trunc(sysdate) from dual --2013-01-06 今天的日期为2013-01-06
2.select trunc(sysdate, 'mm') from dual --2013-01-01 返回当月第一天.
3.select trunc(sysdate,'yy') from dual --2013-01-01 返回当年第一天
4.select trunc(sysdate,'dd') from dual --2013-01-06 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual --2013-01-01 返回当年第一天
6.select trunc(sysdate,'d') from dual --2013-01-06 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual --2013-01-06 17:00:00 当前时间为17:35
8.select trunc(sysdate, 'mi') from dual --2013-01-06 17:35:00 TRUNC()函数没有秒的精确
/***************数字********************/
/*
TRUNC(number,num_digits)
Number 需要截尾取整的数字。
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual --123.4
12.select trunc(123.458,-1) from dual --120
13.select trunc(123.458,-4) from dual --0
14.select trunc(123.458,4) from dual --123.458
15.select trunc(123) from dual --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120
 

4、

在Oracle/PLSQL中, sign 函数返回一个数字的正负标志.

语法如下:sign( number )

number 要测试标志的数字.

If number < 0, then sign returns -1.

If number = 0, then sign returns 0.

If number > 0, then sign returns 1
 

5、查询sql字段长度
length()函数。
 
 

 
6、decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)的理解如下:

if (条件==值1)

 then    

return(翻译值1)

elsif (条件==值2)

then    

return(翻译值2)    

......

elsif (条件==值n)

 then    

return(翻译值n)

else    

return(缺省值)

end if

 
注:其中缺省值可以是你要选择的column name 本身,也可以是你想定义的其他值,比如Other等;
 

5、Lpad()函数
lpad函数将左边的字符串填充一些特定的字符
1.语法格式如下:  
     lpad(string,n,[pad_string])
参数说明:
     string:    字符串或者列名。
     n:         字符串总长度。如果这个值比原字符串的长度还要短,lpad函数将会把字符串截取成从左到右的n个字符;
     pad_string:要填充的字符串,默认为填充空格。
2.例子
select lpad('tech',7) from dual;
--将返回'   tech'
select lpad('tech', 2) from dual;
--将返回'te'
select lpad('tech', 8, '0') from dual;
--将返回'0000tech'
select empno,lpad(ename,7) as ename from emp;

--将返回:

 
EMPNO ENAME
posted on 2016-09-09 09:34  Mr.abner  阅读(1058)  评论(0编辑  收藏  举报