Home Database Mysql Tutorial Oracle中相关函数说明

Oracle中相关函数说明

Jun 07, 2016 pm 04:21 PM
oracle function Related illustrate

3、round函数 ROUND(number, num_digits) 将number四舍五入到只有num_digits个小数位。 4、lpad、rpad函数 lpad()函数的用法: lpad函数将左边的字符串填充一些特定的字符其语法格式如下: lpad(string,n,[pad_string]) string:可是字符或者参数 n:字符的

  3、round函数 ROUND(number, num_digits) 将number四舍五入到只有num_digits个小数位。 4、lpad、rpad函数 lpad()函数的用法: lpad函数将左边的字符串填充一些特定的字符其语法格式如下: lpad(string,n,[pad_string]) string:可是字符或者参数 n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符; pad_string:是个可选参数,这个字符串是要粘贴到string的左边,如果这个参数未写,lpad函数将会在string的左边粘贴空格。 例如: lpad('tech', 7); 将返回' tech' lpad('tech', 2); 将返回'te' lpad('tech', 8, '0'); 将返回'0000tech' lpad('tech on the net', 15, 'z'); 将返回'tech on the net' lpad('tech on the net', 16, 'z'); 将返回'ztech on the net' rpad()函数的用法: rpad函数将右边的字符串填充一些特定的字符其语法格式如下: rpad(string,n,[pad_string]) string:可是字符或者参数 n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符; pad_string:是个可选参数,这个字符串是要粘贴到string的右边,如果这个参数未写,lpad函数将会在string的右边粘贴空格。 例如: rpad('tech', 7); 将返回' tech' rpad('tech', 2); 将返回'te' rpad('tech', 8, '0'); 将返回'tech0000' rpad('tech on the net', 15, 'z'); 将返回'tech on the net' rpad('tech on the net', 16, 'z'); 将返回'tech on the netz' 5、ltrim、rtrim函数 ltrim(x,y) 函数是按照y中的字符一个一个截掉x中的字符,,并且是从左边开始执行的,只要遇到y中有的字符, x中的字符都会被截掉, 直到在x的字符中遇到y中没有的字符为止函数命令才结束 .函数将109当成了三个字符以1,0,9在字符串开始直道出现不为1,0,9这三个字符中的任意一个开始截取;

SELECT LTRIM('1092002081100058424', '109') FROM dual
UNION ALL
SELECT LTRIM('1091000000002671251', '109') FROM dual
UNION ALL
SELECT LTRIM('1000000002671251', '1') FROM dual
UNION ALL
SELECT LTRIM('1000000002671251', '10') FROM dual

结果如下:

1 2002081100058424
2 2671251
3 000000002671251
4 2671251

  RTRIM(,)的意思是:

  首先从字符串'c1'右边查找'c2'中的任意字符,此例为'w','q',直到'wfrqqww'右边不为'w'和'q'字符为止

  SELECT RTRIM ('wfrqqww', 'qq') FROM DUAL查询出来的数据是wfr,

  6、instr instr函数返回要截取的字符串在源字符串中的位置。 语法如下:

instr( string1, string2, start_position,nth_appearance ) [1] [2]

string1 源字符串,要在此字符串中查找。

string2 要在string1中查找的字符串 。

start_position 代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。

nth_appearance 代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

注意:

  位置索引号从1开始。

  如果String2在String1中没有找到,instr函数返回0。

  示例:

  SELECT instr('syranmo','s') FROM dual; -- 返回 1

  SELECT instr('syranmo','ra') FROM dual; -- 返回 3

  SELECT instr('syran mo','a',1,2) FROM dual; -- 返回 0 7、substr

  substr(字符串,截取开始位置,截取长度) //返回截取的字

  substr('Hello World',0,1) //返回结果为 'H' *从字符串第一个字符开始截取长度为1的字符串

  substr('Hello World',1,1) //返回结果为 'H' *0和1都是表示截取的开始位置为第一个字符

  substr('Hello World',2,4) //返回结果为 'ello'

  substr('Hello World',-3,3)//返回结果为 'rld' *负数(-i)表示截取的开始位置为字符串右端向左数第i个字符

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1673
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

See all articles