0% found this document useful (0 votes)
32 views

SQL and PL SQL

comparto

Uploaded by

alolivet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

SQL and PL SQL

comparto

Uploaded by

alolivet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

What does a COMMIT statement do to a CURSOR

a] Open the Cursor


b] Fetch the Cursor
c] Close the Cursor
d] None of the above

2. Which of the following is TRUE

1] Host variables are declared anywhere in the program


2] Host variables are declared in the DECLARE section
a] Only 1 is TRUE
b] Only 2 is TRUE
c] Both 1 & 2are TRUE
d] Both are FALSE

3. Declare
fvar number := null; svar number := 5
Begin
goto << fproc>>
if fvar is null then
<< fproc>>
svar := svar + 5
end if;
End;
  
What will be the value of svar after the execution ?
a] Error
b] 10
c] 5
d] None of the above

4. Declare
a number := 5; b number := null; c number := 10;
Begin
if a > b AND a < c then
a := c * a;
end if;
End;
What will be the value of 'a' after execution ?
a] 50
b] NULL
c] 5
d] None of the above

5. SUBSTR(SQUARE ANS ALWAYS WORK HARD,14,6) will return

a] ALWAY
b} S ALWA
c] ALWAYS
6.  REPLACE('JACK AND JUE','J','BL') will return

a] JACK AND BLUE


b] BLACK AND JACK
c] BLACK AND BLUE
d] None of the above

7. EMPNO ENAME SAL


A822 RAMASWAMY 3500
A812 NARAYAN 5000
A973 UMESH 2850
A500 BALAJI 5750
  
Use these data for the following Questions
  
Select SAL from EMP E1 where 3 > ( Select count(*) from Emp E2
where E1.SAL > E2.SAL ) will retrieve
a] 3500,5000,2500
b] 5000,2850
c] 2850,5750
d] 5000,5750

8.  What is built_in Subprogram ?

a] Stored procedure & Function


b] Collection of Subprogram
c] Collection of Packages
d] None of the above

9. A developer would like to use referential datatype declaration on a variable.


The variable name is EMPLOYEE_LASTNAME, and the corresponding table
and column is EMPLOYEE, and LNAME, respectively. How would the
developer define this variable using referential datatypes?
A. Use employee.lname%type.
B. Use employee.lname%rowtype.
C. Look up datatype for EMPLOYEE column on LASTNAME table and use that.
D. Declare it to be type LONG.

10. The command used to open a CURSOR FOR loop is


A. open
B. fetch
C. parse
D. None, cursor for loops handle cursor opening implicitly.
11. . What is the value of customer_id within the nested block in the example
below?
/* Start main block */
DECLARE
 customer_id NUMBER(9) := 678;
 credit_limit NUMBER(10,2) := 10000;
BEGIN
 /* Start nested block */
DECLARE
 customer_id VARCHAR2(9) := 'AP56';
 current_balance NUMBER(10,2) := 467.87;
BEGIN
-- what is the value of customer_id at this point?
  NULL;
 END;
END;
Please select the best answer.
  A. 678
  B. 10000
  C. 'AP56'
  D. 467.87

12. Select incorrect variable declarations


A. foo_number varchar2(10);
B. foo_text number(10);
C. foo_char char(1) := 'Y';
D. foo_time date;
E. foo_text varchar2(10) := 'hello world';

13. Assuming the date and time is 09/09/2009 09:09:09, what value will the
following statement return SELECT
TO_CHAR(TRUNC(SYSDATE),'MM/DD/YYYY HH24:MI:SS') 
FROM dual;
  A. 09/09/2009 09:09:09
  B. 09/09/2009 09:09:09AM
  C. 09/09/2009
  D. 09/09/2009 00:00:00
  E. None of the above
14. The || is is an example of what function
SELECT last_name || ', ' || first_name || ' ' || middle_name
FROM employees;
  A. Incantination
  B. Integration
  C. Continuation
  D. Concatenation
  E. None of the above

15. Select the invalid PL/SQL looping construct.


  A. WHILE LOOP
                ...
                END LOOP;
  B. FOR rec IN some_cursor LOOP
                ...
                END LOOP;
  C. LOOP
                ...
                UNTIL ;
                END LOOP;
  D. LOOP
                ...
                EXIT WHEN ;
                END LOOP;
  E. None of the above. All are valid.

16. .  Which of the following is not a valid Oracle PL/SQL exception.


  A. NO_DATA_FOUND ORA-01403
  B. TWO_MANY_ROWS ORA-01422
  C. DUP_VAL_ON_INDEX ORA-00001
  D. OTHERS
  E. None of the above. These are all valid.

17. Select the best answer below.  What are the components of a package?
  A. Box, wrapping and binding
  B. Header and body
  C. Specification and content
  D. Specification and body
  E. None of the above

18. . What is the correct syntax to create procedure MYPROC that accepts two
number parameters X and Y? 
a.CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ...
b.CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...
c.CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...
d.CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER) ...

19. You want all dates when any employee was hired. Multiple employees were
hired on the same date and you want to see the date only once. 
Query - 1
Select distinct hiredate
From hr.employee
Order by hiredate;
Query - 2
Select hiredate
From hr.employees
Group by hiredate
Order by hiredate;
Which of the above query is valid?
A) Query - 1
B) Query - 2
C) Both

20. Select the best answer.  Which listed attribute is an invalid attribute of an
Explicit cursor.
  A. %NOTFOUND
  B. %FOUND
  C. %ROWCOUNT
  D. %ISOPEN
  E. None of the above. All of these are valid.

21. CREATE OR REPLACE FUNCTION CALC_PLAYER_AVG


(V_ID in PLAYER_BAT_STAT.PLAYER_ID%TYPE)
RETURN NUMBER
IS
V_AVG NUMBER;
BEGIN
SELECT HITS / AT_BATS
INTO V_AVG
FROM PLAYER_BAT_STAT
WHERE PLAYER_ID = V_ID;
RETURN (V_AVG);
END;

Which statement will successfully invoke this function in SQL *Plus?

A. SELECT CALC_PLAYER_AVG(PLAYER_ID)
FROM PLAYER_BAT_STAT;
B. EXECUTE CALC_PLAYER_AVG(31);
C. CALC_PLAYER(‘RUTH’);
D. CALC_PLAYER_AVG(31);
E. START CALC_PLAYER_AVG(31);

22. Examine this code:


CREATE OR REPLACE PRODECURE add_dept
(p_dept_name VARCHAR2 DEFAULT ‘placeholder’,
p_location VARCHAR2 DEFAULT ‘Boston’)
IS
BEGIN
INSERT INTO departments
VALUES (dept_id_seq.NEXTVAL, p_dept_name, p_location);
END add_dept;
/
Which three are valid calls to the add_dep procedure? (Choose three)
A. add_dept;
B. add_dept(‘Accounting’);
C. add_dept(, ‘New York’);
D. add_dept(p_location=>’New York’);

23. Which two programming constructs can be grouped within a package? (Choose two)
A. Cursor
B. Constant
C. Trigger
D. Sequence
E. View
24. Which code can you use to ensure that the salary is not increased by more than 10% at a
time nor is it
ever decreased?

A. ALTER TABLE emp ADD


CONSTRAINT ck_sal CHECK (sal BETWEEN sal AND sal*1.1);
B. CREATE OR REPLACE TRIGGER check_sal
BEFORE UPDATE OF sal ON emp
FOR EACH ROW
WHEN (new.sal < old.sal OR
new.sal > old.sal * 1.1)
BEGIN
RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease
salary not increase by more than 10%’);
END;
C. CREATE OR REPLACE TRIGGER check_sal
BEFORE UPDATE OF sal ON emp
WHEN (new.sal < old.sal OR
new.sal > old.sal * 1.1)
BEGIN
RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease
salary not increase by more than 10%’);
END;
D. CREATE OR REPLACE TRIGGER check_sal
AFTER UPDATE OR sal ON emp
WHEN (new.sal < old.sal OR
-new.sal > old.sal * 1.1)
BEGIN
RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease
salary not increase by more than 10%’);
END;

Question Number Answer


1 D
2 B
3 A
4 C
5 C
6 C
7 A
8 D
9 A
10 D
11 B
12 E
13 D
14 D
15 C,D
16 B
17 D
18 A
19 C
20 E
21 A
22 A,B,D
23 A,B
24 B

ANSWER --22

A is correct because both of the parameter have a default values.


B is correct because here we call the procedure using position notation, and the first parameter for the
procedure will have the value 'Accounting', and since the second parameter has a default value then
we
can skip it, and in this case it will take the default value.
D is correct because here we are calling the procedure using naming notation, the value 'New York'
will go
to the parameter p_location, and the parameter p_dept_name will have the default value.
The following table list the for passing parameters to a procedure:

You might also like