Javatpoint Logo
Javatpoint Logo

ELT Function in SQL

The ELT string function in Structured Query Language returns the string from the list of string according to the given index number. This function returns NULL, if no string is found at the given index position.

Syntax of ELT String Function

In SQL, we can use the ELT function with the columns of the table, strings, and characters.

Syntax 1:

In this syntax, we used the ELT function with existing table of SQL. Here, we have to define the name and columns of that table on which we want to perform ELT function.

Syntax 2:

In this syntax, we used the ELT function with list of strings.

Syntax 3:

In this syntax, we used the ELT function with list of characters.

Examples of ELT String function

Example 1: The following query uses the ELT function with the list of strings:

Output:

String_at_1thPosition
H

Example 2: The following query searches the "Old" string which is not present in the list of string:

Output:

String_at_7thPosition
India

Example 3: The following SELECT query uses the ELT function with the list of numbers:

Output:

String_at_5thPosition
NULL

Example 4: This example uses the ELT function with the table in Structured Query Language.

In this fourth example, we will create the new table through which we will perform the ELT function with table values:

The following block shows the syntax to create the new table in SQL:

The following CREATE statement creates the Fresher_Marks table:

The below INSERT queries insert the records of freshers with marks and details in the Fresher_Marks table:

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


Fresher_ID First_Name Middle_Name Last_Name City Aptitude_Marks Reasoning_Marks Technical_Marks Percentage
501 Vinay Roy Gupta Lucknow 85 92 78 85
502 Monu Roy Singhania Chandigarh 54 68 98 88
504 Ravi Roy Kumar Lucknow 71 82 69 71
507 Shyam Roy Sharma Delhi 85 90 68 78
510 Abhay Kumar Gupta Chandigarh 45 68 82 78
509 Riya Roy Sharma Delhi 68 90 69 91
505 Vishal Kumar Sharma Mumbai 75 65 88 75
512 Romika Roy Kumar Mumbai 78 95 68 85

Query 1: The following SELECT query uses the ELT function with the First_Name, Middle_Name, Last_Name columns of the above Fresher_Marks table:

This SQL statement shows the value of 3rd index position of each fresher from the above table.

Output:

First_Name Middle_Name Last_Name Value_at_3
Vinay Roy Gupta Gupta
Monu Roy Singhania Singhania
Ravi Roy Kumar Kumar
Shyam Roy Sharma Sharma
Abhay Kumar Gupta Gupta
Riya Roy Sharma Sharma
Vishal Kumar Sharma Sharma
Romika Roy Kumar Kumar

Query 2: The following SELECT query uses the ELT function with the Aptitude_Marks, Reasoning_Marks, and Technical_Marks column of those freshers whose Fresher_ID is greater than 502 in the above Fresher_Marks table:

Output:

Fresher_ID Aptitude_Marks Reasoning_Marks Technical_Marks Number_at_2nd_position
504 71 82 69 82
507 85 90 68 90
510 45 68 82 68
509 68 90 69 90
505 75 65 88 65
512 78 95 68 95






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA