Programming in PL/SQL (Basic Concepts)
Imporove your PL/SQL Skills
Questions
How many sections or parts are there in a PL/SQL program?
- 1
- 2
- 3
- 4
A group of related data items stored in fields, each with its own name and datatype, is called
- varray
- nested table
- record
- index-by tables
Which of the following is NOT a valid loop in PL/SQL?
- For loop.. end loop
- loop..end loop
- While loop.. end loop
- Do while loop..end loop
When a 'Select' command is written inside a PL/SQL program, the ____ keyword must be included in it.
- where
- in
- group by
- into
Which of the following is NOT a valid cursor attribute?
- %ISOPEN
<!--?xml:namespace prefix = o /--><o:p></o:p>
<o:p></o:p> - %EXISTS
- %FOUND
<o:p></o:p> - %ROWCOUNT
Which of the following is a schema object that groups logically related PL/SQL types, items and sub-programs?
- Trigger
<!--?xml:namespace prefix = o /--><o:p></o:p> - Procedure
<o:p></o:p> - Function
<o:p></o:p> - Package
<o:p></o:p>
For which of the following SQL statements can a trigger not be written?
- Alter
- Update
- Delete
- Insert
In PL/SQL, which of the following is the correct syntax of the 'if-else' statement?
- If condition then
statements
elseif condition then
statements
else
statements
end if; - if condition
statements
elseif condition
statements
else
statements
end if; - if condition then
statements
elif condition then
statements
else
statements
end if; - if condition
statements
elsif condition
statements
else
statements
endif;
Which of the following is NOT a correct way of passing parameters to a function or a procedure in PL/SQL?
- IN
- OUT
- INOUT
- OUTIN
Which named exception is thrown when an attempt is made to open a cursor that is already open?
- INVALID_CURSOR
- OPEN_CURSOR
- CURSOR_ALREADY_OPEN
- CURSOR_IS_OPEN
Which of the following is the correct difference between a procedure and a function?
- Procedure can be called from SQL prompt, while function cannot be called from SQL prompt.
- Function can return a value, while procedure cannot return any value.
- Functions can have arguments, while procedure cannot have arguments.
- Function can call procedures while procedure cannot call functions.
Which of the following statements is FALSE about packages?
- Packages are made up of two components: specification and body
- The package body contains the actual code.
- The package specification contains the actual code.
- Packages encapsulate related procedures, functions, etc. into one self-contained unit.
Which of the following statements is FALSE regarding triggers?
- A trigger can be written for handling updates of a particular column.
- A trigger can be run either before or after the execution of an SQL statement.
- A trigger cannot be written on a view.
- A trigger cannot contains a condition.
Which of the following is the correct method of declaring a constant in PL/SQL?
- Data constant number (3)=10
- Data constant number (3) := 10;
- Data constant number (3);
- Constant Data number (3) := 10;
Which of the following keywords is NOT present in a 'function declaration'?
- Declare
- Begin
- Return
- Exception
Which of the following is NOT a difference between SQL and PL/SQL ?
- SQL is declarative, while PL/SQL is procedural.
- SQL is used to write queries, whereas PL/SQL is used to code programs.
- SQL can be embedded within PL/SQL but a PL/SQL statement cannot be embedded in SQL.
- PL/SQL executes one statement at a time, whereas SQL is used to write a code block.
In a PL/SQL 'case' statement, if all the given conditions are false, the statements written in the ____ block are executed.
- default
- else
- case
- otherwise
Which of the following is the correct method of handling exceptions in the 'Exception' section?
- If exception then
exception handling statements - If raised_exception then
exception handling statements - When exception then
exception handling statements - When raised_exception then
exception handling statements
In a PL/SQL program, to declare a variable with the same data type as a column of a table (anchored declaration), the correct syntax will be
- Varname tablename.colname%rowtype
- Varname tablename.colname%istype
- Varname tablename.colname%totype
- Varname tablename.colname%type
Which of the following is NOT an advantage of subprograms (procedures and functions)?
- Modularity
- Reusability
- Abstraction
- Inheritance
With reference to OLD and NEW pseudorecords, which of the following statements is FALSE ?
- For an INSERT trigger, OLD contains no value and NEW contains new values.
- For an ALTER trigger, OLD contains the old values, and NEW contains the new values.
- For an UPDATE trigger, OLD contains the old values, and NEW contains the new values.
- For a DELETE trigger, OLD contains old values, and NEW contains no value.
Which of the following statements is FALSE regarding 'Parameters in Cursor' (Parameterized Cursor)?
- The mode of a parameter can be both IN and OUT.
- A cursor parameter can be assigned a default value.
- The scope of the cursor parameter is local to the cursor.
- We can only specify the datatype of the parameter, not its length.
Which of the following statements is FALSE about 'Implicit Cursors'?
- Oracle performs the open, fetches, and close for you automatically.
- It is less efficient than an explicit cursor.
- It is less vulnerable to data errors.
- It gives you less programmatic control.
Which of the following statements is FALSE regarding variable names?
- Variable names must start with a letter.
- Variable names cannot contain a '$' sign.
- Variable names cannot contain spaces.
- Variable name should be a maximum of 30 characters in length.
Which line in the above code has an error?
declare
no number;
sq number;
begin
no:=&number; --Line 1
if no>10000 then -- Line 2
dbms_output.put_line('Too large value'); -- Line 3
else -- Line 4
sq=no*no; -- Line 5
dbms_output.put_line(\\\\\\'Square of \\\\\\' || no || \\\\\\' is \\\\\\' || sq); -- Line 6
end if; -- Line 7
end;
/
- Line 1
- Line 2
- Line 5
- Line 6