Javatpoint Logo
Javatpoint Logo

NCHAR Function in SQL

The NCHAR string function shows the unicode value of the integer passed in the function. This function takes only one parameter or argument. If we pass the integer value which exceeds the given range then it shows NULL value.

Syntax of NCHAR String Function

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

Syntax1:

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

Syntax2:

In this syntax, we used the NCHAR function with the integer value.

Examples of NCHAR String function

Example 1: The following SELECT query shows the Unicode value of 20:

Output:

Unicode_of_20
^T

Example 2: The following SELECT query shows the Unicode value of 84:

Output:

Unicode_of_84
T

Example 3: The following SELECT query shows the Unicode value of 260:

Output:

Unicode_of_98
NULL

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

In this fourth example, we will create the new table through which we will perform the NCHAR 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
92 Monu Roy Singhania Chandigarh 54 68 98 88
104 Ravi Roy Kumar Lucknow 71 82 69 71
7 Shyam Roy Sharma Delhi 85 90 68 78
85 Abhay Kumar Gupta Chandigarh 45 68 82 78
509 Riya Roy Sharma Delhi 68 90 69 91
65 Vishal Kumar Sharma Mumbai 75 65 88 75

Query 1: The following SELECT query uses the NCHAR function with the Fresher_ID column of the above Fresher_Marks table:

This SQL statement shows the Unicode value of id of each fresher from the above table:

Output

Fresher_ID First_Name Unicode_of_Fresher_ID
501 Vinay NULL
92 Monu \
104 Ravi h
7 Shyam ^G
85 Abhay U
509 Riya NULL
65 Vishal A

Query 2: The following SELECT query uses the NCHAR function with the Aptitude_Marks column of the above Fresher_Marks table:

This SQL statement shows the Unicode value of aptitude marks of each fresher from the above table:

Output:

Fresher_ID Aptitude_Marks Unicode_of_Aptitude_Marks
501 85 U
92 54 6 (Digit)
104 71 G
7 85 U
85 45 -
509 68 D
65 75 K

Query 3: The following SELECT query uses the NCHAR function with the Reasoning_Marks and Technical_Marks column of the above Fresher_Marks table:

This SQL statement shows the Unicode value of reasoning and technical marks of each fresher from the above table:

Output:


Fresher_ID Reasoning_Marks Unicode_of_Reasoning_Marks Technical_Marks Unicode_of_Technical_Marks
501 92 6 (Digit) 78 N
92 68 D 68 b
104 82 R 69 E
7 90 Z 68 D
85 68 D 82 R
509 90 Z 69 E
65 65 A 88 X

Query 4: The following SELECT query uses the NCHAR function with the Percentage column of the above Fresher_Marks table:

Output:

Fresher_ID Percentage Unicode_of_Percentage
501 85 U
92 88 X
104 71 G
7 78 N
85 78 N
509 91 [
65 75 K






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