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(' ') ...
随机推荐
- POJ 1459 && ZOJ 1734--Power Network【最大流dinic】
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25108 Accepted: 13077 D ...
- android 不能在子线程中更新ui的讨论和分析
问题描写叙述 做过android开发基本都遇见过 ViewRootImpl$CalledFromWrongThreadException,上网一查,得到结果基本都是仅仅能在主线程中更改 ui.子线程要 ...
- Eclipse------启动Server时出现弹窗Server at localhost was unable to start within 45 seconds.
弹窗详细信息: Server Tomcat v8. Server at localhost was unable to start within seconds. If the server requ ...
- [转]Tomcat的部署
1.1 Context descriptors Tomcat4中的Manager和Admin管理工具其实就是利用它来部署的.在Tomcat5中提出了Context descriptor这个概念,且为其 ...
- iOS 优秀文章网址收录
1. iOS应用支持IPV6,就那点事儿 地址:http://www.jianshu.com/p/a6bab07c4062 2. iOS配置IPV6网络 地址:http://www.jianshu.c ...
- my97date 时间范围限制
需求:根据开始时间,动态限制结束时间 实现: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- HTML 换行
<br /> 标签可以用于换行 <!DOCTYPE HTML> <html> <body> <p> I like Playing. < ...
- [Ubuntu] 关于使用 root 账号登录
(本文验证环境为 Ubuntu 14.04 和 Lubuntu 13.04) Ubuntu 维护者们认为实在没有必要使用 root 帐户,因为你想做的所有事情管理员都可以完成,管理员只需使用 sudo ...
- java接口定义的静态方法和默认如何在类实现的时候使用
在 JDK1.8,允许我们给接口添加两种非抽象的方法实现: 1.默认方法,添加 default 修饰即可: 2.静态方法,使用 static 修饰:示例如下: 这样可以实现接口的增强,那我们在类实现接 ...
- Hadoop计算平均值【转】
file1.txt a 1b 2a 3b 3a 5b 7c 3c 5 file2.txt a 1b 7c 5a 1c 3 结果: a 2.2b 4.75c 4.0 代码: package org.ap ...