CHAR Function in SQLThe CHAR string function shows the ASCII value of the integer passed in the function. This function takes only one argument. If we pass the integer value which exceeds the given range then it shows NULL value. Syntax of CHAR String FunctionIn SQL, we can use the CHAR function with the columns of the table, strings, and characters. Syntax 1: In this syntax, we used the CHAR 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 CHAR function. Syntax 2: In this syntax, we used the CHAR function with the integer value. Examples of CHAR String functionExample 1: The following SELECT query shows the ASCII value of 20: Output:
Example 2: The following SELECT query shows the ASCII value of 84: Output:
Example 3: The following SELECT query shows the ASCII value of 260: Output:
Example 4: This example uses the CHAR function with the table in Structured Query Language. In this fourth example, we will create the new table through which we will perform the CHAR 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:
Query 1: The following SELECT query uses the CHAR function with the Fresher_ID column of the above Fresher_Marks table: This SQL statement shows the ASCII value of id of each fresher from the above table: Output:
Query 2: The following SELECT query uses the CHAR function with the Aptitude_Marks column of the above Fresher_Marks table: This SQL statement shows the ASCII value of aptitude marks of each fresher from the above table: Output:
Query 3: The following SELECT query uses the CHAR function with the Reasoning_Marks and Technical_Marks column of the above Fresher_Marks table: This SQL statement shows the ASCII value of reasoning and technical marks of each fresher from the above table: Output:
Query 4: The following SELECT query uses the CHAR function with the Percentage column of the above Fresher_Marks table: Output:
Next TopicELT Function in SQL |