Introduction to the substr() function of SQL


The substr function is used to intercept a part of a column field in the database.

The function names in each database are different (it’s really painful. Can’t the later invented database be the same as the first one?)

Copy codeThe code is as follows:
Oracle: SUBSTR( )
SQL Server: SUBSTRING( ) ;

Common methods are:

It is the position starting from POS and intercepting to the end.

Another commonly used is:

Copy codeThe code is as follows:

The meaning of this expression is to intercept len characters (whitespace is also a character) from the position starting from POS.

It should be noted that if POS is 1 (instead of 0), it means to start from the first position.

This is also easy to understand, because the database is not our usual program. It has its own set of habits. The records of the database start from 1 instead of 0. Yeah.