INSERT Function in SQL

The INSERT string function of Structured Query Language allows you to insert the string or character within the given string at the fixed position.

Syntax of INSERT String Function

Syntax1: This syntax uses INSERT function with the column name of the SQL table:

Output:

Tpoint_5_6
Java Tpoint

Example 2: The following SELECT query inserts the 'C' character at the first position in the given word:

Output:

C_1_1
Cngratulations

Example 3: The following SELECT query inserts the 'Capital' sub-string before 'of' word:

Output:

Capital_17_7
New Delhi is the Capital

Example 4: The following SELECT query inserts the 'Tpoint' string at the fifth position in the 'Java Excel' string:

Output:

Capital_17_7
Example.com

Example 5: This example uses the INSERT function with the table in Structured query Language.

Now, we create the new table in SQL, which helps to understand each string function. The syntax for creating the new table in the SQL database is as follows:

The following CREATE statement creates the Worker_Grade table:

The below INSERT queries insert the records of Workers with Grades, Salaries, and Remarks in the Worker_Grade table:

The following SELECT statement displays the inserted records of the above Worker_Grade table:


Worder_IDFirst_NameLast_NameFirst_CitySecond_CityNew_CityAttendance_RemarksWork_RemarksGrade
10AmanSharmaLucknowChandigarhGhaziabad8895A2
02VishalSharmaChandigarhGhaziabadGhaziabad9582A1
07RajGuptaDelhiGhaziabadLucknow9195A1
04YashSinghaniaGhaziabadDelhiLucknow8582A2
11VinayRoyDelhiKanpurGhaziabad9597A1
16ManojGuptaGhaziabadMeerutChandigarh9590B1
19RamGuptaLucknowGhaziabadChandigarh8995A2

The following SELECT query uses the FORMAT function with the First_Name column of the above Worker_Grade table:

This SQL statement inserts the 'Aman' sub-string at the first position in the first name of each worker

Output:

First_NameAman_1_5
AmanresAman es
VishalkushAman lkush
RajeshAman h
YashrajAman aj
VinaybhattAman bhatt
ManojjeetaAman jeeta
RameshAman h





Latest Courses