服务器之家

服务器之家 > 正文

Oracle文本函数简介

时间:2019-12-20 15:23     来源/作者:lijiao

Oracle文本函数使我们常用的函数,下面就为您介绍几种Oracle文本函数的用法,供您参考学习,希望可以让您对Oracle文本函数有更深的认识。

(1)UPPER、LOWER和INITCAP

这三个函数更改提供给它们的文体的大小写。

 

?
1
2
3
4
5
select upper(product_name) from product;
 
select lower(product_name) from product;
 
select initcap(product_name) from product;

函数INITCAP能够整理杂乱的文本,如下:

?
1
select initcap(‘this TEXT hAd UNpredictABLE caSE') from dual;


(2)LENGTH

求数据库列中的数据所占的长度。

 

?
1
2
3
4
5
select product_name,length(product_name) name_length
 
from product
 
order by product_name;

(3)SUBSTR

取子串,格式为:

SUBSTR(源字符串,起始位置,子串长度);

 

?
1
2
3
4
5
6
7
create table item_test(item_id char(20),item_desc char(25));
 
insert into item_test values(‘LA-101','Can, Small');
 
insert into item_test values(‘LA-102','Bottle, Small');
 
insert into item_test values(‘LA-103','Bottle, Large');

取编号:

 

?
1
2
3
select substr(item_id,4,3) item_num,item_desc
 
from item_test;

(4)INSTR

确定子串在字符串中的位置,格式如下:

INSTR(源字符串,要查找的字符串,查找起始位置)

?
1
select instr(‘this is line one','line',1) from dual;

其返回值为子串在源字符串中从起始位置开始第一次出现的位置。上面例子的返回值为9。

 

?
1
select item_desc , instr(item_desc,',',1)from item_test;

(5)LTRIM、RTRIM和TRIM

去除字符串左边的空格、去除字符串右边的空格、去除字符串左右两边的空格。

 

?
1
select ltrim(‘ abc def ‘) from dual;

以上就是Oracle文本函数的用法介绍,希望对大家的学习有所帮助。

标签:

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
配置IIS网站web服务器的安全策略配置解决方案
配置IIS网站web服务器的安全策略配置解决方案 2019-05-23
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
Nginx服务器究竟是怎么执行PHP项目
Nginx服务器究竟是怎么执行PHP项目 2019-05-24
返回顶部