REPEAT Function in SQLThe REPEAT string function shows the string in the output to the given number of times. Syntax of REPEAT String FunctionSyntax1: This syntax uses the REPEAT function with the column name of the SQL table: In the syntax, we have to specify the name of that column on which we want to perform the REPEAT function. Syntax2: This syntax uses the REPEAT function with the string: Syntax2: This syntax uses the REPEAT function with the individual character: Examples of REPEAT String functionExample 1: The following SELECT query shows the JavaTpoint string four times in the result: Output:
Example 2: The following SELECT query shows the given set of words two times in the output: Output:
Example 3: The following SELECT query shows the S character five times in the result: Output:
Example 4: The following SELECT query shows the set of numbers six times in the result: Output:
Example 5: This example uses the REPEAT function with the table in Structured Query Language. To understand the REPEAT function with SQL, we have to create the SQL table first using CREATE statement. The syntax for creating the new table in the SQL database is as follows: The following CREATE statement creates the Student_Marks table: The below INSERT queries insert the records of college Faculties in the Student_Marks table: The following SELECT statement displays the inserted records of the above Student_Marks table:
Query 1: The following SELECT query uses the REPEAT function with the Student_First_Name column of the above Student_Marks table: This SQL statement shows the First name of each student three times in the result. Output:
Query 2: The following SELECT query uses the REPEAT function with the Student_Last_Name column of the above Student_Marks table: This SQL statement shows the last name of each student two times in the result. Output:
Query 3: The following SELECT query uses the REPEAT function with the Student_Address column of the above Student_Marks table: This SQL statement shows the state four times of each student in the result. Output:
Query 4: The following SELECT query uses the REPEAT function with the Student_Middle_Name and Student_City column of the above Student_Marks table: This SQL statement shows the middle name two times and the city three times for each student in the result. Output:
Next TopicSUBSTRING_INDEX Function in SQL |