Sample Exam Questions
Choose an appropriate explanation for this.
※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/01
PostgreSQL comes standard with a procedural language called PL/pgSQL. This can be used to perform complex tasks on the server side.
Functions written in PL/pgSQL are divided into a declaration starting with DECLARE, an execution starting with BEGIN, and an end with END.
The variable definition in declaration part (x record on line 3 in the example), the execution statement (SELECT statement starting on line 5 and RETURN statement on line 7 in the example), and the final END require a semicolon to mark the end of the statement. However, DECLARE and BEGIN must not be followed by a semicolon, or a syntax error will occur.
In addition to the familiar data types for database tables, such as integer and varchar, variable declarations can include row types. These represent the same structure as the specified table (written as table_name% ROWTYPE). They can also include record types to which any row structure can be assigned (line 3 in the example).
At the time of CREATE FUNCTION, only parsing is done, and the existence or types of tables and columns are not checked. For example, if the executor uses a variable that is not defined in declaration, or if the SQL syntax is incorrect, CREATE FUNCTION itself will return an error. However, even if the specified table or column does not exist, CREATE FUNCTION will succeed if the SQL syntax is correct. An error will be returned when attempting to execute the defined function.
Therefore, the correct answer is E.
© EDUCO All Rights Reserved.