SQL Fundamentals || Single-Row Functions || 字符函数 character functions
SQL Fundamentals || Single-Row Functions || 字符函数 character functions
SQL Fundamentals || Single-Row Functions || 数字函数number functions
SQL Fundamentals || Single-Row Functions || 日期函数date functions
SQL Fundamentals || Single-Row Functions || 转换函数 Conversion function
SQL Fundamentals || Single-Row Functions || 通用函数 General function
字符函数character functions

接收数据返回具体的字符信息;
|
函数名称 |
描述 |
||||
|
UPPER( 列 | 字符串) |
将字符串的内容全部转大写 SQL> SELECT UPPER('wendy') FROM dual; |
||||
|
LOWER( 列 | 字符串) |
将字符串的内容全部转小写 SQL> SELECT LOWER('WENDY') FROM dual; |
||||
|
INITCAP( 列 | 字符串) |
将字符串的开头首字母大写 SQL> SELECT INITCAP('WENDY') FROM dual; SQL> SELECT ename ,INITCAP(ename) FROM emp; |
||||
|
REPLACE(列 | 字符串, 新的字符串) |
使用新的字符串替换旧的字符串 SELECT ename , REPLACE(ename,'A','_') FROM emp ; |
||||
|
LENGTH(列 | 字符串) |
求出字符串长度 SQL> SELECT * FROM emp WHERE LENGTH(ename)=5; |
||||
|
SUBSTR(列 | 字符串, 开始点 [, 长度]) |
字符串截取 SUBSTR()函数有两种形式:
(1)查询姓名先三位为JAM的 SQL> SELECT * FROM emp WHERE SUBSTR(ename,0,3)='JAM'; (2)查询某部门姓名前三位. SELECT ename , SUBSTR(ename,3) FROM emp WHERE deptno=10 ; (3)查询姓名后三位 SELECT ename,SUBSTR(ename,LENGTH(ename)-2) FROM emp ; SELECT ename,SUBSTR(ename,-3) FROM emp ; 在oracle数据库中,下标都是从1开始,如果设置为0,也会自动将其转换为1. java语言中字符串下表是从0开始,并且java语言中的substring的方法不能设置负数. |
||||
|
ASCII(字符) |
返回与指定字符对应的十进制数字 SQL> SELECT ASCII('A') FROM dual; |
||||
|
CHR(数字) |
给出一个整数,并返回与之对应的字符 SQL> SELECT CHR(100) FROM DUAL; |
||||
|
RPAD(列 | 字符串 , 长度 , 填充字符) LPAD(列 | 字符串 , 长度 , 填充字符) |
在右或左填充指定长度字符串 SELECT LPAD('MLDN' , 10 , '*') LPAD函数使用 , RPAD('MLDN' , 10 , '*') RPAD函数使用 , LPAD(RPAD('MLDN' , 10 , '*') , 16 , '*') 组合使用 FROM dual ; |
||||
|
LTRIM(字符串)、RTRIM(字符串) |
去掉左或右空格 SELECT ' MLDN LiXingHua ' , LTRIM(' MLDN LiXingHua ') FROM dual ; SELECT ' MLDN LiXingHua ' , RTRIM(' MLDN LiXingHua ') FROM dual ; |
||||
|
TRIM(列 | 字符串) |
去掉左右空格 SELECT ' MLDN LiXingHua ' , TRIM(' MLDN LiXingHua ') FROM dual ; 不能去掉中间空格. |
||||
|
INSTR(列 | 字符串, 要查找的字符串 , 开始位置 , 出现位置) |
查找一个子字符串是否在指定的位置上出现 SELECT INSTR('MLDN Java' , 'MLDN') 查找得到 , INSTR('MLDN Java' , 'Java') 查找得到 , INSTR('MLDN Java' , 'JAVA') 查找不到 FROM dual ; 如果能找到就返回位置,如果查不到就返回0 这个函数和JAVA中的indexof()函数功能相同. |
Character Functions
Single-row character functions accept character data as input and can return both character and numeric values. Character functions can be divided into the following:
|
Case-conversion functions 大小写转换函数 |
Lower转换为小写 Upper转换为大写 initcap首字母大写,其他小写 SQL> select lower('SQL Function') from dual; LOWER('SQLFU ------------ sql function SQL> select upper('SQL Function') from dual; UPPER('SQLFU ------------ SQL FUNCTION SQL> select initcap('sql function') from dual; INITCAP('SQL ------------ Sql Function SQL> select 'The job id for '||UPPER(ename)||' is '||LOWER(JOB) AS "emp details" FROM scott.emp; emp details -------------------------------------- The job id for SMITH is clerk The job id for WARD is salesman 应用:有时候不知道查询的名字是大写还是小写,在匹配的时候可能找不到,就使用LOWER将名字全部转换为小写,再来匹配. SQL> select ename,job FROM emp WHERE ename='higgins'; SQL> select ename,job FROM emp WHERE LOWER(ename)='higgins'; Case Conversion functions The SELECT query below demonstrates the use of case conversion functions. SELECT UPPER (first_name), INITCAP (last_name), LOWER (job_id) UPPER(FIRST_NAME) INITCAP(LAST_NAME) LOWER(JOB_ |
||||||||||||||||
|
Character-manipulation functions 字符操作函数 |
CONCAT连接||操作 SUBSTR取子字符串 LENGTH求字符串的长度 INTER返回的是一个数字,查询一个子字符串在字符串中的第几个位置 LPAD左填充 RPAD右填充 TRIM去掉字符串的首尾空格或特殊字符(注意只能去掉首尾空格或字符) REPLACE搜索字符串,替换
综合应用: SELECT empid, CONCAT(first_name,last_name) NAME, jobid, LENGTH(last_name), INSTR(last_name,'a') "Contains 'a'?" FROM emp WHERE substri(jobid,4)='REP'; Character functions The SELECT query below demonstrates the use of CONCAT function to concatenate two string values. SELECT CONCAT (first_name, last_name) CONCAT(FIRST_NAME,LAST_NAME) The SELECT query below demonstrates the use of SUBSTR and INSTR functions. SUBSTR function returns the portion of input string from 1st position to 5th position. INSTR function returns the numeric position of character 'a' in the first name. SELECT SUBSTR (first_name,1,5), INSTR (first_name,'a') SUBST INSTR(FIRST_NAME,'A') The SELECT query below demonstrates the usage of LPAD and RPAD to pretty print the employee and job information. SELECT RPAD(first_name,10,'_')||LPAD (job_id,15,'_') RPAD(FIRST_NAME,10,'_')|| |
|
function |
purpose |
|
LOWER(column | expression) |
Coverts alpha character values to lowercase 将字符串转换为小写字母 Coverts mixed-case or uppercase character strings to lowercase |
|
UPPER(column | expression) |
Coverts alpha character values to uppercase 将字符串转换为大写字母 Converts mixed-case or lowercase character strings to uppercase |
|
INITCAP(column | expression) |
Coverts alpha character values to uppercase for the first letter of each word; all other letters in lowercase 将字符串中每个单词首字母大写,其他小写 Converts the first letter of each word to uppercase and the remaining letters to lowercase |
|
CONCAT(column | expression) |
Concatenates the first character value to the second character value; equivalent to concatenation operator(||) 把两个字符串连接起来 |
|
SUBSTR(column | expression, m[,n]) |
Returns specified characters from character value starting at character position m, n characters long(if m is negative, the count starts from the end of the character value, if n is omitted, all characters to the end of the string are returned ) 从字符串中返回指定字符,从字符m开始,n个字符长(如果m是负数,则计数从字符值的结尾开始,如果省略n,则返回字符串结尾的所有字符) |
|
LENGTH(column | expression) |
Returns the number of characters in the expression |
|
INTER(column | expression, 'string', [,m],[n]) 查找子字符串在表达式中的为位置 m为开始搜索的位置,n表示字符串第几次出现. |
Returns the numeric position of a named string. Optionally, you can provide a position m to start searching ,m 表示开始搜索的位置,and the occurrence n of the string. n表示字符串第几次出现. m and n default to 1, m,n默认都是1,meaning start the search at the beginning of the string and report the first occurrence. |
|
LPAD(column | expression, n, 'string') RPAD(column | expression, n, 'string') 用一个给定的字符string来填出这个表达式/字符串,填充完以后总长度为n. |
Returns an expression left-padded(左填充) to legth of n characters with a character expression. Returns an expression right-padded to length of n characters with a character expression. 例子:LPAD(column | expression, 5, 'w') 给这个字符串左边填充w,直到填充后的字符串总长度为5 |
|
TRIM(leading|trailing|both, trim_character FROM trim_source) |
Enables you to trim(削减) leading(前导) or trailing(尾部) characters(or both) from a character string. If trim_character on trim_source is a character literal, you must enclose it in single quotation marks.
|
|
REPLACE(text, search_string, replacement_string) 在文本里搜指定字符串,将搜寻到的字符串替换为替换字符串. |
Searches a text expression for a character string and, if found, replaces it with a specified replacement string |
SQL Fundamentals || Single-Row Functions || 字符函数 character functions的更多相关文章
- SQL Fundamentals || Single-Row Functions || 日期函数date functions
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...
- SQL Fundamentals || Single-Row Functions || 数字函数number functions
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使用单 ...
- Oracle Single-Row Functions(单行函数)——NULL-Related Functions
参考资料:http://docs.oracle.com/database/122/SQLRF/Functions.htm#SQLRF006 Single-row functions return a ...
- SQL Fundamentals || Single-Row Functions || 转换函数 Conversion function
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...
- SQL Fundamentals: Using Single-Row Functions to Customize Output使用单行函数自定义输出
SQL Fundamentals || Oracle SQL语言 DUAL is a public table that you can use to view results from functi ...
- SQL Fundamentals || Single-Row Functions || 通用函数 General function || (NVL,NVL2,NULLIF,DECODE,CASE,COALESCE)
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使用单 ...
- SQL Fundamentals || Oracle SQL语言
对于SQL语言,有两个组成部分: DML(data manipulation language) 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据 ...
- SQL入门(2): Oracle内置函数-字符/数值/日期/转换/NVL/分析函数与窗口函数/case_decode
本文介绍Oracle 的内置函数. 常用! 一. 字符函数 ASCII 码与字符的转化函数 chr(n) 例如 select chr(65) || chr(66) || chr(67) , ch ...
- oracle 常用sql字符函数介绍
常用字符函数介绍 1.ascii 返回与指定的字符对应的十进制数: SQL>select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') ...
随机推荐
- C#------如何深度克隆一个对象
普通版: public static object CloneObject( object obj ) { using ( MemoryStream memStream = new MemoryStr ...
- iOS 使用动态库
苹果的开放态度 WWDC2014上发布的Xcode6 beta版有了不少更新,其中令我惊讶的一个是苹果在iOS上开放了动态库,在Xcode6 Beta版的更新文档中是这样描述的: Frameworks ...
- UnicodeEncodeError: ‘gbk’ codec can’t encode character u’\u200e’ in position 43: illegal multib
[问题] 在执行代码时,提示上述错误,源码如下: # 下载小说... def download_stoy(crawl_list,header): # 创建文件流,将各个章节读入内存 with open ...
- 【GIS】ArcGIS Server密码
1.C:\Program Files\ArcGIS\Server\tools\passwordreset 2.PasswordReset -l 列出管理站点的管理员用户的名称 3.PasswordRe ...
- c++的字节对齐
win32平台下的微软C编译器对齐策略: 1)结构体变量的首地址能够被其最宽数据类型成员的大小整除.编译器在为结构体变量开辟空间时,首先找到结构体中最宽的数据类型,然后寻找内存地址能被该数据类型大小整 ...
- Android 监听apk安装替换卸载广播
首先是要获取应用的安装状态,通过广播的形式 以下是和应用程序相关的Broadcast Action ACTION_PACKAGE_ADDED 一个新应用包已经安装在设备上,数据包括包名(最新安装的包程 ...
- App store最新审核标准公布
本文转载至 http://blog.csdn.net/shuidonglCH/article/details/47083623 导读:苹果近日更新了App Store审核指南的相关章节,对此前版本进行 ...
- css !important用法以及CSS样式使用优先级判断
之前一直看到很多css中都有!important这个样式,一直不知道有什么作用的,今天在网上详细了解了一下,看了别人的博客,顺便转载收藏一下 css !important用法CSS样式使用优先级判断 ...
- Linux下的XAMPP基本配置技巧(设置虚拟主机、添加FTP账户等)
xampp安装好之后就只有一个默认站点及一个默认nobody的ftp账户,这显然不符合我们平时的需求了,那么下面就来讲一下如何设置并管理多个虚拟主机及ftp账户了,至于xampp的安装不在此讨论范围, ...
- window下遍历并修改文件
今天需要写一个遍历文件夹下的所有文件,试了试以前的方法竟然报错了.重新改了一下. #include <iostream> #include <stdlib.h> #includ ...