In this session, you learnt about case statements, stored routines and cursors in SQL. Let’s watch the upcoming video to revisit the topics that were covered in this session one by one.
The topics that were covered in this session can be summarised as follows:
Case statements: Case statements are used to classify data values into different groups according to the given criteria. The syntax of a case statement is as follows:
UDFs: UDFs are used to create and reuse certain pieces of functionality in SQL. The syntax of a UDF is as follows:
Stored procedures: Stored procedures are also used to reuse some required functionality in SQL. The syntax of a stored procedure is as follows:
UDFs vs stored procedures: The differences between UDFs and stored procedures are summarised in the table given below.
UDF | Stored Procedure |
It supports only the input parameter, not the output. | It supports input, output and input-output parameters. |
It cannot call a stored procedure. | It can call a UDF. |
It can be called using any SELECT statement. | It can be called using only a CALL statement. |
It must return a value. | It need not return a value. |
Cursors: A cursor is used to individually process each row that is returned in a query.