SIGN Function in SQLThe SIGN string function in Structured Query Language returns the specified number with the positive or negative sign. If the number is greater than zero, the function returns 1 otherwise -1. If the number specified as zero, the function returns zero in result. Syntax of SIGN String FunctionSyntax1: This syntax uses the SIGN function with the column name of the SQL table: In the syntax, we have to specify the name of that column on which we have to use SIGN function Syntax2: We can also use the SIGN function with any number: Examples of SIGN String functionExample 1: The following SELECT query uses the SIGN function 0 Output:
Example 2: The following SELECT query shows the SIGN of the number Output:
Example 3: following SELECT query shows the SIGN of the negative number: Output:
Example 4: This example uses the SIGN function with the table in Structured Query Language. The syntax for creating the new table in the SQL database is as follows: The following CREATE statement creates the Student_Percentage table: The below INSERT queries insert the records of students with grades and marks in the Student_Percentage table: The following SELECT statementdisplays the inserted records of the above Student_Percentage table:
Query 1: The following SELECT query uses the SIGN function with the Roll_No column of the above Student_Percentage table: This SQL statement shows the SIGN of roll number of each student from the above table. Output:
Query 2: The following SELECT query uses the SIGN function with the English_Marks column of the above Student_Percentage table: This SQL statement shows the SIGN of the english marks of each student. Output:
Query 3: The following SELECT query uses the SIGN function with the Hindi_Marks column of the above Student_Percentage table: This SQL statement shows the SIGN of the hindi marks of each student. Output:
Query 4: The following SELECT query uses the SIGN function with the Maths_Marks and Percentage column of the above Student_Percentage table: Output:
Next TopicSQRT Function in SQL |