Explore key differences and similarities between PL/SQL, T-SQL, and procedural SQL concepts with these beginner-friendly multiple-choice questions. Enhance your understanding of syntax, error handling, variables, and transaction control relevant to popular procedural SQL dialects.
Which procedural SQL language is primarily associated with Oracle databases?
Explanation: PL/SQL is the procedural language extension used mainly in Oracle database systems. T-SQL is connected to a different database system. SQL/PSM is a more generic procedural language standard. MySQL SQL refers to SQL used in another database but is not specifically a procedural extension.
What keyword is used in T-SQL for variable declaration, as shown in 'DECLARE @amount INT;'?
Explanation: In T-SQL, the DECLARE keyword is used for variable declarations like DECLARE @amount INT;. VAR is not valid syntax in this context. LET and ASSIGN are also not used for variable declaration in T-SQL. Misusing these keywords would result in an error.
In PL/SQL, which loop structure would you use to repeat a set of statements an unknown number of times until a condition is met?
Explanation: WHILE LOOP is used in PL/SQL to repeat actions as long as a condition remains true. FOR LOOP is intended for repeating a fixed number of times. REPEAT LOOP is not standard PL/SQL syntax. GO LOOP is not a recognized loop construct in procedural SQL.
Which keyword is used in PL/SQL for exception handling after a BEGIN-END block?
Explanation: The EXCEPTION section is used in PL/SQL for handling errors after a BEGIN-END block. CATCH and RESCUE are found in other programming languages, not in PL/SQL. ERROR is not a valid handler in PL/SQL's error management structure.
Which statement is commonly used in both T-SQL and PL/SQL to make database changes permanent?
Explanation: COMMIT is widely used for finalizing transactions and saving changes in both T-SQL and PL/SQL. FINISH and END are not valid transactional commands in this context. SAVE exists as part of SAVEPOINT, but SAVE by itself does not commit transactions.
How do you write a single-line comment in PL/SQL?
Explanation: PL/SQL uses two hyphens (--) for single-line comments. Double slashes (//) and hash (#) are not accepted for single-line comments in PL/SQL. Block comments use /* */, not for single lines, making -- the correct answer here.
What command allows you to display output for debugging purposes in PL/SQL?
Explanation: DBMS_OUTPUT.PUT_LINE is used in PL/SQL to print output, useful for debugging. PRINT is used in T-SQL, not PL/SQL. SHOW and LOG_OUTPUT are not valid commands to display output in PL/SQL procedures.
Where can you declare a variable in PL/SQL to restrict its use only to a specific block of code?
Explanation: Variables declared inside the DECLARE section of a PL/SQL block are local to that block. There is no 'global section' in standard PL/SQL. Declaring variables at the server level is not a function of PL/SQL, and variables cannot be declared within a standard SELECT statement.
Which keyword is used in T-SQL scripts to signal the end of a batch of statements?
Explanation: In T-SQL, the GO statement indicates the end of a batch and is recognized by many T-SQL environments. END is used for closing code blocks, not batches. STOP and HALT are not used for batch separation in T-SQL scripts.
How does T-SQL indicate an input parameter in a stored procedure named @id?
Explanation: T-SQL uses the @ symbol to denote parameters and variables, such as @id, in stored procedures. A colon is used for binding variables in other languages. The dollar sign and double quotes are not used to indicate procedure parameters in T-SQL.