How to intercept some characters in a string in oracle
In Oracle, you can use the Instr() and substr() functions to intercept part of the characters in the string. The syntax is "SUBSTR('String to be intercepted', interception starting position, INSTR('Required Intercepted string,'','search starting position','number of occurrences')-1) ".
The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.
oracle intercepts part of the string in the field
Use the Instr() and substr() functions in Oracle:
In Oracle, you can use the instr function to judge a string to determine whether it contains specified characters.
The syntax is:
instr(sourceString,destString,start,appearPosition). instr('源字符串' , '目标字符串' ,'开始位置','第几次出现')
where
sourceString represents the source string;
destString represents The substring to be searched for in the source string;
start represents the starting position of the search. This parameter is optional and defaults to 1;
appearPosition represents how many times destString appears from the source character. This parameter is also optional and defaults to 1;
If the value of start is a negative number, then it means The search is performed from right to left, but the location data is still calculated from left to right.
The return value is: the position of the found string.
For the instr function, we often use it like this: find the position of the specified substring from a string. For example:
SQL> select instr('yuechaotianyuechao','ao') position from dual; POSITION ---------- 6
Start searching from the 7th character
SQL> select instr('yuechaotianyuechao','ao', 7) position from dual; POSITION ---------- 17
Start from the 1st character and search for the second occurrence of the substring
SQL> select instr('yuechaotianyuechao','ao', 1, 2) position from dual; POSITION ---------- 17
For the instr function, We often use it like this: find the position of a specified substring in a string. For example:
SQL> select instr('abcdefgh','de') position from dual; POSITION ---------- 4
Starting from 1, d ranks fourth, so 4 is returned
SQL>select instr('abcdefghbc','bc',3) position from dual; POSITION ---------- 9
The third character starting from the 3rd character is c, so the string starting from 3 Find bc, return 9
Usage of the substr function, get the string with the specified starting position and length in the string, the default is the substring from the starting position to the end.
substr( string, start_position, [ length ] ) substr('目标字符串',开始位置,长度)
For example:
substr('This is a test', 6, 2) would return 'is' substr('This is a test', 6) would return 'is a test' substr('TechOnTheNet', -3, 3) would return 'Net' substr('TechOnTheNet', -6, 3) would return 'The'select substr('Thisisatest', -4, 2) value from dual
SUBSTR() function
1. Purpose: Returns a string from a given character expression or memo field substring.
2. Grammar format:
substr(string string, int a, int b); substr(string string, int a) ;
Format 1:
1. string The string to be intercepted
2. a The starting position of the intercepted string (Note: When a is equal to 0 or 1, interception starts from the first bit)
3. b The length of the string to be intercepted
Format 2:
1. string The string that needs to be intercepted
2. a can be understood as intercepting all subsequent strings starting from the a-th character.
oracle intercepts the string
Intercept C3411.907w15 into the string C3411 before the dot SUBSTR ('C3411.907w15', 0, INSTR ('C3411.907w15 , '.', 1, 1) - 1)
SELECT SUBSTR ('C3411.907w15', 0, INSTR ('C3411.907w15, '.', 1, 1) - 1) FROM DUAL
Intercept the string 907w15 after the dot from C3411.907w15 SUBSTR ('C3411.907w15', INSTR ('C3411.907w15', '.' , 1, 1) 1)
SELECT SUBSTR ('C3411.907w15', INSTR ('C3411.907w15', '.', 1, 1)+1) FROM DUAL
Project application example:
Original string:
Original There are 7 "_" in the field. Now I just want to take out the string after the last "_". How to solve it?
Two steps:
The first step is to find the 7th "_" character through the Instr() function:
select instr('Q room Net Group_Brokerage Division_South China District_Shenzhen Shihua_Sales Department_Nanshan Qianhai District_Qianhai Central Area_Qianhai Fifth Branch','_', 1, 7) fdisplayname from SHENZHENJM1222.B
Or:
select instr('Qfang.com Group_Brokerage Division_South China District_Shenzhen Shihua_Business Department_Nanshan Qianhai District_Qianhai Center Area_Qianhai Wufen Branch', '_', -1, 1) fdisplayname FROM SHENZHENJM1222.B
The two have the same effect. The -1 below means starting from the right Count the starting character, 1 means to get the first "_"
The obtained result is as shown in the figure:
Step 2, use the substr() function to get the required fields:
select substr(fdisplayname,instr(fdisplayname,'_',-1 ,1) 1) fdisplayname from SHENZHENJM1222.B
fdisplayname: Represents the field name, equivalent to metastring
Focus on the introduction 1
1 means starting to intercept the first string after the target string "_"
Let's take a look at the situation of different numbers:
fdisplayname ,instr(fdisplayname,'_',-1,1) 1) fdisplayname from SHENZHENJM1222.B
Let’s take a look at what 1 in instr(fdisplayname,'_',-1,1) means:
# Recommended tutorial: "
The above is the detailed content of How to intercept some characters in a string in oracle. For more information, please follow other related articles on the PHP Chinese website!

The core purpose of Oracle backup and recovery is to quickly restore the database to a consistent state when data is lost or corrupted. 1. Backup phase: Copy the database file to the backup media through RMAN or other tools. 2. Recovery phase: When a database fails, first restore the backup data, and then restore to the pre-failed state by applying the redo log file.

OracleRAC achieves high availability and scalability through multi-node shared database storage. Its working principle includes load balancing, failover and dynamic node expansion to ensure efficient operation of the system and data consistency.

Deploying and managing Oracle databases in OCI can be achieved through the following steps: 1. Create a database instance and set configuration parameters using OCIPythonSDK; 2. Configure network and storage resources; 3. Connect to the database and execute SQL queries; 4. Perform database backup and recovery operations; 5. Optimize database performance by adjusting resource configuration, network optimization and backup policies. This is a highly automated process where users only need to provide the necessary configuration parameters and the OCI will handle the remaining work.

OracleDBA interview preparation requires mastering core knowledge such as database architecture, performance tuning, and backup and recovery. 1. Understand the Oracle database schema, including the relationship between instances and databases. 2. Master performance tuning methods, such as SQL tuning and index optimization. 3. Familiar with backup and recovery strategies and use RMAN and data pump tools. Through these preparations, you can demonstrate your professional skills in the interview and successfully pass the interview.

OracleSQL tuning can improve query performance through the following steps: 1. Create an appropriate index, such as creating an index for the department column; 2. Analyze the execution plan, use the EXPLAINPLAN command to view and optimize; 3. Perform SQL rewrite, such as using subqueries to avoid unnecessary connection operations. Through these methods, the query efficiency of Oracle database can be significantly improved.

The security of Oracle databases can be achieved through a variety of measures, including authentication, authorization, encryption and auditing. 1) Use password files for user authentication and authorization; 2) Protect sensitive data through transparent data encryption (TDE); 3) Use virtual private databases (VPDs) to achieve fine-grained access control; these methods ensure the confidentiality, integrity and availability of data.

OracleGoldenGate enables real-time data replication and integration by capturing the transaction logs of the source database and applying changes to the target database. 1) Capture changes: Read the transaction log of the source database and convert it to a Trail file. 2) Transmission changes: Transmission to the target system over the network, and transmission is managed using a data pump process. 3) Application changes: On the target system, the copy process reads the Trail file and applies changes to ensure data consistency.

The procedures, functions and packages in OraclePL/SQL are used to perform operations, return values and organize code, respectively. 1. The process is used to perform operations such as outputting greetings. 2. The function is used to calculate and return a value, such as calculating the sum of two numbers. 3. Packages are used to organize relevant elements and improve the modularity and maintainability of the code, such as packages that manage inventory.


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

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.