Sie sind auf Seite 1von 8

The following exception handler will successfully insert the Oracle error number and error message into

a log table
whenever an Oracle Server error occurs. True or False?
EXCEPTION
WHEN OTHERS THEN
INSERT INTO err_log_table (num_col, char_col)
VALUES (SQLCODE, SQLERRM);
END;
(Assume that err_log_table has been created with suitable columns and datatypes.)

FALSE
When an exception is trapped in the WHEN OTHERS exception handler, you can use
a set of generic functions to identify those errors. You cannot use SQLCODE or
SQLERRM directly in a SQL statement. Instead you must assign their values to local
variables and then use the variables in the SQL statement.
DECLARE
err_num NUMBER;
err_msg VARCHAR(100);
EXCEPTION
WHEN OTHERS THEN
err_num := SQLCODE;
err_msg := SQLCODE;
INSERT INTO err_log_table (num_col, char_col)
VALUES (err_num, err_msg);
END;

An attempt to update an employees salary to a negative value will violate a check


constraint and raise an ORA-02290 exception.
Write the correct definition of a handler for this exception

DECLARE
e_sal_except EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_except,-02290);

Which of these exceptions would need to be raised explicitily by the PL/SQL


programmer

Others
Select statement returns more than one row
A check constraint is violated
A SQL UPDATE statement does not update any rows
A row is FETCHED from a cursor while the cursor is closed

Which of the following will cfully return a user-defined error message?


RAISE_APPLICATION_ERROR('Error Raised',-22001);
RAISE_APPLICATION_ERROR(-20257,'Error raised');
RAISE_APPLICATION_ERROR(-22001,'Error Raised');
RAISE_APPLICATION_ERROR('Error Raised',-20257);

The number range -20000 to -20999 is reserved by Oracle for programmer use, and is
never used for predefined Oracle Server errors.
You can use the %ROWTYPE with tables and views.
True

What will happen when the following code is executed?


DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;

Return an unhandled e_except2 to the calling environment

Exceptions declared in a block are considered local to that block and global to all its
sub blocks
True

Differences between anonymous blocks and subprograms


Anonymous Blocks
Unnamed pl/sql blocks
Compiled every time
Not stored in the database
Cannot be invoked by other applications
Do no return values
Cannot take parameters

Subprograms
Named pl/sql blocks
Compiled only once
Stored in the database
Named and therefore can be invoked by
other applications
Subprograms called functions must
return values
Can take parameters

CREATE OR REPLACE PROCEDUREadd_dept


IS
v_dept_id dept.department_id%TYPE;
v_dept_namedept.department_name%TYPE;
BEGIN
v_dept_id:=280;
v_dept_name:='ST-Curriculum';
INSERT INTO dept(department_id,department_name)
VALUES(v_dept_id,v_dept_name);
DBMS_OUTPUT.PUT_LINE('Inserted '||SQL%ROWCOUNT ||'row');

END;

CREATE OR REPLACE PROCEDURE raise_salary


(p_id IN my_employees.employee_id%TYPE,
p_percent IN NUMBER)
IS
BEGIN
UPDATE my_employees
SET salary = salary * (1 + p_percent/100)
WHERE employee_id = p_id;
END raise_salary;
BEGIN raise_salary(176,10); END;

Parameter Passing: Examples


Passing by positional notation
Passing by named notation
Passing by combination notation
CREATE OR REPLACE PROCEDURE add_dept(
p_name IN my_depts.department_name%TYPE,
p_loc IN my_depts.location_id%TYPE) IS
BEGIN
INSERT INTO my_depts(department_id,
department_name, location_id)
VALUES (departments_seq.NEXTVAL, p_name, p_loc);
END add_dept;
add_dept ('EDUCATION', 1400);
add_dept (p_loc=>1400, p_name=>'EDUCATION');
add_dept ('EDUCATION', p_loc=>1400);

Procedure SOMEPROC has five parameters named A, B, C, D, E in that order. The procedure was called as follows:
SOMEPROC(10,20,D=>50);
How was parameter B referenced?

Positional
Named
A combination of positionally and named
A combination of named and defaulted

Defaulted

A stored PL/SQL Procedure can be invoked from

A PL/SQL anonymous block


Another PL/SQL procedure
A calling application

What are the types of parameter modes

IN
OUT
INOUT

Which of the following statements about actual parameters is NOT


true
1. An actual parameter is declared in the calling environment,
not in the called procedure
2. An actual parameter must be the name of a variable
3. An actual parameter can have a Boolean datatype
4. The datatypes of an actual parameter and its formal
parameter must be compatible
5. An actual parameter can have a TIMESTAMP datatype

Why will this function not compile correctly


CREATE FUNCTION bad_one
IS
BEGIN
RETURN NULL;
END bad_one;
1.
2.
3.
4.
5.

You cannot RETURN a NULL


You must declare the type of the RETURN before the IS
You must have at least one IN parameter
You must code CREATE OR REPLACE, not CREATE
The body of the function must contain at least one executable
statement(as well as RETURN);

Which of the following is a difference between a procedure and a function


A procedure can include DML statements, but a function cannot
A function must have at least one IN parameter, while parameters are
optional for a procedure
A procedure can return a BOOLEAN datatype while a function cannot
A function can be used inside a SQL statement, while a
procedure cannot
A procedure can include an EXCEPTION section, while a function cannot

You have created a function named NEWFUNC. You now change some of the
function code, and try to recreate the function by executing : CREATE OR
REPLACE FUNCTION newfunct. What happens?
The function is automatically dropped and then recreated

You want to remove the procedure NO_NEED from your schema. You
execute: DROP PROCEDURE no_need
Which Data Dictionary views are updated automatically
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
All of the above
You want to see the names, modes and data types of the formal parameters
of function MY_FUNC in your schema. How can you do this
Query USER_PARAMETERS
Query USER_SOURCE
Query USER_FUNCTIONS
SHOW PARAMETER my_func
DESCRIBE my_func

When must AUTHID CURRENT_USER be included in an autonomous


transaction subprogram
When declaring Definers rights
When declaring Invokers rights
When using COMMIT or ROLLBACK
When using GRANT on subprogram
User FRED creates a procedure called DEL_DEPT using Definer's Rights,
which deletes a row from Fred's DEPARTMENTS table. What privilege(s) will
user BOB need to be able to execute Fred's procedure?
EXECUTE on DEL_DEPT

User BOB creates procedure MYPROC using the default Definer's Rights. BOB then executes:
GRANT EXECUTE ON bob.myproc TO ted;
When TED invokes BOB.MYPROC, whose privileges are checked?
TED's privileges
PUBLIC's privileges
SYSTEM's privileges
BOB's privileges
ORACLE's privileges

User REYHAN creates the following procedure:


CREATE PROCEDURE proc1 AUTHID CURRENT_USER
IS
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM tom.employees;
END;
User BILL wants to execute this procedure. What privileges will BILL need?
EXECUTE on REYHAN.PROC1 and SELECT on TOM.EMPLOYEES
EXECUTE on REYHAN.PROC1
SELECT on TOM.EMPLOYEES
BILL needs no privileges
None of the above. The procedure will fail to compile because REYHAN does not have SELECT privilege
on TOM.EMPLOYEES.

Das könnte Ihnen auch gefallen