Oracle中相关函数说明
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个字符

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

Creating an Oracle table involves the following steps: Use the CREATE TABLE syntax to specify table names, column names, data types, constraints, and default values. The table name should be concise and descriptive, and should not exceed 30 characters. The column name should be descriptive, and the data type specifies the data type stored in the column. The NOT NULL constraint ensures that null values are not allowed in the column, and the DEFAULT clause specifies the default values for the column. PRIMARY KEY Constraints to identify the unique record of the table. FOREIGN KEY constraint specifies that the column in the table refers to the primary key in another table. See the creation of the sample table students, which contains primary keys, unique constraints, and default values.

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

Use the ALTER TABLE statement, the specific syntax is as follows: ALTER TABLE table_name ADD column_name data_type [constraint-clause]. Where: table_name is the table name, column_name is the field name, data_type is the data type, and constraint-clause is an optional constraint. Example: ALTER TABLE employees ADD email VARCHAR2(100) Add an email field to the employees table.

Oracle provides multiple deduplication query methods: The DISTINCT keyword returns a unique value for each column. The GROUP BY clause groups the results and returns a non-repetitive value for each group. The UNIQUE keyword is used to create an index containing only unique rows, and querying the index will automatically deduplicate. The ROW_NUMBER() function assigns unique numbers and filters out results that contain only line 1. The MIN() or MAX() function returns non-repetitive values of a numeric column. The INTERSECT operator returns the common values of the two result sets (no duplicates).

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.
