Javatpoint Logo
Javatpoint Logo

MAKE_SET Function in SQL

The MAKE_SET string function in Structured Query Language returns the value of the given bit from the set of multiple values.

Syntax of MAKE_SET String Function

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

Syntax 1:

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

Syntax 2:

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

Syntax 3:

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

Examples of MAKE_SET String function

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

Output:

Value_at1st_bit
H

Example 2: The following query searches the string at 1st and 4th bit:

Output:

Value_at1st_4th_bit
New, is

Example 3: The following query shows the value at second bit from the given set:

Output:

Value_at2nd_bit
I

Example 4: The following query shows the value at second and fourth bit from the given set:

Output:

Value_at2_4_bit
I, A

Example 5: This example uses the MAKE_SET function with the table in Structured Query Language.

In this fourth example, we will create the new table through which we will perform the MAKE_SET 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

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

This query shows the value of Middle name of each fresher from the above table.

Output:

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

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

Output:

Fresher_ID Aptitude_Marks Reasoning_Marks Technical_Marks Value_at_4bit
504 71 82 69 69
507 85 90 68 68
510 45 68 82 82
509 68 90 69 69
505 75 65 88 88

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

This query shows the value of Middle name of each fresher from the above table.

Output:

First_Name Middle_Name Last_Name Value_at_1_3bit
Vinay Roy Gupta Vinay, Roy
Monu Roy Singhania Monu, Roy
Ravi Roy Kumar Ravi, Roy
Shyam Roy Sharma Shyam, Roy
Abhay Kumar Gupta Abhay, Kumar
Riya Roy Sharma Riya, Roy
Vishal Kumar Sharma Vishal, Kumar






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