Wednesday, 3 May 2017

oracle sql,plsql questions

Q~:. All users currently have the INSERT privileges on the PLAYER table. You want only your users to insert into this table using the ADD_PLAYER procedure. Which two actions must you take? (Choose two)
A. GRANT SELECT ON ADD_PLAYER TO PUBLIC;
B. GRANT EXECUTE ON ADD_PLAYER TO PUBLIC;
C. GRANT INSERT ON PLAYER TO PUBLIC;
D. GRANT EXECUTE, INSERT ON ADD_PLAYER TO PUBLIC;
E. REVOKE INSERT ON PLAYER FROM PUBLIC;
Q~:. Which Oracle supply package allows you to run jobs at user defined times?
A. DBMS_JOB
B. DBMS_RUN
C. DBMS_PIPE
D. DBMS_SQL
Q~:. You need to drop a table from within a stored procedure. How do you implement this?
A. You cannot drop a table from a stored procedure.
B. Use the DROP command in the procedure to drop the table.
C. Use the DBMS_DDL packaged routines in the procedure to drop the table.
D. Use the DBMS_SQL packaged routines in the procedure to drop the table.
E. Use the DBMS_DROP packaged routines in the procedure to drop the table.
Q~:. Which data dictionary views give you the names and the source code of all the procedures that you have created?
A. USER_SOURCE
B. USER_OBJECTS
C. USER_PROCEDURES
D. USER_SUBPROGRAMS
Q~:. Examine this package
CREATE OR REPLACE PACKAGE BB_PACK
IS
V_MAX_TEAM_SALARY NUMBER(12,2);
PROCEDURE ADD_PLAYER(V_ID IN NUMBER, V_LAST_NAME VARCHAR2,V_SALARY NUMBER);
END BB_PACK;
/
CREATE OR REPLACE PACKAGE BODY BB_PACK
IS
V_PLAYER_AVG NUMBER(4,3);
PROCEDURE UPD_PLAYER_STAT
V_ID IN NUMBER, V_AB IN NUMBER DEFAULT4, V_HITS IN NUMBER)
IS
BEGIN
UPDATE PLAYER_BAT_STAT
SET ADD_BAT=ADD_BATS+V_AB,
HITS=HITS+V_HITS
WHERE PLAYER_ID=V_ID;
COMMIT;
VALIDATE_PLAYER_STAT(V_ID);
END UPD_PLAYER_STAT;
PROCEDURE ADD_PLAYER
(V_ID IN NUMBER, V_LAST_NAME, VARCHAR2, V_SALARY IN NUMBER);
IS
BEGIN
INSERT INTO PLAYER (ID, LAST_NAME, SALARY)
VALUES(V_ID, V_LAST_NAME, V_SALARY);
UPD_PLAYER_STAT(V_ID,0,0);
END ADD_PLAYER;
END BB_PACK;.22
Which kind of packaged variables is V_MAX_TEAM_SALARY?
A. PRIVATE
B. PUBLIC
C. IN
D. OUT
Q~:. Examine this trigger.
CREATE OR REPLACE TRIGGER UPD_TEAM_SALARY
AFTER INSERT OR UPDATE OR DELETE ON PLAYER
FOR EACH ROW
BEGIN
UPDATE TEAM
SET TOT_SALARY=TOT_SALARY+:NEW SALARY.
WHERE ID=:NEW:TEAM_ID;
You will be adding additional coat later but for now you want the current block to fire when updated the salary column. Which solution should you use to verify that the user is performing an update on the salary column?
A. ROW_UPDATE(‘SALARY’)
B. UPDATING(‘SALARY’)
C. CHANGING(‘SALARY’)
D. COLUMN_UPDATE(‘SALARY’)
Q~:. Examine this package:
CREATE OR REPLACE PACKAGE BB_PACK
V_MAX_TEAM_SALARY NUMBER(12,2);
PROCEDURE ADD_PLAYER(V_ID IN NUMBER, V_LAST_NAME
VARCHAR2, V_SALARY NUMBER);
BB_PACK;

 CREATE OR REPLACE PACKAGE BODY BB_PACK
IS
V_WHERE_AVG NUMBER(4,3);
PROCEDURE UPD_PLAYER_STAT
(V_ID IN NUMBER, V_AVG IN NUMBER DEFAULT 4,V_HITS IN NUMBER)
IS
BEGIN
UPDATE PLAYER_BAT_STAT
SET AT_BATS=AT_BATS+V_AB,
HITS=HITS+V_HITS
WHERE PLAYER_ID=V_ID;
COMMIT;
VALIDATE_PLAYER_STAT(V_ID);
END UPD_PLAYER_STAT;
PROCEDURE ADD-PLAYER
(V_ID IN NUMBER, V_LAST_NAME VARCHAR2, V_SALARY NUMBER)
IS
BEGIN
INSERT INTO PLAYER(ID, LAST_NAME, SALARY)
VALUES(V_ID, V_LAST_NAME, V_SALARY);
UPD_PLAYER_STAT(V_ID,0,0);
END ADD_PLAYER;
END BB_PACK;
An outside procedure VALIDATE_PLAYER_STAT is executed from this package.What will happen when this procedure changes?
A. The package specification is dropped.
B. The package specification is invalidated.
C. The package is invalidate.
D. The package body is invalidated.
Q~:. The PROCEDURE_ADD_PRODUCT is defined within a package specifications as follows:
PROCEDURE_ADD_PRODUCT (P_PRODNO NUMBER,P_PRODNAME VARCHER2);
Which procedure declaration can’t be added to package specifications?
A. PROCEDURE add_product (p_order_date DATE);
B. PROCEDURE add_product (p_name VARCHER2, P_ORDERED DATE);
C. PROCEDURE add_product (p_prodname VARCHER2, P_PRISE NUMBER);
D. PROCEDURE add_product (p_prize NUMBER, P_DESCRIPTION VARCHER2);
Q~:. Examine this package
CREATE OR REPLACE PACKAGE PACK_CUR
IS
CURSOR C1 IS
SELECT PRODID
FROM PRODUCT
ORDER BY PRODID DESC;
PROCEDURE PROC1;
PROCEDURE PROC2;
END PACK_CUR;
/
CREATE OR REPLACE PACKAGE BODY PACK_CUR
IS
V_ID NUMBER;
PROCEDURE PROC1 IS
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO V_PRODID;
DBMS_OUTPUT. PUT_LINE (ROW IS :,||C1/ROWCOUNT);
EXIT WHEN C1/ROWCOUNT>=3;
END LOOP;
END PROC1;
PROCEDURE PROC2 IS
BEGIN
LOOP
FETCH C1 TO V_PRODID
DBMS_OUTPUT. PUT_LINE (ROW IS :,||C1/ROWCOUNT);
EXIT WHEN C1/ROWCOUNT>=6;
END LOOP;
CLOSE C1;
END PROC2;
END PACK_CUR;
/
The products table has more than 1000 rows. The SQL plus server output setting is turned on in your session. You execute procedure proc1 from sql plus with the command:
EXECUTE PACK_CUR.PROC1. What is the output in your session?
A. Error at line 1
B. Row is:
Row is:
Row is:
C. Row is:1
Row is:2
Row is:3
D. Row is:4
Row is:5
Row is:6
Q~:. When creating procedures, local variables and arguments should be placed after which key words?
A. IS
B. BEGIN
C. DECLARED
D. PROCEDURE
Q~:. Which two statements about packages are true? (Choose two)
A. Both specifications and body are required components of a package.
B. Package specification is optional but the package body is required.
C. A package specification is required but the package body is optional.
D. The specification and body of the package is stored together in a database.
E. The specification and body of the package are stored separately in the database.
Q~:. You want to send a message to another session connected to the same instance. Which Oracle supplied package will you use to achieve this task?
A. DBMS_JOB
B. DBMS_PIPES
C. DBMS_OUTPUT
D. DBMS_MESSAGE
E. SEND_MESSAGE
Q~:. Which system privileges must you have to manually recompile a stored procedure owned by another application developer?
A. ALTER PROCEDURE
B. ALTER ANY PROCEDURE
C. ALTER ALL PROCEDURE
D. COMPILE ANY PROCEDURE
Q~:. Which situation requires a before update statement level trigger on the table?
A. When you need to populate values of each updated row into another table.
B. When a trigger must fire for each row affected by the triggering statement.
C. When you need to make sure that user making modifications to the table as necessary privileges.
D. When you need to store the information of the use who successfully modified tables and in audit table.
Q~:. Examine the trigger
Create a replace trigger cascade_updates
After update (Deptno) on Dept
For each row
BEGIN
UPDATE EMP
SET emp_deptno=: new. Deptno
WHERE emp.Deptno=: old.Deptno;
END
When this trigger will fire successfully?
A. Only when the dept no in the emp table holds a NULL value.
B. Irrespective of any referential integrity constraints between two tables.
C. When there is no referential integrity between the dept number columns of the emp and the dept tables within their table definitions.
D. Only when there is referential integrity constraint between the emp no columns of the emp and dept tables within their table definitions.
Q~:. Examine this code:
CREATE OR REPLACE PROCEUDRE AUDIT_EMP;
(P_ID IN EMP. EMPNO%TYPE)
IS
V_ID NUMBER;
PROCEDURE LOG_EXEC
IS
BEGIN
INSERT INTO LOG_TABLE (USER_ID,LOG_DATE)
VALUES (USERS,SYSDATE);
END LOG_EXEC
V_NAME VARCHAR2(20)
BEGIN
DELETE FROM EMP
WHERE EMPNO = P_ID;
LOG_EXEC;
SELECT ENAME,EMPNO
INTO V_NAME,V_ID
FROM EMP
WHERE EMPNO=P_ID
END AUDIT_EMP;
Why does this code cause and error when compiled?
A. An insert statement is not allowed in a sub program declaration.
B. The LOG_exec procedure should be declared before any identifiers.
C. The V_NAME variable should be declared before declaring the LOG_EXEC procedure.
D. The LOG_EXEC procedure should be invoked as execute log_exec with in the AUDIT_EMP procedure.
Q~:. When creating a function in which section will you typically find a return key word?
A. Header Only
B. Declarative
C. Executable and header
D. Executable and exception handling
Q~:. Examine this package
CREATE OR REPLACE PACKAGE COMPILE_THIS
IS
G_VALUE VARCHAR2(100);
PROCEDURE A;
PROCEDURE B;
END COMPILE_THIS;
/
CREATE OR REPLACE PACKAGE BODY COMPILE_THIS
IS
PROCEDURE A
IS
BEGIN
G_VALUE := (‘HELLO WORLD’);
END A;
PROCEDURE B
IS
BEGIN
C;
DBMS_OUTPUT. PUT_LINE (‘PROCEDURE B CALLING C’);
END B;
PROCEDURE C
IS
BEGIN
B;
DBMS_OUTPUT. PUT_LINE (‘PROCEDURE C CALLING B’);
END;
END COMILE_THIS; /
Procedure C is a local construct to the package. What happens when this package is compiled?
A. It produces the output Procedure B calling C
B. It produces the output Procedure C calling B
C. It produces a compilation error because procedure C requires a forward declaration.
D. It produces a compilation error because procedure B requires a forward declaration.
E. It produces a compilation error because identified g_value is not declared in procedure A
Q~:. The ADD_PLAYER, UPD_PLAYER_STAT and UPD_PITCHER_STAT procedures are grouped together in a package. A variable must be shared among only these procedures. Where should you declare this variable?
A. In the package body.
B. In the data base triggers.
C. In the package specification.
D. In the procedures declare section using the exact name in each.
Q~:. Examine the trigger heading
CREATE OR REPLACE TRIGGER SALARY_CHECK
Before update (sal,job) on emp
For each row
Under what conditions does this trigger fire?
A. When a row is inserted to EMP table.
B. When the value of the SAL or JOB column in a row is updated in a emp table.
C. When any column other than the sal or job columns in a row are updated in the EMP table.
D. Only when both values of sal or jobs column in a row are updated together in the EMP table.
Q~:. Which code can you use to ensure that the salary is neither increased by more than 10% at a time nor is ever decreased?
A. ALTER TABLE emp ADD
constraint_ck_sal CALC(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 nor
increase by more than 10%’);
END;
C. CREATE OR REPLACE TRIGGER check_sal
BEFORE UPDATE OF sal OR emp
WHEN (NEW.SAL<OLD.SAL OR
NEW.SAL>OLD.SAL*1.1)
BEGIN
RAISE_APPLICATION_ERROR(-20508, ‘Do not decrease salary nor
increase by more than 10%’);
D. CREATE OR REPLACE TRIGGER check_sal
AFTER UPDATE OF sal OR emp
WHEN (NEW.SAL<OLD.SAL OR
NEW.SAL>OLD.SAL*1.1)
BEGIN
RAISE_APPLICATION_ERROR(-20508, ‘Do not decrease salary nor
increase by more than 10%’);
END;
Q~:. Which command must you issue to allow users to access the UPD_TEAM_STAT trigger on the TEAM table?
A. GRANT SELECT, INSERT, UPDATE, DELETE ON TEAM TO PUBLIC;
B. GRANT SELECT, INSERT, UPDATE, DELETE ONUPD_TEAM_STAT TO PUBLIC;
C. GRANT EXECUTE ON TEAM TO PUBLIC;
D. GRANT SELECT, EXECUTE ON TEAM, UPD_TEAM_STAT TO PUBLIC;
Q~:. Which compiler directive to check the purity level of functions?
A. PRAGMA SECURITY_LEVEL.
B. PRAGMA SEARIALLY_REUSABLE.
C. PRAGMA RESTRICT_REFERRENCES.
D. PRAGMA RESTRICT_PURITY_LEVEL.
E. PRAGMA RESTRICT_FUNCTION_REFERRENCE.
Q~:. You have an AFTER UPDATE row-level trigger on the table EMP. This trigger queries the EMP table and inserts the updating users information into the AUDIT_TABLE. What happens when the users update rows on the EMP table?
A. A compile time error occurs.
B. A run time error occurs. The effect of the trigger body and the triggering statement are rolled back.
C. A run time error occurs. The effect of the trigger body is rolled back but the update on the EMP table takes place.
D. The trigger file successfully update the EMP file on the EMP table occurs and the data is asserted into the AUDIT_TABLE.
E. A run time error occurs. The update on the EMP table does not take place but the insert into the AUDIT_TABLE occurs.
Q~:. Given the header of a procedure ACCOUNT_TRANSACTION:
CREATE OR REPLACE PROCEDURE ACCOUNT_TRANSACTION
IS
BEGIN
END;
Which command will execute the PROCEDURE ACCOUNT_TRANSACTION from the SQL Plus prompt?
A. ACCOUNT_TRANSACTION;
B. RUN ACCOUNT_TRANSACTION;
C. START ACCOUNT_TRANSACTION;
D. EXECUTE ACCOUNT_TRANSACTION;
Q~:. Which one is the correct routine for the utilization order when using dynamic SQL?
A. Open, Parse, Bind, Execute, Fetch, Close
B. Parse, Bind, open, Execute, Close, Fetch
C. Bind, Open, Parse, Execute, Fetch, Close
D. Open, Bind, Parse, Execute, Close, Fetch
Q~:. Examine this trigger:
CREATE OR REPLACE TRIGGER UPD_PLAYER_STAT_TRIG
AFTER INSERT ON PLAYER
FOR EACH ROW
BEGIN
INSERT INTO PLAYER_BAT_STAT(PLAYER_ID, SEASON_YEAR,AT_BATS,HITS)
VALUES(player_id_seq.currval, 1997, 0, 0 );
END;
After creating this trigger, you test it by inserting a row into the PAYER table. You
receive this error message:
ORA-04091: table SCOTT.PLAYER is mutating,trigger/function may not see it.
How can you avoid getting this error?
A. Drop the foreign key contraint on the PLAYER_ID column of the PLAYER_BAT_STAT table.
B. Drop the primary key contraint on the PLAYER_ID column of the PLAYER_BAT_STAT table.
C. Drop the primary key constraint on the ID column of the PLAYER table.
D. The code of the trigger is invalid. Drop and recreate the trigger.
Q~:. Examine this package:.29
CREATE OR REPLACE PACKAGE manage_emps
IS
Tax_rate CONSTRAINT NUMBER(5,2):=. 28;
v_id NUMBER;
PROCEDURE insert_emp(p_dept NO NUMBER, p_sal NUMBER);
PROCEDURE delete_emp;
PROCEDURE update_emp;
FUNCTION calc_text(p_sal NUMBER)
RETURN NUMBER;
END manage_emps;
/
CREATE OR REPLACE PACKAGE BODY manage_emps
IS
PROCEDURE update_sal
(p_raise_amt NUMBER)
IS
BEGIN
UPDATE EMP
SET SAL=(SAL*p_raise_AMP)+SAL WHERE EMPNO=v_id;
END;
PROCEDURE insert_emp
(p_deptno NUMBER,p_sal NUMBER)
IS
BEGIN
INSERT INTO EMP(EMPNO,DEPTNO,SAL)
VALUES(v_id,p_deptno,p_sal);
INERT INTO EMP;
PROCEURE delete_emp
IS
BEGIN
DELETE FROM EMP
WHERE EMPNO=v_id;
END delete_emp;
PROCEDURE audit_emp;
IS
V_sal NUMBER(10,2);
V_raise NUMBER(10,2);
IS
SELECT SAL
INTO v_sal
FROM EMP
WHERE EMPNO=v_id;
IF v_sal<500 THEN v_raise:=. 05;ELSE
v_sal<1000 THEN v_raise:=. 07;ELSE
v_raise:=. 04;
END IF; update_sal (v_raise);
END update_emp; FUNCTION calc_tax
(p_sal NUMBER)
RETURN NUMBER
IS
BEGIN
RETURN p_sal*tax_rate;
END calc_tax;.30
END manage_emps;
/
How many public procedures are there in the MANAGE_EMPS package?
A. 1.
B. 2.
C. 3.
D. 4.
E. 5.
F. None.
Q~:. You want to execute a procedure from SQL Plus. However you are not sure of the argument list for this procedure. Which command will display the argument list?
A. DESCRIBE.
B. SHOWLIST.
C. SHOW ARG_LIST.
D. SHOW PROCEDURE.
Q~:. You are creating a stored procedure in the SQL Plus environment. The text of the procedure is stored in a script file. You run the script file to compile the procedure. What happens if the procedure contains syntax error?
A. Neither the source code nor the errors are stored in the database.
B. Both the source code and the compilation errors are stored in the database.
C. Compilation errors are appended to the script file that contains the source code.
D. The source code is stored in the database and the errors are stored in an output file.
E. The only compilation errors are written to the database and source code remains in the script file.
Q~:. Which statement about the forward declarations is true?
A. Forward declarations are not allowed in packages.
B. Forward declarations let you use mutually referential subprograms in a package.
C. A forward declaration means placing a subprogram declaration at the end of the package body.
D. Forward declaration in a package specification contains only the name of the sub program without the formal parameter list.
Q~:. Which statement is true?
A. Server side procedures are stored in script files on the server.
B. Server side procedures are visible in the ALL_SOURCE dictionary view.
C. Server side procedures are visible in the SERVER_SOURCE dictionary view.
D. Server side procedures are visible in the SERVER_PROCEDURE data dictionary view.

Q~:. Examine this package specification:
CREATE OR REPLACE PACKAGE concat_all
IS
V_string VARCHER2(100);
PROCEDURE combine(p_num_val NUMBER);
PROCEDURE combine (p_dateval DATE);
PROCEDURE combine(p_char_val VARCHER2,p_num_val NUMBER);
END concat_all;
Which overloaded COMBINE procedure declaration can be added to this package specification?
A. PROCEDURE combine;
B. PROCEDURE combine (p_no NUMBER);
C. PROCEDURE combine (p_val_1 VARCHER2,p_val_2 NUMBER);
D. PROCEDURE concat_all (p_num_val VARCHER2,p_char_val NUMBER);
Q~:. Examine this package body:
CREATE OR REPLACE PACKAGE BODY forward_pack
IS
V_sum NUMBER;
PROCEDURE calc_ord(. . . );
PROCEDURE generate_summary(. . . )
IS
BEGIN
Calc_ord(. . . );
. . .
END calc_ord;
END forward_pack;
Which construct has a forward declaration?
A. V_SUM
B. CALC_ORD.
C. FORWARD_PACK
D. GENERATE_SUMMARY.
Q~:. CREATE OR REPLACE PROCEDURE manage_emp(p_eno NUMBER)
IS
V_sal emp.sal%TYPE;
V_job emp.job%TYPE;
BEGIN
SELECT sal,job
INTO v_sal,v_job
FROM emp
WHERE empno=p_eno;
IF(v_sal<1000)THEN
DBMS_OUTPUT.PUT_LINE(‘Delete employees who earn less than$1000’);
DELETE FROM emp
WHERE empno=p_eno;
ELSE
DBMS_OUTPUT.PUT_LINE(‘Updating employee salaries.’);
UPDATE emp
SET sal=sal+100
WHERE empno=p_eno;
END IF;
END;
/
What privileges do you need in order to invoke this procedure?
A. No privileges are required.
B. EXECUTE privilege on the procedure.
C. EXECUTE privilege on the DBMS_OUTPUT package.
D. DELETE and UPDATE privilege on the table EMP.
E. EXECUTE privilege on the procedure, and delete and update privileges on the table EMP.
Q~:. The ADD_PLAYER procedure inserts rows into the player table. Which command will show this direct dependency?
A. SELECT * FROM USER_DEPENDENCIES WHERE REFFERENCE_NAME= ‘PLAYER’;
B. SELECT * FROM USER_DEPENDENCIES WHERE REFFERENCE_NAME= ‘ADD_PLAYER’;
C. SELECT * FROM USER_DEPENDENCIES WHERE TYPE= ‘DIR’;
D. SELECT * FROM USER_DEPENDENCIES WHERE REFFERENCE_NAME= ‘TABLE’;
Q~:. Examine this procedure:
CREATE OR REPLACE PROCEDURE ADD_PLAYER
(V_ID IN NUMBER, V_LAST_NAME VARCHER2(30))
IS
BEGIN
INSERT INTO PLAYER(ID, LAST_NAME)
VALUES(V_ID, V_LAST_NAME);
COMMIT;
END;
Why does this command fail when executed?
A. When declaring arguments length is not allowed.
B. When declaring arguments each argument must have a mode specified.
C. When declaring arguments each argument must have a length specified.
D. When declaring a VARCHAR2 argument it must be specified.
Q~:. Examine this trigger:
CREATE OR REPLACE TRIGGER CHECK_TOT_SALARY
AFTER INSERT OR UPDATE OF SALARY ON PLAYER
FOR EACH ROW
DECLARE
V_TOT_SALS NUMBER(12, 2);
BEGIN
SELECT SUM(SALARY)
INTO V_TOT_SAL
FROM PLAYER
WHER TEAM_ID=:NEW. SALARY;
END;
Why does this trigger fail when inserting a row into player table?
A. You can’t read data from a table that is being affected by the same trigger.
B. You can’t use the sum function with row triggers.
C. You can’t use the sum function with statement triggers.
D. You can’t reference :NEW with row triggers.
Q~:. Which procedure of the dbms_output supply package would you use to append text to the current line of the output buffer?
A. GET.
B. GET_LINE.
C. PUT_TEXT_LINE.
D. PUT_LINE.
Q~:. What happens during the parse phase with dynamic SQL?
A. Rows are selected and ordered.
B. The number of rows processed is returned.
C. The validity of the SQL statement is established.
D. An area of memory is established to process the SQL statement.
E. An area of memory is established to process the SQL statement is released.
Q~:. Which script file must be executed before you can determine indirect independence’s using
the DEPTREE AND IDEPTREE VIEWS?
A. UTL_IDEPT.SQL.
B. UTLIDD.SQL.
C. UTLINDD.SQL.
D. UTLDTREE.SQL
Q~:. Debug the logic in a stored procedure. How do you monitor the value of variables in the procedure using SQL Plus environment?
A. INSERT TEXT_IO.PUT_LINE statement to view data on the screen when the stored procedure is executed.
B. Insert break points in the code and observe the variable values displayed to the screen as the procedure is executed.
C. Insert DBMS_OUTPUT.PUT_LINE statement to view data on the screen when the stored procedure is executed.
D. Insert DEBUG VARIABLE statements to view the variable values on the screen as the procedure is executed.
Q~:. Which two statements are true? (Choose two)
A. A function must return a value.
B. A procedure must return a value.
C. A function executes a PL/SQL statement.
D. A function is invoked as part of an expression.
E. A procedure must have a return data type specify in its declaration.
Q~:. Which allows a PL/SQL user define a function?
A. NEXTVAL.
B. HAVING clause of the SELECT COMMAND.
C. ALTER TABLE command.
D. FROM clause of the SELECT AN UPDATE COMMANDS.
Q~:. CREATE OR REPLACE PROCEDURE set_bonus (p_cutoff IN VARCHAR2 DEFAULT 'WEEKLY',
p_employee_id IN employees_employee_id%TYPE,p_salary IN employees_salary%TYPE,
p_bonus_percent IN OUT NUMBER DEFAULT 1.5, p_margin OUT NUMBER DEFAULT 2,
p_bonus_value OUT NUMBER)
IS
BEGIN
UPDATE emp_bonus
SET bonus_amount =(p_salary * p_bonus_percent)/p_margin
WHERE employee_id = p_employee_id;
END set_bonus;
You execute the CREATE PROCEDURE statement above and notice that it fails. What are two
reasons why it fails? (Choose two)
A. The syntax of the UPDATE statement is incorrect.
B. You cannot update a table using a stored procedure.
C. The format parameter p_bonus_value is declared but is not used anywhere.
D. The formal parameter p_cutoff cannot have a DEFAULT clause.
E. The declaration of the format parameter p_margin cannot have a DEFAULT clause.
F. The declaration of the format parameter p_bonus_percent cannot have a DEFAULT clause.
Q~:. Which three statements are true regarding database triggers? (Choose three)
A. A database trigger is a PL/SQL block, C, or Java procedure associated with a table, view, schema, or the database.
B. A database trigger needs to be executed explicitly whenever a particular event takes place .
C. A database trigger executes implicitly whenever a particular event takes place.
D. A database trigger fires whenever a data event (such as DML) or system event (such as logon, shutdown) occurs on a schema or database.
E. With a schema, triggers fire for each event for all users; with a database, triggers fire for each event for that specific user.
Q~:. A dependent procedure or function directly or indirectly references one or more of which four objects? (Choose four)
A. view
B. sequence
C. privilege
D. procedure
E. anonymous block
F. packaged procedure or function


Q~:. Examine this package:
CREATE OR REPLACE PACKAGE pack_cur
IS
CURSOR c1 IS
SELECT prodid
FROM product
ORDER BY Prodid DESC;
PROCEDURE Proc1;
PROCEDURE Proc2;
END pack_cur;
/
CREATE OR REPLACE PACKAGE BODY pack_cur
IS
v_prodif NUMBER;
PROCEDURE proc1 IS
BEGIN
OPEN C1;
LOOP
PROCEDURE proc2 IS
BEGIN
LOOP
FETCH C1 INTO v_prodid;
DBMS_OUTPUT-PUT_LINE ( ' Row is: ' ll c1 %ROWCOUNT);
EXIT WHEN C1%ROWCOUNT >= 3;
END LOOP;
END Procl;
/
The product table has more than 1000 rows. The SQL*Plus SERVEROUTPUT setting is turned
on in your session.
You execute the procedure PROC1 from SQL *Plus with the command:
EXECUTE pack_cur. PROC1;
You then execute the procedure PROC2 from SQL *Plus with the command:
EXECUTE pack_cur. PROC2;
What is the output in your session from the PROC2 procedure?
A. ERROR at line 1:
B. Row is:
Row is:
Rows is:
C. Row is: 1
Row is: 2
Row is: 3
D. Row is: 4
Row is: 5
Row is: 6
Q~:. You have the following table:
CREATE TABLE Emp_log (
Emp_id NUMBER
Log_date DATE,
New_salary NUMBER,
Action VARCHAR (20));
You have the following data in the EMPLOYEES table:
EMPLOYEE_ID LAST_NAME SALARY DEPARTMENT_ID
----------- ------------------- ------------ -------------
Q~: King 24000 90
Q~: Kochhar 17000 90
Q~: De Haan 17000 90
Q~: Hunold 9000 60
Q~: Ernst 6000 60
Q~: Austin 4800 60
Q~: Pataballa 4800 60
Q~: Lorentz 4200 60
Q~: Greenberg 12000 100
Q~: Hartstein 13000 20
Q~: Fay 6000 20
You create this trigger:
CREATE OR REPLACE TRIGGER Log_salary_increase.
AFTER UPDATE ON employees
FOR EACH ROW
WHEN (new.Salary > 1000)
BEGIN
INSERT INTO Emp_log (Emp_id, Log_date, New_Salary, Action)
VALUES (: new.Employee_id, SYSDATE, :new.salary, 'NEW SAL' );
END
/
Then, you enter the following SQL statement:
UPDATE Employee SET Salary = Salary + 1000.0
Where Department_id = 20
What are the result in the EMP_LOG table?
A.
EMP_ID LOG_DATE NEW_SALARY ACTION
---------- -------- ---------- ----------
Q~: 24-SEP-02 13000 NEW SAL
Q~: 24-SEP-02 600 NEW SAL
B.
EMP_ID LOG_DATE NEW_SALARY ACTION
---------- -------- ---------- ----------
Q~: 24-SEP-02 14000 NEW SAL
Q~: 24-SEP-02 7000 NEW SAL
C.
EMP_ID LOG_DATE NEW_SALARY ACTION
---------- -------- ---------- ----------
Q~: 24-SEP-02 NEW SAL
Q~: 24-SEP-02 NEW SAL
D. No rows are inserted.
Q~:. Examine this code:
CREATE OR REPLACE FUNCTION gen_email_name
(p_first VARCHAR2, p_last VARCHAR2)
RETURN VARCHAR2
IS
v_email_name VARCHAR (19) ;
BEGIN
v_email_bame := SUBSTR(p_first, 1, 1) || SUBSRE(p_last, 1, 7) ||
RETURN v_email_name;
END
/
Which two statements are true?(Choose Two)
A. This function is invalid.
B. This function can be used against any table.
C. This function cannot be used in a SELECT statement.
D. This function can be used only if the two parameters passed in are not bull values.
E. This function will generate a string based on 2 character values passed into the function.
F. This function can be used only on tables where there is a p_first and p_last column.
Q~:. Examine the code examples. Which one is correct?
A. CREATE OR REPLACE TRIGGER authorize_action BEFORE INSERT ON EMPLOYEES
CALL log_exectution; /
B. CREATE OR REPLACE TRIGGER authorize_action BEFORE EMPLOYEES INSERT
CALL log_exectution;
C. CREATE OR REPLACE TRIGGER authorize_action BEFORE EMPLOYEES INSERT
CALL log_exectution;
D. CREATE OR REPLACE TRIGGER authorize_action CALL log_exectution; BEFORE INSERT
ON EMPLOYEES; /
Q~:. Which of the following statements about LOB are true? (Choose Three)
A. LOB is a database object
B. LOB represents a data type that is used to store large, unstructured data.
C. LOB can be stored inside or outside a database.
D. Internal LOB is a category of LOB.
Q~:. Examine the following statement:
CREATE OR REPLACE TRIGGER Check_sal BEFORE UPDATE OF SALARY ON
EMPLOYEES for each ROW
WHEN (NEW.salary < OLD. Salary OR NEW.Salary > OLD.salary * 1.2)
BEGIN
RAISE_APPLICATION_ERROR(-20004,’You cannot increase salary by more than 10% nor
can you decrease it’);
END;
What will happen when you execute the statement?
A. the statement will fail because the OLD and NEW qualifiers are not prefixed with a colon (:).
B. the statement will fail because a trigger cannot be defined on a particular column of a table.
C. The statement will execute successfully and the trigger will be created.
D. The statement will execute successfully and the trigger will be created, but the trigger will fail when the salary column of the Employees table is updated.
Q~:. You work as an application developer for Dolliver Inc. The company uses an oracle database. You own subprograms that reference to other subprograms on remote locations. Oracle server uses the signature mode of remote dependency in order to manage remote dependencies among the subprograms. Which of the following statements about the signature mode of dependency are true? (Choose two)
A. Oracle Server records only the signature for each PL/SQL program unit.
B. Using the signature mode prevents the unnecessary recompilation of dependent local procedures, as it allows remote procedures to be recompiled without affecting the dependent local procedures.
C. Signature mode is the default mode of remote dependency.
D. Oracle server records both the timestamp and the signature for each PL/SQL program unit.
Q~:. You work as an application developer for federal Inc. the company uses an Oracle database. You have created a function named My_Func in the database. You want to change the arguments declared for the function. Before changing the arguments you want to see the names of the procedures and other functions that invoke the My_Func function. Which of the following data dictionary views will you query to accomplish this? (choose two)
A. USER_DB_LINKS
B. ALL_DEPENDENCIES
C. USER_DEPENDENCIES
D. USER_SOURCE.
Q~:. You work as an application developer for federal Inc. the company uses an oracle database. The database contains a package named G_Comm. You want to remove the package specification from the database while retaining the package body. Which of the following statements will you use to accomplish this?
A. DROP Package G_Comm;
B. DROP Package Specification G_Comm;
C. DROP Package Body G_Comm;
D. You cannot accomplish this;
Q~:. Which of the following Oracle supplied package is used to enable HTTP callouts from
PL/SQL and SQL to access data on the Internet?
A. DBMS_DDL
B. UTL_HTTP
C. UTL_SMTP
D. UTL_URL
Q~:. The DBMS_DDL package provides access from within PL/SQL to:
A. One DDL
B. Two DDL
C. Three DDL
D. Four DDL
Q~:. If there is any changes applied to the package specification or body of a stored sub-program which statement is true about it?
A. Package Specification only requires recompilation
B. Package body only requires recompilation
C. both package & body requires recompilation
D. both package & body does not require recompilation.
Q~:. You disabled all triggers on the EMPLOYEES table to perform a data load. Now, you need to enable all triggers on the EMPLOYEES table. Which command accomplished this?
A. You cannot enable multiple triggers on a table in one command.
B. ALTER TRIGGERS ON TABLE employees ENABLE;
C. ALTER employees ENABLE ALL TRIGGERS;
D. ALTER TABLE employees ENABLE ALL TRIGGERS;
Q~:. Which statement is true?
A. Stored functions can be called from the SELECT and WHERE clauses only.
B. Stored functions do not permit calculations that involve database links in a distributed environment.
C. Stored functions cannot manipulate new types of data, such as longitude and latitude.
D. Stored functions can increase the efficiency of queries by performing functions in the query rather than in the application.
Q~:. Examine this code:
CREATE OR REPLACE STORED FUNCTION get_sal (p_raise_amt NUMBER, p_employee_id employees.employee_id%TYPE) RETURN NUMBER
IS
v_salary NUMBER;
v_raise NUMBER(8,2);
BEGIN
SELECT salary
INTO v_salary
FROM employees
WHERE employee_id = p_employee_id;
v_raise := p_raise_amt * v_salary;
RETURN v_raise;
END;
Which statement is true?
A. This statement creates a stored procedure named get_sal.
B. This statement returns a raise amount based on an employee id.
C. This statement creates a stored function named get_sal with a status of invalid.
D. This statement creates a stored function named get_sal.
E. This statement fails.
Q~:. Examine this code:
 CREATE OR REPLACE PACKAGE metric_converter
IS
c_height CONSTRAINT NUMBER := 2.54;
c_weight CONSTRAINT NUMBER := .454;
FUNCTION calc_height (p_height_in_inches NUMBER) RETURN NUMBER;
 FUNCTION calc_weight (p_weight_in_pounds NUMBER) RETURN NUMBER;
END; /
CREATE OR REPLACE PACKAGE BODY metric_converter
 IS
 FUNCTION calc_height (p_height_in_inches NUMBER) RETURN NUMBER
 IS
 BEGIN
 RETURN p_height_in_inches * c_height;
 END calc_height;
FUNCTION calc_weight (p_weight_in_pounds NUMBER) RETURN NUMBER
 IS
BEGIN
RETURN p_weight_in_pounds * c_weight
 END calc_weight ;
END metric_converter; /

CREATE OR REPLACE FUNCTION calc_height (p_height_in_inches NUMBER) RETURN
NUMBER
IS
BEGIN
RETURN p_height_in_inches * metric_converter.c_height;
 END calc_height; /
 Which statement is true?
A. If you remove the package specification, then the package body and the stand alone stored function
CALC_HEIGHT are removed.
B. If you remove the package body, then the package specification and the stand alone stored function
CALC_HEIGHT are removed.
C. If you remove the package specification, then the package body is removed.
D. If you remove the package body, then the package specification is removed.
E. If you remove the stand alone stored function CALC_HEIGHT, then the METRIC_CONVERTER package body and the package specification are removed.
F. The stand alone function CALC_HEIGHT cannot be created because its name is used in a packaged function.
Q~:. You need to create a DML trigger. Which five pieces need to be identified? (Choose five)
A. Table
B. DML event
C. Trigger body
D. Package body
E. Package name
F. Trigger name
G. System event.
H. Trigger timing
Q~:. Procedure PROCESS_EMP references the table EMP. Procedure UPDATE_EMP updates rows of table EMP through procedure PROCESS_EMP. There is a remote procedure QUERY_EMP that queries the EMP table
through the local procedure PROCESS_EMP. The dependency mode is set to TIMESTAMP in this session.
Which two statements are true? (Choose two)
A. If the signature of procedure PROCESS_EMP is modified and successfully recompiles, the EMP table is invalidated.
B. If internal logic of procedure PROCESS_EMP is modified and successfully recompiles, UPDATE_EMP gets invalidated and will recompile when invoked for the first time.
C. If the signature of procedure PROCESS_EMP is modified and successfully recompiles, UPDATE_EMP gets invalidated and will recompile when invoked for the first time.
D. If internal logic of procedure PROCESS_EMP is modified and successfully recompiles, QUERY_EMP gets invalidated and will recompile when invoked for the first time.
E. If internal logic of procedure PROCESS_EMP is modified and successfully recompiles, QUERY_EMP gets invalidated and will recompile when invoked for the second time.
Q~:. When using a packaged function in a query, what is true?
A. The COMMIT and ROLLBACK commands are allowed in the packaged function.
B. You can not use packaged functions in a query statement.
C. The packaged function cannot execute an INSERT, UPDATE, or DELETE statement against the table that is being queried.
D. The packaged function can execute and INSERT, UPDATE, or DELETE statement against the table that is being queried if it is used in a subquery.
E. The packaged function can execute an INSERT, UPDATEM or DELETE statement against the table that is being queried if the pragma RESTRICT REFERENCE is used.
Q~:. Which three are true regarding error propagation? (Choose three)
A. An exception cannot propagate across remote procedure calls.
B. An exception raised inside a declaration immediately propagates to the current block.
C. The use of the RAISE; statement in an exception handler reprises the current exception
D. An exception raised inside an exception handler immediately propagates to the enclosing block.

  1. Examine this procedure:
CREATE OR REPLACE PROCEDURE DELETE_PLAYER(V_ID IN NUMBER)
IS BEGIN
 DELETE FROM PLAYER
 WHERE ID = V_ID
EXCEPTION
 WHEN STATS_EXITS_EXCEPTION THEN
 DBMS_OUTPUT.PUT_LINE(Cannotdeletethisplayer, childrecordsexistin PLAYER_BAT_STAT table);
END;

What prevents this procedure from being created successfully?

A. A comma has been left after the STATS_EXIST_EXCEPTION exception.
B. The STATS_EXIST_EXCEPTION has not been declared as a number.
C. The STATS_EXIST_EXCEPTION has not been declared as an exception.
D. Only predefined exceptions are allowed in the EXCEPTION section.

Q~:. Under which two circumstances do you design database triggers? (Choose two)

A. To duplicate the functionality of other triggers.
B. To replicate built-in constraints in the Oracle server such as primary key and foreign key.
C. To guarantee that when a specific operation is performed, related actions are performed.
D. For centralized, global operations that should be fired for the triggering statement, regardless of which user or application issues the statement.

Q~:. Local procedure A calls remote procedure B. Procedure B was compiled at 8 A.M. Procedure
A was modified and recompiled at 9 A.M. Remote procedure B was later modified and
recompiled at 11 A.M. The dependency mode is set to TI MESTAMP. What happens when
procedure A is invoked at 1 P.M?

A. There is no affect on procedure A and it runs successfully.
B. Procedure B is invalidated and recompiles when invoked.
C. Procedure A is invalidated and recompiles for the first time it is invoked.
D. Procedure A is invalidated and recompiles for the second time it is invoked.

Q~:. What is a condition predicate in a DML trigger?

A. A conditional predicate allows you to specify a WHEN-LOGGING-ON condition in the trigger body.
B. A conditional predicate means you use the NEW and OLD qualifiers in the trigger body as a condition.
C. A conditional predicate allows you to combine several DML triggering events into one in the trigger body.
D. A conditional predicate allows you to specify a SHUTDOWN or STARTUP condition in the trigger body.

Q~:. This statement fails when executed:

CREATE OR REPLACE TRIGGER CALC_TEAM_AVG
AFTER INSERT ON PLAYER
BEGIN
INSERT INTO PLAYER_BATSTAT (PLAYER_ID, SEASON_YEAR, AT_BATS, HI TS)
VALUES (:NEW.ID, 1997, 0, 0) ;
END;

To which type must you convert the trigger to correct the error?
A. Row
B. Statement
C. ORACLE FORM trigger
D. Before

Q~:. An internal LOB is _____.
A. A table.
B. A column that is a primary key.
C. Stored in the database.
D. A file stored outside of the database, with an internal pointer to it from a database column.

Q~:. You need to disable all triggers on the EMPLOYEES table. Which command accomplishes this?
A. None of these commands; you cannot disable multiple triggers on a table in one command.
B. ALTER TRIGGERS ON TABLE employees DISABLE;
C. ALTER employees DISABLE ALL TRIGGERS;
D. ALTER TABLE employees DISABLE ALL TRIGGERS;

Q~:. You have a row level BEFORE UPDATE trigger on the EMP table. This trigger contains a SELECT statement on the EMP table to ensure that the new salary value falls within the minimum and maximum salary for a given job title. What happens when you try to update a salary value in the EMP table?
A. The trigger fires successfully.
B. The trigger fails because it needs to be a row level AFTER UPDATE trigger.
C. The trigger fails because a SELECT statement on the table being updated is not allowed.
D. The trigger fails because you cannot use the minimum and maximum functions in a BEFORE UPDATE trigger.

Q~:. You need to implement a virtual private database (vpd). In order to have the vpd functionality, a trigger is required to fire when every user initiates a session in the database. What type of trigger needs to be created?
A. DML trigger
B. System event trigger
C. INSTEAD OF trigger
D. Application trigger
Q~:. Which two program declarations are correct for a stored program unit? (Choose two)
A. CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER
B. CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER) RETURN NUMBER
C. CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER)
D. CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER(10,2)
E. CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER(10, 2))
Q~:. The creation of which four database objects will cause a DDL trigger to fire? (Choose four)
A. Index
B. Cluster
C. Package
D  Function
E. Synonyms
F. Dimensions
G. Database links.4
Q~:. Examine this code:
CREATE OR REPLACE PROCEDURE insert_dept (p_location_id NUMBER)
IS
v_dept_id NUMBER(4);
BEGIN
INSERT INTO departments
VALUES (5, .Education., 150, p_location_id);
SELECT department_id INTO v_dept_id FROM employees WHERE employee_id=99999;
END insert_dept; /
CREATE OR REPLACE PROCEDURE insert_location ( p_location_id NUMBER, p_city
VARCHAR2)
IS BEGIN
INSERT INTO locations(location_id, city)
VALUES (p_location_id, p_city);
insert_dept(p_location_id);
END insert_location; /
You just created the departments, the locations, and the employees table. You did not insert any
rows. Next you created both procedures. You new invoke the insert_location procedure using
the following command: EXECUTE insert_location (19, .San Francisco .) What is the result in
this EXECUTE command?
A. The locations, departments, and employees tables are empty.
B. The departments table has one row. The locations and the employees tables are empty.
C. The location table has one row. The departments and the employees tables are empty.
D. The locations table and the departments table both have one row. The employees table is empty.
Q~:. What is true about stored procedures?
A. A stored procedure uses the DELCLARE keyword in the procedure specification to declare formal parameters.
B. A stored procedure is named PL/SQL block with at least one parameter declaration in the procedure specification.
C. A stored procedure must have at least one executable statement in the procedure body.
D. A stored procedure uses the DECLARE keyword in the procedure body to declare formal parameters.
Q~:. Examine the trigger:
CREATE OR REPLACE TRIGGER Emp_count
AFTER DELETE ON Emp_tab
FOR EACH ROW
DELCARE n INTEGER;
BEGIN
SELECT COUNT (*)
INTO n
FROM Emp_tab;
DMBS_OUTPUT.PUT_LINE (‘There are now’  ||n || ‘ employees’);
END;
This trigger results in an error after this SQL statement is entered: DELETE FROM Emp_tab
WHERE Empno = 7499;
How do you correct the error?
A. Change the trigger type to a BEFORE DELETE.
B. Take out the COUNT function because it is not allowed in a trigger.
C. Remove the DBMS_OUTPUT statement because it is not allowed in a trigger.
D. Change the trigger to a statement-level trigger by removing FOR EACH ROW.
Q~:. The OLD and NEW qualifiers can be used in which type of trigger?
A. Row level DML trigger
B. Row level system trigger
C. Statement level DML trigger
D. Row level application trigger
E. Statement level system trigger
F. Statement level application trigger
Q~:. Which view displays indirect dependencies, indenting each dependency?
A. DEPTREE
B. IDEPTREE
C. INDENT_TREE
D. I_DEPT_TREE
Q~:. Examine this code:
CREATE OR REPLACE PROCEDURE audit_action (p_who VARCHAR2)
 AS
BEGIN
INSERT INTO audit(schema_user)
VALUES(p_who);
END audit_action; /
CREATE OR REPLACE TRIGGER watch_it
AFTER LOGON ON DATABASE CALL audit_action(ora_login_user) /
What does this trigger do?
A. The trigger records an audit trail when a user makes changes to the database.
B. The trigger marks the user as logged on to the database before an audit statement is issued.
C. The trigger invoked the procedure audit_action each time a user logs on to his/her schema and adds the username to the audit table.
D. The trigger invokes the procedure audit_action each time a user logs on to the database and adds the username to the audit table.
Q~:. Examine this procedure:
CREATE OR REPLACE PROCEDURE UPD_BAT_STAT (V_ID IN NUMBER DEFAULT 10,
V_AB IN NUMBER DEFAULT 4) IS
BEGIN
UPDATE PLAYER_BAT_STAT
SET AT_BATS = AT_BATS + V_AB
WHERE PLAYER_ID = V_ID;
COMMIT;
END;
Which two statements will successfully invoke this procedure in SQL *Plus? (Choose two)
A. EXECUTE UPD_BAT_STAT;
B. EXECUTE UPD_BAT_STAT(V_AB=>10, V_ID=>31);
C. EXECUTE UPD_BAT_STAT(31, 'FOUR', 'TWO');
D. UPD_BAT_STAT(V_AB=>10, V_ID=>31);
E. RUN UPD_BAT_STAT;
Q~:. Examine this code:
CREATE OR REPLACE FUNCTION gen_email_name (p_first_name VARCHAR2, p_last_name VARCHAR2, p_id NUMBER)  RETURN VARCHAR2
IS
v_email_name VARCHAR2(19);
BEGIN
v_email_name := SUBSTR(p_first_name, 1, 1) || SUBSTR(p_last_name, 1, 7) || '@oracle.com’ ;
UPDATE employees
 SET email = v_email_name
WHERE employee_id = p_id;
 RETURN v_email_name;
END;
Which statement removes the function?
A. DROP gen_email_name;
B. REMOVE gen_email_name;
C. DELETE gen_email_name;
D. DROP FUNCTION gen_email_name;
Q~:. Examine this code:
CREATE OR REPLACE PACKAGE comm_package IS
g_comm NUMBER := 10;
PROCEDURE reset_comm(p_comm IN NUMBER);
END comm_package; /
User Jones executes the following code at 9:01am:
EXECUTE comm_package.g_comm := 15
User Smith executes the following code at 9:05am:
EXECUTE comm_paclage.g_comm := 20 Which statement is true?
A. g_comm has a value of 15 at 9:06am for Smith.
B. g_comm has a value of 15 at 9:06am for Jones.
C. g_comm has a value of 20 at 9:06am for both Jones and Smith.
D. g_comm has a value of 15 at 9:03 am for both Jones and Smith.
E. g_comm has a value of 10 at 9:06am for both Jones and Smith.
F. g_comm has a value of 10 at 9:03am for both Jones and Smith
Q~:. Examine this package:
CREATE OR REPLACE PACKAGE BB_PACK
IS
 V_MAX_TEAM_SALARY NUMBER(12,2);
PROCEDURE ADD_PLAYER(V_ID IN NUMBER, V_LAST_NAME VARCHAR2, V_SALARY NUMBER);
END BB_PACK; /

CREATE OR REPLACE PACKAGE BODY BB_PACK IS
V_PLAYER_AVG NUMBER(4,3);
PROCEDURE UPD_PLAYER_STAT V_ID IN NUMBER, V_AB IN NUMBER DEFAULT 4,
V_HITS IN NUMBER) IS
BEGIN
 UPDATE PLAYER_BAT_STAT
 SET AT_BATS = AT_BATS + V_AB, HITS = HITS +V_HITS
 WHERE PLAYER_ID = V_ID;
COMMIT;
VALIDATE_PLAYER_STAT(V_ID);
END UPD_PLAYER_STAT;

PROCEDURE ADD_PLAYER (V_ID IN NUMBER, V_LAST_NAME VARCHAR2,
V_SALARY NUMBER) IS
BEGIN INSERT INTO PLAYER(ID,LAST_NAME,SALARY) VALUES (V_ID,
V_LAST_NAME, V_SALARY); UPD_PLAYER_STAT(V_ID,0,0);
END ADD_PLAYER;
END BB_PACK /

Which statement will successfully assign .333 to the V_PLAYER_AVG variable from a
procedure outside the package?
A. V_PLAYER_AVG := .333;.7
B. BB_PACK.UPD_PLAYER_STAT.V_PLAYER_AVG := .333;
C. BB_PACK.V_PLAYER_AVG := .333;
D. This variable cannot be assigned a value from outside of the package.
Q~:. What can you do with the DBMS_LOB package?
A. Use the DBMS_LOB.WRITE procedure to write data to a BFILE.
B. Use the DBMS_LOB.BFILENAME function to locate an external BFILE.
C. Use the DBMS_LOB.FILEEXISTS function to find the location of a BFILE.
D. Use the DBMS_LOB.FILECLOSE procedure to close the file being accessed.
Q~:. Examine this package:
CREATE OR REPLACE PACKAGE manage_emps
IS
tax_rate CONSTANT NUMBER(5,2) := .28;
v_id NUMBER;
PROCEDURE insert_emp (p_deptno NUMBER, p_sal NUMBER);
PROCEDURE delete_emp; PROCEDURE update_emp;
FUNCTION calc_tax (p_sal NUMBER) RETURN NUMBER;
END manage_emps; /

CREATE OR REPLACE PACKAGE BODY manage_emps IS
PROCEDURE update_sal (p_raise_amt NUMBER)
IS
BEGIN
UPDATE emp SET sal = (sal * p_raise_emt) + sal
WHERE empno = v_id;
END;
PROCEDURE insert_emp (p_deptno NUMBER, p_sal NUMBER)
IS
BEGIN
INSERT INTO emp(empno, deptno, sal)
VALUES(v_id, p_depntno, p_sal);
END insert_emp;
PROCEDURE delete_emp
IS
BEGIN
DELETE FROM emp
WHERE empno = v_id;
END delete_emp;
PROCEDURE update_emp IS
 v_sal NUMBER(10, 2);
 v_raise NUMBER(10, 2);
BEGIN
 SELECT sal
 INTO v_sal
FROM emp
WHERE empno = v_id;
IF v_sal < 500 THEN
  v_raise := .05;
ELSIF v_sal < 1000 THEN
  v_raise := .07;
ELSE v_raise := .04;
END IF;
update_sal(v_raise);
END update_emp;

FUNCTION calc_tax (p_sal NUMBER) RETURN NUMBER IS
BEGIN RETURN p_sal * tax_rate;
END calc_tax;
END manage_emps; /
What is the name of the private procedure in this package?
A. CALC_TAX
B. INSERT_EMP
C. UPDATE_SAL
D. DELETE_EMP
E. UPDATE_EMP
F. MANAGE_EMPS
Q~:. Which two dopes the INSTEAD OF clause in a trigger identify? (Choose two)
A. The view associated with the trigger.
B. The table associated with the trigger.
C. The event associated with the trigger.
D. The package associated with the trigger.
E. The statement level or for each row association to the trigger.
Q~:. Which three are valid ways to minimize dependency failure? (Choose three)
A. Querying with the SELECT * notification.
B. Declaring variables with the %TYPE attribute.
C. Specifying schema names when referencing objects.
D. Declaring records by using the %ROWTYPE attribute.
E. Specifying package.procedure notation while executing procedures.
Q~:. Examine this code:
 CREATE OR REPLACE PROCEDURE add_dept ( p_name departments.department_name%TYPE DEFAULT ‘unknown’, p_loc departments.location_id%TYPE DEFAULT 1700)
 IS
BEGIN
INSERT INTO departments (department_id, department_name, loclation_id)
VALUES (dept_seq.NEXTVAL,p_name, p_loc);
END add_dept; /

You created the add_dept procedure above, and you now invoke the procedure in SQL *Plus.
Which four are valid invocations? (Choose four)
A. EXECUTE add_dept(p_loc=>2500)
B. EXECUTE add_dept('Education', 2500)
C. EXECUTE add_dept('2500', p_loc =>2500)
D. EXECUTE add_dept(p_name=>'Education', 2500)
E. EXECUTE add_dept(p_loc=>2500, p_name=>'Education')
Q~:. Which two describe a stored procedure? (Choose two)
A. A stored procedure is typically written in SQL.
B. A stored procedure is a named PL/SQL block that can accept parameters.
C. A stored procedure is a type of PL/SQL subprogram that performs an action.
D. A stored procedure has three parts: the specification, the body, and the exception handler part.
E. The executable section of a stored procedure contains statements that assigns values, control execution, and return values to the calling environment.
Q~:. To be callable from a SQL expression, a user-defined function must do what?
A. Be stored only in the database.
B. Have both IN and OUT parameters.
C. Use the positional notation for parameters.
D. Return a BOOLEAN or VARCHAR2 data type.
Q~:. Examine the procedure:
CREATE OR REPLACE PROCEDURE INSERT TEAM (V_ID in NUMBER, 
V_CITY in VARCHER2 DEFAULT ‘AUSTIN’,  V_NAME in VARCHER2)
IS
BEGIN
INSERT INTO TEAM (id, city, name)
VALUES (v_id,v_city,v_name);
COMMIT;
END;
Which two statements will successfully invoke this procedure in SQL Plus? (Choose two)
A. EXECUTE INSERT_TEAM;
B. EXECUTE INSERT_TEAM (3, V_NAME=>'LONGHORNS', V_CITY=>'AUSTIN');
C. EXECUTE INSERT_TEAM (3, 'AUSTIN', 'LONGHORNS');
D. EXECUTE INSERT_TEAM (V_ID := V_NAME := 'LONGHORNS', V_CITY := 'AUSTIN');
E. EXECUTE INSERT_TEAM (3, 'LONGHORNS');
Q~:. How can you migrate from a LONG to a LOB data type for a column?
A. Use the DBMS_MANAGE_LOB.MIGRATE procedure.
B. Use the UTL_MANAGE_LOB.MIGRATE procedure.
C. Use the DBMS_LOB.MIGRATE procedure.
D. Use the ALTER TABLE command.
E. You cannot migrate from a LONG to a LOB date type for a column.
Q~:. You need to remove the database trigger BUSINESS_HOUR. Which command do you use
to remove the trigger in the SQL *Plus environment?
A. DROP TRIGGER business_hour;
B. DELETE TRIGGER business_hour;
C. REMOVE TRIGGER business_hour;
D. ALTER TRIGGER business_hour REMOVE;
E. DELETE FROM USER_TRIGGERS WHERE TRIGGER_NAME = .BUSINESS_HOUR;
Q~:. A CALL statement inside the trigger body enables you to call ______.
A. A package.
B. A stored function.
C. A stored procedure.
D. Another database trigger.
Q~:. You are about to change the arguments of the CALC_TEAM_AVG function. Which dictionary view can you query to determine the names of the procedures and functions that invoke the CALC_TEAM_AVG function?
A. USER_PROC_DEPENDS
B. USER_DEPENDENCIES
C. USER_REFERENCES
D. USER_SOURCE
Q~:. You create a DML trigger. For the timing information, which is valid with a DML trigger?
A. DURING
B. INSTEAD
C. ON SHUTDOWN
D. BEFORE
E. ON STATEMENT EXECUTION
Q~:. Which type of argument passes a value from a procedure to the calling environment?
A. VARCHAR2
B. BOOLEAN.10
C. OUT
D. IN
Q~:. You want to create a PL/SQL block of code that calculates discounts on customer orders. This code will be invoked from several places, but only within the program unit ORDERTOTAL. What is the most appropriate location to store the code that calculates the discounts?
A. A stored procedure on the server.
B. A block of code in a PL/SQL library.
C. A standalone procedure on the client machine.
D. A block of code in the body of the program unit ORDERTOTAL.
E. A local subprogram defined within the program unit ORDERTOTAL.
Q~:. Which statement about triggers is true?
A. You use an application trigger to fire when a DELETE statement occurs.
B. You use a database trigger to fire when an INSERT statement occurs.
C. You use a system event trigger to fire when an UPDATE statement occurs.
D. You use INSTEAD OF trigger to fire when a SELECT statement occurs.
Q~:. Examine this procedure:
 CREATE OR REPLACE PROCEDURE ADD_PLAYER(V_ID IN NUMBER, V_LAST_NAME VARCHAR2)
 IS
 BEGIN
 INSERT INTO PLAYER(ID,LAST_NAME)
 VALUES (V_ID, V_LAST_NAME);
 COMMIT;
 END;
This procedure must invoke the UPD_BAT_STAT procedure and pass a parameter. Which statement, when added to the above procedure will successfully invoke the  UPD_BAT_STAT procedure?
A. EXECUTE UPD_BAT_STAT(V_ID);
B. UPD_BAT_STAT(V_ID);
C. RUN UPD_BAT_STAT(V_ID);
D. START UPD_BAT_STAT(V_ID);
Q~:. Which four triggering events can cause a trigger to fire? (Choose four)
A. A specific error or any errors occurs.
B. A database is shut down or started up.
C. A specific user or any user logs on or off.
D. A user executes a CREATE or an ALTER table statement.
E. A user executes a SELECT statement with an ORDER BY clause.
F. A user executes a JOIN statement that uses four or more tables.
Q~:. When creating a function in SQL*Plus, you receive this message: .Warning: Function created with compilation errors.. Which command can you issue to see the actual error message?
A. SHOW FUNCTION_ERROR
B. SHOW USER_ERRORS
C. SHOW ERRORS
D. SHOW ALL_ERRORS

Q~:. There is a CUSTOMER table in a schema that has a public synonym CUSTOMER and you are granted all object privileges on it. You have a procedure PROCESS_CUSTOMER that processes customer information that is in the public synonym CUSTOMER table. You have just created a new table called CUSTOMER within your schema. Which statement is true?
A. Creating the table has no effect and procedure PROCESS_CUSTOMER still accesses data from  public synonym CUSTOMER table.
B. If the structure of your CUSTOMER table is the same as the public synonym CUSTOMER table then the procedure PROCESS_CUSTOMER is invalidated and gives compilation errors.
C. If the structure of your CUSTOMER table is entirely different from the public synonym CUSTOMER table then the procedure PROCESS_CUSTOMER successfully recompiles and accesses your CUSTOMER table.
D. If the structure of your CUSTOMER table is the same as the public synonym CUSTOMER table then the procedure PROCESS_CUSTOMER successfully recompiles when invoked and accesses your CUSTOMER table.
Q~:. Examine this package:
CREATE OR REPLACE PACKAGE BB_PACK
 IS
V_MAX_TEAM_SALARY NUMBER (12,2);
PROCEDURE ADD_PLAYER (V_ID IN NUMBER, V_LAST_NAME VARCHAR2, V_SALARY_NUMBER)
END BB_PACK;
 /
CREATE OR REPLACE PACKAGE BODY BB_PACK
IS
PROCEDURE UPD_PLAYER_STAT (V_ID IN NUMBER, V_AB IN NUMBER DEFAULT 4,
V_HITS IN NUMBER)
IS
BEGIN
UPDATE PLAYER_BAT_STAT
SET AT_BATS = AT_BATS + V_AB,
HITS = HITS + V_HITS
WHERE PLAYER_ID = V_ID;
 COMMIT;
 END UPD_PLAYER_STAT;
PROCEDURE ADD_PLAYER (V_ID IN NUMBER, V_LAST_NAME VARCHAR2, V_SALARY NUMBER)
IS
BEGIN
INSERT INTO PLAYER(ID,LAST_NAME,SALARY)
VALUES (V_ID, V_LAST_NAME, V_SALARY);
UPD_PLAYER_STAT(V_ID,0.0);
END ADD_PLAYER;
END BB_PACK;
Which statement will successfully assign $75,000,000 to the V_MAX_TEAM_SALARY variable from within a
stand-alone procedure?
A. V_MAX_TEAM_SALARY := 7500000;
B. BB_PACK.ADD_PLAYER.V_MAX_TEAM_SALARY := 75000000;
C. BB_PACK.V_MAX_TEAM_SALARY := 75000000;
D. This variable cannot be assigned a value from outside the package.
Q~:. Examine this code:
 CREATE OR REPLACE TRIGGER update_emp
AFTER UPDATE ON emp
 BEGIN
INSERT INTO audit_table (who, dated)
VALUES (USER, SYSDATE);
END;
You issue an UPDATE command in the EMP table that results in changing 10 rows.  How many rows are inserted into the AUDIT_TABLE ?
A. 1
B. 10
C. None
D. A value equal to the number of rows in the EMP table.



Q~:. Examine this package
CREATE OR REPLACE PACKAGE discounts
 IS
G_ID NUMBER:=7839;
DISCOUNT_RATE NUMBER:= 0. 00;
PROCEDURE DISPLAY_PRICE (V_PRICE NUMBER);
END DISCOUNTS;
/
CREATE OR REPLACE PACKAGE BODY discounts
IS
PROCEDURE DISPLAY_PRICE (V_PRICE_NUMBER)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE(‘DISCOUNTED||2_4
(V_PRICE*NVL(DISCOUNT_RATE, 1)))
END DISPLAY_PRICE;
BEGIN DISCOUNT_RATE;=0. 10;
END DISCOUNTS;
/
Which statement is true?
A. The value of DISCOUNT_RATE always remain 0. 00 in a session.
B. The value of DISCOUNT_RATE is set to 0. 10 each time the package are invoked in a session.
C. The value of DISCOUNT_RATE is set to 1 each time the procedure DISPLAY_PRICE is invoked.
D. The value of DISCOUNT_RATE is set to 0. 10 when the package is invoked for first time in a session.

Q~:. Examine this code:
CREATE OR REPLACE TRIGGER secure_emp
BEFORE LOGON ON employees
BEGIN
IF (TO_CHAR(SYSDATE, .DY.) IN ( .SAT., .SUN.)) OR
(TO_CHAR(SYSDATE, .HH24:MI .) NOT BETWEEN .08:00 AND .18:00 ) THEN
 RAISE_APPLICATION_ERROR (-20500, ‘You may insert into EMPLOYEES table only during business hours. ‘);
END IF;
END;
What type of trigger is it?
A. DML trigger
B. INSTEAD OF trigger
C. Application trigger
D. System event trigger
E. This is an invalid trigger.
Q~:. Which table should you query to determine when your procedure was last compiled?
A. USER_PROCEDURES
B. USER_PROCS
C. USER_OBJECTS
D. USER_PLSQL_UNITS
Q~:. Examine this code:
CREATE OR REPLACE FUNCTION gen_email_name (p_first_name VARCHAR2, p_last_name VARCHAR2,
p_id NUMBER)  RETURN VARCHAR2
 is
v_email_name VARCHAR2 (19);
BEGIN
 v_email_home := SUBSTR(p_first_name, 1, 1) || SUBSTR(p_last_name, 1, 7) ||’@Oracle.com ‘;
UPDATE employees SET email = v_email_name
WHERE employee_id = p_id;
RETURN v_email_name;
END;
You run this SELECT statement:
SELECT first_name, last_name gen_email_name(first_name, last_name, 108) EMAIL FROM
employees; What occurs?
A. Employee 108 has his email name updated based on the return result of the function.
B. The statement fails because functions called from SQL expressions cannot perform DML.
C. The statement fails because the functions does not contain code to end the transaction.
D. The SQL statement executes successfully, because UPDATE and DELETE statements are ignoring in stored functions called from SQL expressions.
E. The SQL statement executes successfully and control is passed to the calling environment.

Q~:. What part of a database trigger determines the number of times the trigger body executes?
A. Trigger type
B. Trigger body
C. Trigger event
D. Trigger timing

Q~:. What happens during the execute phase with dynamic SQL for INSERT, UPDATE, and DELETE operations?
A. The rows are selected and ordered.
B. The validity of the SQL statement is established.
C. An area of memory is established to process the SQL statement.
D. The SQL statement is run and the number of rows processed is returned.
E. The area of memory established to process the SQL statement is released.

Q~:. Given a function CALCTAX :
CREATE OR REPLACE FUNCTION calc tax  (sal NUMBER) RETURN NUMBER
IS
BEGIN RETURN (sal * 0.05);
 END;
If you want to run the above function from the SQL *Plus prompt, which statement is true?
A. You need to execute the command CALCTAX(1000); .
B. You need to execute the command EXECUTE FUNCTION calc tax; .
C. You need to create a SQL *Plus environment variable X and issue the command :X :=
CALCTAX (1000); .
D. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X :=
CALCTAX;
E. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X :=
CALCTAX(1000);

Q~:. Which two dictionary views track dependencies? (Choose two)
A. USER_SOURCE
B. UTL_DEPTREE
C. USER_OBJECTS
D. DEPTREE_TEMPTAB
E. USER_DEPENDENCIES
F. DBA_DEPENDENT_OBJECTS

Q~:. Which statements are true? (Choose all that apply)
A. If errors occur during the compilation of a trigger, the trigger is still created.
B. If errors occur during the compilation of a trigger you can go into SQL *Plus and query the USER_TRIGGERS data dictionary view to see the compilation errors.
C. If errors occur during the compilation of a trigger you can use the SHOW ERRORS command within iSQL *Plus to see the compilation errors.
D. If errors occur during the compilation of a trigger you can go into SQL *Plus and query the USER_ERRORS data dictionary view to see compilation errors.

Q~:. You need to create a trigger on the EMP table that monitors every row that is changed and places this information into the AUDIT_TABLE. What type of trigger do you create?
A. FOR EACH ROW trigger on the EMP table.
B. Statement-level trigger on the EMP table.
C. FOR EACH ROW trigger on the AUDIT_TABLE table.
D. Statement-level trigger on the AUDIT_TABLE table.
E. FOR EACH ROW statement-level trigger on the EMP table.
Q~:. Examine this package:
CREATE OR REPLACE PACKAGE BB:PACK
IS
V_MAX_TEAM: SALARY NUMBER(12,2);
 PROCEDURE ADD_PLAYER(V_ID IN NUMBER,V_LAST_NAME VARCHAR2, V_SALARY NUMBER);
END BB_PACK;
/
CREATE OR REPLACE PACKAGE BODY  BB_PACK
IS
PROCEDURE UPD_PLAYER_STAT (V_ID IN
NUMBER, V_AB IN NUMBER DEFAULT 4, V_HITS IN NUMBER)
 IS
 BEGIN
UPDATE PLAYER_BAT_STAT
 SET
AT_BATS = AT_BATS + V_AB,
HITS = HITS + V_HITS WHERE
PLAYER_ID = V_ID; COMMIT;
END UPD_PLAYER_STAT;
PROCEDURE ADD_PLAYER
(V_ID IN NUMBER, V_LAST_NAME VARCHAR2, V_SALARY NUMBER)
IS
BEGIN
INSERT INTO PLAYER(ID,LAST_NAME,SALARY)
VALUES (V_ID, V_LAST_NAME,
V_SALARY); UPD_PLAYER_STAT(V_ID,0,0);
END ADD_PLAYER;
END BB_PACK;
You make a change to the body of the BB_PACK package. The BB_PACK body is recompiled. What
happens if the stand alone procedure VALIDATE_PLAYER_STAT references this package?
A. VALIDATE_PLAYER_STAT cannot recompile and must be recreated.
B. VALIDATE_PLAYER_STAT is not invalidated.
C. VALDIATE_PLAYER_STAT is invalidated.
D. VALIDATE_PLAYER_STAT and BB_PACK are invalidated.

Q~:. Which statement is valid when removing procedures?
A. Use a drop procedure statement to drop a standalone procedure.
B. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile thepackage specification.
C. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package body.
D. For faster removal and re-creation, do not use a drop procedure statement. Instead, recompile the procedure using the alter procedure statement with the REUSE SETTINGS clause.

Q~:. Examine this code:
CREATE OR REPLACE PACKAGE bonus IS
g_max_bonus NUMBER := .99;
FUNCTION calc_bonus (p_emp_id NUMBER) RETURN NUMBER;
FUNCTION calc_salary (p_emp_id NUMBER) RETURN NUMBER;
END; /

CREATE OR REPLACE PACKAGE BODY bonus
IS
v_salary employees.salary%TYPE;
v_bonus employees.commission_pct%TYPE;
FUNCTION calc_bonus (p_emp_id NUMBER)
RETURN NUMBER
IS
BEGIN
SELECT salary, commission_pct
INTO v_salary, v_bonus
FROM employees
WHERE employee_id = p_emp_id;
RETURN v_bonus * v_salary;
END calc_bonus
FUNCTION calc_salary (p_emp_id NUMBER)
RETURN NUMBER
IS
BEGIN SELECT salary, commission_pct INTO v_salary, v_bonus
FROM employees
 WHERE employees
 RETURN v_bonus * v_salary + v_salary;
END cacl_salary;
END bonus; /
 Which statement is true?
A. You can call the BONUS.CALC_SALARY packaged function from an INSERT command against the EMPLOYEES table.
B. You can call the BONUS.CALC_SALARY packaged function from a SELECT command against.15       the EMPLOYEES table.
C. You can call the BONUS.CALC_SALARY packaged function form a DELETE command against
      the EMPLOYEES table.
D. You can call the BONUS.CALC_SALARY packaged function from an UPDATE command
      against the EMPLOYEES table.
Q~:. 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;
Q~:. Which two statements describe the state of a package variable after executing the package in which it is declared? (Choose two)
A. It persists across transactions within a session.
B. It persists from session to session for the same user.
C. It does not persist across transaction within a session.
D. It persists from user to user when the package is invoked.
E. It does not persist from session to session for the same user.
Q~:. Which two programming constructs can be grouped within a package? (Choose two)
A. Cursor
B. Constant
C. Trigger
D. Sequence
E. View
Q~:. Which two statements about packages are true? (Choose two)
A. Packages can be nested.
B. You can pass parameters to packages.
C. A package is loaded into memory each time it is invoked.
D. The contents of packages can be shared by many applications.
E. You can achieve information hiding by making package constructs private.
Q~:. 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’);



Q~:. You have created a stored procedure DELETE_TEMP_TABLE that uses dynamic SQL to
remove a table in your schema. You have granted the EXECUTE privilege to user A on this
procedure. When user A executes the DELETE_TEMP_TABLE procedure, under whose
privileges are the operations performed by default?
A. SYS privileges
B. Your privileges
C. Public privileges
D. User A.s privileges
E. User A cannot execute your procedure that has dynamic SQL.
Q~:. Which three are true statements about dependent objects? (Choose three)
A. Invalid objects cannot be described.
B. An object with status of invalid cannot be a referenced object.
C. The Oracle server automatically records dependencies among objects.
D. All schema objects have a status that is recorded in the data dictionary.
E. You can view whether an object is valid or invalid in the USER_STATUS data dictionary view.
F. You can view whether an object is valid or invalid in the USER_OBJECTS data dictionary view.
Q~:. Examine this function:
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)
Q~:. The number of cascading triggers is limited by which data base initialization parameter?
A. CASCADE_TRIGGER_CNT.
B. OPEN_CURSORS.
C. OPEN_TRIGGERS.
D. OPEN_DB_TRIGGERS.
Q~:. Which type of package construct must be declared both within the package specification and
package body?
A. All package variables.
B. Boolean variables.
C. Private procedures and functions.
D. Public procedures and functions.
Q~:. Why do stored procedures and functions improve performance? (Chose two)
A. They reduce network round trips.
B. They postpone PL/SQL parsing until run time.
C. They allow the application to perform high speed processing locally.
D. They reduce the number of calls to the database and decrease network traffic by bundling commands.
E. They reduce the number of calls to the database and decrease network traffic by using the local PL/SQL engine.
Q~:. When creating store procedures and functions which construct allows you to transfer values
to and from the calling environment?
A. Local variables.
B. Arguments.
C. Boolean variables.
D. Substitution variables.

Q~:. You need to remove database trigger BUSINESS_RULE. Which command do you use to remove the trigger in the SQL*Plus environment?
A. DROP TRIGGER business_rule;
B. DELETE TRIGGER business_rule;
C. REMOVE TRIGGER business_rule;
D. ALTER TRIGGER business_rule;
E. DELETE FROM USER_TRIGGER
F. WHERE TRIGGER_NAME= ‘BUSINESS_RULE’;

Q~:. Which two tables are fused track object dependencies? (Choose two)
A. USER_DEPENDENCIES.
B. USER_IDEPTREE.
C. IDEPTREE.
D. USER_DEPTREE.
E. USER_DEPENDS.

Q~:. The QUERY_PRODUCT procedure directly references the product table. There is a NEW_PRODUCT_VIEW view created based on the NOT NULL columns of the table. The ADD_PRODUCT procedure updates the table indirectly by the way of NEW_PRODUCT_VIEW view. Under which circumstances does the procedure
ADD_PRODUCT get invalidated but automatically get complied when invoked?
A. When the NEW_PRODUCT_VIEW is dropped.
B. When rows of the product table are updated through SQL Plus.
C. When the internal logic of the QUERY_PRODUCT procedure is modified.
D. When a new column that can contain null values is added to the product table.
E. When a new procedure s created that updates rows in the product table directly.
Q~:. You need to recompile several program units you have recently modified through a PL/SQL program. Which statement is true?.18
A. You cannot recompile program units using a PL/SQL program.
B. You can use the DBMS_DDL. REOMPILE package procedure to recompile the program units.
C. You can use the DBMS_ALTER. COMPILE packaged procedure to recompile the program units.
D. You can use the DBMS_DDL.ALTER_COMPILE packaged procedure to recompile the program units.
E. You can use the DBMS_SQL.ALTER_COMPILE packaged procedure to recompile the program units.
Q~:. Which type of argument passes a value from a calling environment?
A. VARCHER2.
B. BOOLEAN.
C. OUT.
D. IN.
Q~:. In order for you to create run a package MAINTAIN_DATA which privilege do you need?
A. EXECUTE privilege on the MAINTAIN_DATA package.
B. INVOKE privilege on the MAINTAIN_DATA package.
C. EXECUTE privilege on the program units in the MAINTAIN_DATA package.
D. Object privilege on all of the objects that the MAINTAIN_DATA package is accessing.
E. Execute privilege on the program units inside the MAINTAIN_DATA package and execute
privilege on the MAINTAIN_DATA package.
Q~:. You have created a script file EMP_PROC.SQL that holds the text to create a procedure PROCESS_EMP. You have compiled the procedure for SQL Plus environment by running the script file EMP_PROC.SQL. What happens if there are syntax errors in the procedure PROCESS_EMP?
A. The errors are stored in the EMP_PROC.ERR file.
B. The errors are displayed to the screen when the script file is run.
C. The errors are stored in the procedure_errors data dictionary view.
D. YOU need to issue the SHOW ERRORS command in the SQL Plus environment to see the errors.
E. YOU need to issue the display errors command in the SQL Plus environment to see the errors.
Q~:. Which statement about the local dependent object is TRUE?
A. They are on different nodes.
B. They are in a different database.
C. They are on the same node in the same database.
D. They are on the same node in a different database.
Q~:. You need to create a stored procedure, which deletes rows from a table. The name of the table from which the rows are to be deleted is unknown until run time. Which method do you implement while creating such a procedure?
A. Use SQL command delete in the procedure to delete the rows.
B. Use DBMS_SQL packaged routines in the procedure to delete the rows.
C. Use DBMS_DML packaged routines in the procedure to delete the rows.
D. Use DBMSDELETE packaged routines in the procedure to delete the rows.
E. You cannot have a delete statement without providing a table name before compile time.
Q~:. Under which situation do you create a server side procedure?
A. When the procedure contains no SQL statements.
B. When the procedure contains no PL/SQL commands.
C. When the procedure needs to be used by many client applications accessing several remote databases.
D. When the procedure needs to be used by many users accessing the same schema objects on a local database.
Q~:. Examine this function
CREATE OR REPLACE FUNCTION CALC_PLAYER_AVG
(V_ID in PLAYER_BAT_STAT. PLAYER_ID%TYPE)
RETURN NUMBER
IS
V_AVG NUMBER;
SELECTS HITS/AT_BATS
INTO V_AVG
FROM PLAYER_BAT_STAT
WHERE PLAYER_ID_V_ID;
RETURN(V_AVG);
END;
This function must be moved to a package. Which additional statement must be added to the function to allow you to continue using the function in the group by the clause of a select statement?
A. PRAGMA RESTRICT_REFERENCES (CALC_PLAYER_AVG, WNDS, WNPS);
B. PRAGMA RESTRICT_REFERENCES (CALC_PLAYER_AVG, WNPS);
C. PRAGMA RESTRICT_REFERENCES (CALC_PLAYER_AVG, RNPS, WNPS);
D. PRAGMA RESTRICT_REFERENCES (CALC_PLAYER_AVG, ALLOW_GROUP_BY);

Q~:. Which code successfully calculates tax?
A. CREATE OR REPLACE PROCEDURE calc (p_no IN NUMBER)
RETURN tax
IS
V_sal NUMBER;
Tax NUMBER;
BEGIN
SELECT sal
INTO v_sal
FROM emp
WHERE EMPNO=p_no;
Tax:=v_sal * 0. 05;
END;
B. CREATE OR REPLACE FUNCTION calctax (p_no NUMBER)
RETURN NUMBER
 IS
V_sal NUMBER;
BEGIN
SELECT sal
INTO v_sal
FROM emp
WHERE empno =p_no;
RETURN (v_sal* 0. 05);
END;
C. CRETAE OR REPLACE FUNCTION calctax(p_no NUMBER)
RETURN NUMBER IS
V_sal NUMBER;
Tax NUMBER;
BEGIN
SELECT sal INTO v_sal
FROM emp
WHERE empno =p_no;
Tax:=v_sal * 0. 05;
END;
D. CREATE OR REPLACE FUNCTION calctax(p_no NUMBER)IS
V_sal NUMBER;
Tax NUMBER;
BEGIN
SELECT sal INTO v_sal
FROM emp
WHERE empno =p_no;
Tax :=v_sal * 0. 05;
RETURN(tax);
END;
Q~:. The programmer view developed a procedure ACCOUNT_TRANSACTION left organization. You were assigned a task to modify this procedure. YOU want to find all the program units invoking the ACCOUNT_TRANSACTION procedure. How can you find this information?
A. Query the USER_SOURCE data dictionary view.
B. Query the USER_PROCEDURES data dictionary view.
C. Query the USER_DEPENDENCIES data dictionary views.
D. Set the SQL Plus environment variable trade code=true and run the ACCOUNT_TRANSACTION procedure.
E. Set the SQL Plus environment variable DEPENDENCIES=TRUE and run the Account_Transaction procedure.
Q~:. Which two statements about the overloading feature of packages are true? (Choose two)
A. Only local or packaged sub programs can be overloaded.
B. Overloading allows different functions with the same name that differ only in their return types.
C. Overloading allows different subprograms with the same number, type and order of the parameter.
D. Overloading allows different subprograms with the same name and same number or type of the parameters.
E. Overloading allows different subprograms with the same name but different in either number or type or order of parameter.

Tuesday, 2 May 2017

oracle sql ,plsql questions and answers PART5

Q. How can variables be passed to a SQL routine?

: By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1, &2,...,&8) to pass the values after the command into the SQLPLUS session. To be prompted for a specific variable, place the ampersanded variable in the code itself:
"select * from dba_tables where owner=&owner_name;" . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable, a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user.
Q. You want to include a carriage return/linefeed in your output from a SQL script, how can you do this?

Expected answer: The best method is to use the CHR() function (CHR(10) is a return/linefeed) and the concatenation function "||". Another method, although it is hard to document and isn’t always portable is to use the return/linefeed as a part of a quoted string.
Q. How can you call a PL/SQL procedure from SQL?

Expected answer: By use of the EXECUTE (short form EXEC) command.
Q. How do you execute a host operating system command from within SQL?

 : By use of the exclamation point "!" (in UNIX and some other OS) or the HOST (HO) command.
Q. You want to use SQL to build SQL, what is this called and give an example

 : This is called dynamic SQL. An example would be:
set lines 90 pages 0 termout off feedback off verify off
spool drop_all.sql
select ‘drop user ‘||username||’ cascade;’ from dba_users
where username not in ("SYS’,’SYSTEM’);
spool off
Essentially you are looking to see that they know to include a command (in this case DROP USER...CASCADE;) and that you need to concatenate using the ‘||’ the values selected from the database.
Q. What SQLPlus command is used to format output from a select?

 : This is best done with the COLUMN command.
Q. You want to group the following set of select returns, what can you group on?
Max(sum_of_cost), min(sum_of_cost), count(item_no), item_no

 : The only column that can be grouped on is the "item_no" column, the rest have aggregate functions associated with them.
Q. What special Oracle feature allows you to specify how the cost based system treats a SQL statement?

 : The COST based system allows the use of HINTs to control the optimizer path selection. If they can give some example hints such as FIRST ROWS, ALL ROWS, USING INDEX, STAR, even better.
Q. You want to determine the location of identical rows in a table before attempting to place a unique index on the table, how can this be done?

 : Oracle tables always have one guaranteed unique column, the rowid column. If you use a min/max function against your rowid and then select against the proposed primary key you can squeeze out the rowids of the duplicate rows pretty quick. For example:
select rowid from emp e
where e.rowid > (select min(x.rowid)
from emp x
where x.emp_no = e.emp_no);
In the situation where multiple columns make up the proposed key, they must all be used in the where clause.
Q. What is a Cartesian product?

 : A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows in each table involved in the join.
Q. You are joining a local and a remote table, the network manager complains about the traffic involved, how can you reduce the network traffic?

 : Push the processing of the remote data to the remote instance by using a view to pre-select the information for the join. This will result in only the data required for the join being sent across.
Q. What is the default ordering of an ORDER BY clause in a SELECT statement?

 : Ascending


Q. What is tkprof and how is it used?

 : The tkprof tool is a tuning tool used to determine cpu and execution times for SQL statements. You use it by first setting timed_statistics to true in the initialization file and then turning on tracing for either the entire database via the sql_trace parameter or for the session using the ALTER SESSION command. Once the trace file is generated you run the tkprof tool against the trace file and then look at the output from the tkprof tool. This can also be used to generate explain plan output.
Q. What is explain plan and how is it used?

 : The EXPLAIN PLAN command is a tool to tune SQL statements. To use it you must have an explain_table generated in the user you are running the explain plan for. This is created using the utlxplan.sql script. Once the explain plan table exists you run the explain plan command giving as its argument the SQL statement to be explained. The explain_plan table is then queried to see the execution plan of the statement. Explain plans can also be run using tkprof.
Q. How do you set the number of lines on a page of output? The width?

 : The SET command in SQLPLUS is used to control the number of lines generated per page and the width of those lines, for example SET PAGESIZE 60 LINESIZE 80 will generate reports that are 60 lines long with a line width of 80 characters. The PAGESIZE and LINESIZE options can be shortened to PAGES and LINES.
Q. How do you prevent output from coming to the screen?

 : The SET option TERMOUT controls output to the screen. Setting TERMOUT OFF turns off screen output. This option can be shortened to TERM.
Q. How do you prevent Oracle from giving you informational messages during and after a SQL statement execution?

 : The SET options FEEDBACK and VERIFY can be set to OFF.
Q. How do you generate file output from SQL?

 : By use of the SPOOL command
Q. Describe the difference between a procedure, function and anonymous pl/sql block.

ans-- Candidate should mention use of DECLARE statement, a function must return a value while a procedure doesn’t have to.
Q. What is a mutating table error and how can you get around it?

ans-- This happens with triggers. It occurs because the trigger is trying to update a row it is currently using. The usual fix involves either use of views or temporary tables so the database is selecting from one while updating the other.
Q. Describe the use of %ROWTYPE and %TYPE in PL/SQL

ans--: %ROWTYPE allows you to associate a variable with an entire table row. The %TYPE associates a variable with a single column type.
Q. What packages (if any) has Oracle provided for use by developers?

ans-- Oracle provides the DBMS_ series of packages. There are many which developers should be aware of such as DBMS_SQL, DBMS_PIPE, DBMS_TRANSACTION, DBMS_LOCK, DBMS_ALERT, DBMS_OUTPUT, DBMS_JOB, DBMS_UTILITY, DBMS_DDL, UTL_FILE. If they can mention a few of these and describe how they used them, even better. If they include the SQL routines provided by Oracle, great, but not really what was asked.
Q. Describe the use of PL/SQL tables

ans-- PL/SQL tables are scalar arrays that can be referenced by a binary integer. They can be used to hold values for use in later queries or calculations. In Oracle 8 they will be able to be of the %ROWTYPE designation, or RECORD.
Q. When is a declare statement needed?

The DECLARE statement is used in PL/SQL anonymous blocks such as with stand alone, non-stored PL/SQL procedures. It must come first in a PL/SQL stand alone file if it is used.
Q. In what order should a open/fetch/loop set of commands in a PL/SQL block be implemented if you use the %NOTFOUND cursor variable in the exit when statement? Why?

ans-- OPEN then FETCH then LOOP followed by the exit when. If not specified in this order will result in the final return being done twice because of the way the %NOTFOUND is handled by PL/SQL.





Q. What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?

ans-- SQLCODE returns the value of the error number for the last error encountered. The SQLERRM returns the actual error message for the last error encountered. They can be used in exception handling to report, or, store in an error log table, the error that occurred in the code. These are especially useful for the WHEN OTHERS exception.
Q. How can you find within a PL/SQL block, if a cursor is open?

ans-- Use the %ISOPEN cursor status variable.
Q. How can you generate debugging output from PL/SQL?
Level:Intermediate to high
ans-- Use the DBMS_OUTPUT package. Another possible method is to just use the SHOW ERROR command, but this only shows errors. The DBMS_OUTPUT package can be used to show intermediate results from loops and the status of variables as the procedure is executed. The new package UTL_FILE can also be used.
Q. What are the types of triggers?
Level:Intermediate to high
ans-- There are 12 types of triggers in PL/SQL that consist of combinations of the BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and ALL key words:
BEFORE ALL ROW INSERT
AFTER ALL ROW INSERT
BEFORE INSERT
AFTER INSERT etc.
SOME ORACLE DBA QUESTIONS AND ANSWERS-
Q. Give one method for transferring a table from one schema to another:

ANS:-There are several possible methods, export-import, CREATE TABLE... AS SELECT, or COPY.
Q. What is the purpose of the IMPORT option IGNORE? What is it’s default setting?

ANS:-The IMPORT IGNORE option tells import to ignore "already exists" errors. If it is not specified the tables that already exist will be skipped. If it is specified, the error is ignored and the tables data will be inserted. The default value is N.
Q. You have a rollback segment in a version 7.2 database that has expanded beyond optimal, how can it be restored to optimal?

ANS:-Use the ALTER TABLESPACE ..... SHRINK command.



Q. If the DEFAULT and TEMPORARY tablespace clauses are left out of a CREATE USER command what happens? Is this bad or good? Why?

ANS:-The user is assigned the SYSTEM tablespace as a default and temporary tablespace. This is bad because it causes user objects and temporary segments to be placed into the SYSTEM tablespace resulting in fragmentation and improper table placement (only data dictionary objects and the system rollback segment should be in SYSTEM).
Q. What are some of the Oracle provided packages that DBAs should be aware of?

ANS:-Oracle provides a number of packages in the form of the DBMS_ packages owned by the SYS user. The packages used by DBAs may include: DBMS_SHARED_POOL, DBMS_UTILITY, DBMS_SQL, DBMS_DDL, DBMS_SESSION, DBMS_OUTPUT and DBMS_SNAPSHOT. They may also try to answer with the UTL*.SQL or CAT*.SQL series of SQL procedures. These can be viewed as extra credit but aren’t part of the answer.
Q. What happens if the constraint name is left out of a constraint clause?

ANS:-The Oracle system will use the default name of SYS_Cxxxx where xxxx is a system generated number. This is bad since it makes tracking which table the constraint belongs to or what the constraint does harder.
Q. What happens if a tablespace clause is left off of a primary key constraint clause?

ANS:-This results in the index that is automatically generated being placed in then users default tablespace. Since this will usually be the same tablespace as the table is being created in, this can cause serious performance problems.
Q. What is the proper method for disabling and re-enabling a primary key constraint?

ANS:-You use the ALTER TABLE command for both. However, for the enable clause you must specify the USING INDEX and TABLESPACE clause for primary keys.
Q. What happens if a primary key constraint is disabled and then enabled without fully specifying the index clause?

ANS:-The index is created in the user’s default tablespace and all sizing information is lost. Oracle doesn’t store this information as a part of the constraint definition, but only as part of the index definition, when the constraint was disabled the index was dropped and the information is gone.
Q. (On UNIX) When should more than one DB writer process be used? How many should be used?

ANS:-If the UNIX system being used is capable of asynchronous IO then only one is required, if the system is not capable of asynchronous IO then up to twice the number of disks used by Oracle number of DB writers should be specified by use of the db_writers initialization parameter.


Q. You are using hot backup without being in archivelog mode, can you recover in the event of a failure? Why or why not?

ANS:-You can’t use hot backup without being in archivelog mode. So no, you couldn’t recover.
Q. What causes the "snapshot too old" error? How can this be prevented or mitigated?

ANS:-This is caused by large or long running transactions that have either wrapped onto their own rollback space or have had another transaction write on part of their rollback space. This can be prevented or mitigated by breaking the transaction into a set of smaller transactions or increasing the size of the rollback segments and their extents.
Q. How can you tell if a database object is invalid?

ANS:-By checking the status column of the DBA_, ALL_ or USER_OBJECTS views, depending upon whether you own or only have permission on the view or are using a DBA account.
Q. A user is getting an ORA-00942 error yet you know you have granted them permission on the table, what else should you check?

ANS:-You need to check that the user has specified the full name of the object (select empid from scott.emp; instead of select empid from emp;) or has a synonym that points to the object (create synonym emp for scott.emp;)
Q. A developer is trying to create a view and the database won’t let him. He has the "DEVELOPER" role which has the "CREATE VIEW" system privilege and SELECT grants on the tables he is using, what is the problem?

ANS:-You need to verify the developer has direct grants on all tables used in the view. You can’t create a stored object with grants given through views.
Q. If you have an example table, what is the best way to get sizing data for the production table implementation?

ANS:-The best way is to analyze the table and then use the data provided in the DBA_TABLES view to get the average row length and other pertinent data for the calculation. The quick and dirty way is to look at the number of blocks the table is actually using and ratio the number of rows in the table to its number of blocks against the number of expected rows.
Q. How can you find out how many users are currently logged into the database? How can you find their operating system id?

ANS:-There are several ways. One is to look at the v$session or v$process views. Another way is to check the current_logins parameter in the v$sysstat view. Another if you are on UNIX is to do a "ps -ef|grep oracle|wc -l’ command, but this only works against a single instance installation.

Q. A user selects from a sequence and gets back two values, his select is:
SELECT pk_seq.nextval FROM dual;
What is the problem?

ANS:-Somehow two values have been inserted into the dual table. This table is a single row, single column table that should only have one value in it.
Q. How can you determine if an index needs to be dropped and rebuilt?

ANS:-Run the ANALYZE INDEX command on the index to validate its structure and then calculate the ratio of LF_BLK_LEN/LF_BLK_LEN+BR_BLK_LEN and if it isn’t near 1.0 (i.e. greater than 0.7 or so) then the index should be rebuilt. Or if the ratio
BR_BLK_LEN/ LF_BLK_LEN+BR_BLK_LEN is nearing 0.3.

Analytical Function in oracle


 Analytical Function
Oracle includes a number of very useful functions that allow you to analyze, aggregate, and rank
vast amounts of stored data. You can use these analytical functions to find the top-n revenuegenerating
courses, compare revenues of one course with another, or compute various statistics
about students’ grades.
You will gain an appreciation of their core functionality and usefulness, particularly with regard
to the calculation of rankings or generation of moving averages, moving sums, and so on.
Analytical functions execute queries fairly quickly because they allow you to make one pass
through the data rather than write multiple queries or complicated SQL to achieve the same
result. This significantly speeds up query performance.
The general syntax of analytical functions is as follows.
analytic_function([arguments]) OVER (analytic_clause)
The OVER keyword indicates that the function operates after the results of the FROM, WHERE,
GROUP BY, and HAVING clauses have been formed.
ANALYTIC_CLAUSE can contain three other clauses: QUERY_PARTITIONING,
ORDER_BY, or WINDOWING.
[query_partition_clause] [order_by_clause [windowing_clause]]
The QUERY_PARTIONING clause allows you to
split a result into smaller subsets on which you can apply the analytical functions. The
ORDER_BY_CLAUSE is much like the familiar ordering clause; however, it is applied to the
result of an analytical function. WINDOWING_CLAUSE lets you compute moving and
accumulative aggregates—such as moving averages, moving sums, or cumulative sums—by
choosing only certain data within a specified window.

Query Processing with Analytical Functions
Analytical Function Types

whatever an analytic function does can be done by native SQL, with join and sub-queries. But the same
routine done by analytic function is always faster, or at least as fast, when compared to native SQL
How are analytic functions different from group or aggregate functions?
SELECT deptno,
COUNT(*) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30)
GROUP BY deptno;
DEPTNO DEPT_COUNT

---------------------- ----------------------
20 5
30 6
SELECT empno, deptno,
COUNT(*) OVER (PARTITION BY
deptno) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30);
EMPNO DEPTNO DEPT_COUNT
---------- ---------- ----------
7369 20 5
7566 20 5
7788 20 5
7902 20 5
7876 20 5
7499 30 6
7900 30 6
7844 30 6
7698 30 6
7654 30 6
7521 30 6

How to break the result set in groups or partitions?
It might be obvious from the previous example that the clause PARTITION BY is used to break the result
set into groups. PARTITION BY can take any non-analytic SQL expression.
Some functions support the <window_clause> inside the partition to further limit the records they act
on. In the absence of any <window_clause> analytic functions are computed on all the records of the
partition clause.
The functions SUM, COUNT, AVG, MIN, MAX are the common analytic functions the result of which does
not depend on the order of the records.
Functions like LEAD, LAG, RANK, DENSE_RANK, ROW_NUMBER, FIRST, FIRST VALUE, LAST, LAST VALUE
depends on order of records. In the next example we will see how to specify that.
How to specify the order of the records in the partition?
The answer is simple, by the "ORDER BY" clause inside the OVER( ) clause. This is different from the
ORDER BY clause of the main query which comes after WHERE. In this section we go ahead and
introduce each of the very useful functions LEAD, LAG, RANK, DENSE_RANK, ROW_NUMBER, FIRST,
FIRST VALUE, LAST, LAST VALUE and show how each depend on the order of the record.
The general syntax of specifying the ORDER BY clause in analytic function is:
ORDER BY <sql_expr> [ASC or DESC] NULLS [FIRST or LAST]
The syntax is self-explanatory.
ROW_NUMBER, RANK and DENSE_RANK
All the above three functions assign integer values to the rows depending on their order. That is the
reason of clubbing them together.

ROW_NUMBER( )
gives a running serial number to a partition of records. It is very useful in reporting, especially in places
where different partitions have their own serial numbers. In Query-5, the function ROW_NUMBER( ) is
used to give separate sets of running serial to employees of departments 10 and 20 based on their
HIREDATE.
SQL>SELECT empno, deptno, hiredate,
ROW_NUMBER( ) OVER (PARTITION BY
deptno ORDER BY hiredate
NULLS LAST) SRLNO
FROM emp
WHERE deptno IN (10, 20)
ORDER BY deptno, SRLNO;
EMPNO DEPTNO HIREDATE SRLNO
------ ------- --------- ----------
7782 10 09-JUN-81 1
7839 10 17-NOV-81 2
7934 10 23-JAN-82 3
7369 20 17-DEC-80 1
7566 20 02-APR-81 2
7902 20 03-DEC-81 3
7788 20 09-DEC-82 4
7876 20 12-JAN-83 5
8 rows selected.

SQL> cl scr
Rank
The RANK function assigns each row a unique number. However, duplicate rows
receive the identical ranking, and a gap appears in the sequence before the next
rank
SQL> SELECT EName, Deptno, Sal,
 RANK()
 OVER(ORDER BY Sal) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER By Emprank;
ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
SMITH 20 800 1
JAMES 30 950 2
ADAMS 20 1100 3
MARTIN 30 1250 4
WARD 30 1250 4
MILLER 10 1300 6
TURNER 30 1500 7
ALLEN 30 1600 8
CLARK 10 2450 9
BLAKE 30 2850 10
JONES 20 2975 11

ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
FORD 20 3000 12
SCOTT 20 3000 12
KING 10 5000 14
14 rows selected.
SQL> ed
Wrote file afiedt.buf
 SELECT E1.*
 FROM (SELECT EName, Deptno, Sal,
 RANK()
 OVER(ORDER BY Sal) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER By Emprank
 ) E1
* WHERE E1.EmpRank = &GRank
SQL> /
Enter value for grank: 1
ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
SMITH 20 800 1

SQL> /
Enter value for grank: 5
no rows selected
SQL> /
Enter value for grank: 4
ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
MARTIN 30 1250 4
WARD 30 1250 4
SQL> cl scr
DENSE_RANK
The ranking function DENSE_RANK assigns duplicate values the same rank.
SQL> SELECT EName, Deptno, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER BY EmpRank;
ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
KING 10 5000 1

FORD 20 3000 2
SCOTT 20 3000 2
JONES 20 2975 3
BLAKE 30 2850 4
CLARK 10 2450 5
ALLEN 30 1600 6
TURNER 30 1500 7
MILLER 10 1300 8
MARTIN 30 1250 9
WARD 30 1250 9
ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ----------
ADAMS 20 1100 10
JAMES 30 950 11
SMITH 20 800 12
 rows selected.
SQL> cl scr
SQL> SELECT ROWNUM, E1.*
 FROM (SELECT EName, Deptno, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal

 ORDER BY EmpRank) E1
 ORDER BY ROWNUM;
ROWNUM ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ---------- ----------
1 KING 10 5000 1
2 FORD 20 3000 2
3 SCOTT 20 3000 2
4 JONES 20 2975 3
5 BLAKE 30 2850 4
6 CLARK 10 2450 5
7 ALLEN 30 1600 6
8 TURNER 30 1500 7
9 MILLER 10 1300 8
10 MARTIN 30 1250 9
11 WARD 30 1250 9
ROWNUM ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ---------- ----------
12 ADAMS 20 1100 10
13 JAMES 30 950 11
14 SMITH 20 800 12
14 rows selected.
SQL> SELECT ROWNUM, E1.*
 FROM (SELECT Ename, Sal

 FROM Emp
 ORDER BY Sal DESC
 ) E1
 WHERE ROWNUM <= 5;
ROWNUM ENAME SAL
---------- ---------- ----------
1 KING 5000
2 FORD 3000
3 SCOTT 3000
4 JONES 2975
5 BLAKE 2850
SQL> ed
Wrote file afiedt.buf
 SELECT ROWNUM, E1.*
 FROM (SELECT Ename, Sal
 FROM Emp
 ORDER BY Sal DESC
 ) E1
 WHERE ROWNUM <= 6
SQL> ed
Wrote file afiedt.buf
 SELECT ROWNUM, E1.*

 FROM (SELECT EName, Deptno, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER BY EmpRank) E1
 WHERE EmpRank <= 5
 ORDER BY ROWNUM
SQL> /
ROWNUM ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ---------- ----------
1 KING 10 5000 1
2 FORD 20 3000 2
3 SCOTT 20 3000 2
4 JONES 20 2975 3
5 BLAKE 30 2850 4
6 CLARK 10 2450 5
6 rows selected.
SQL> cl scr
SQL> SELECT
 DENSE_RANK()
 OVER(ORDER BY Ename) RollNo,
 EName, Deptno, Sal

 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER BY RollNo;
SQL> SELECT
 DENSE_RANK()
 OVER(ORDER BY Ename) RollNo,
 EName, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) RankSal,
 HireDate,
 DENSE_RANK()
 OVER(ORDER BY HireDate) SeniorRank,
 DENSE_RANK()
 OVER(ORDER BY HireDate DESC) JuniorRank
 FROM Emp
 GROUP BY Deptno, EName, Sal, HireDate
 ORDER BY RollNo;
 SELECT
EName, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) RankSal
 FROM Emp
 GROUP BY EName, Sal

 ORDER BY RankSal
SQL> SELECT EName, Deptno, Sal,
 RANK()
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) "TOP Sal"
 FROM Emp
 ORDER BY Deptno, Sal DESC;
.

SQL> /
SQL> SELECT ROWNUM, E1.*
 FROM (SELECT EName, Deptno, Sal,
 DENSE_RANK()
 OVER(ORDER BY Sal DESC) EmpRank
 FROM Emp
 GROUP BY Deptno, EName, Sal
 ORDER BY EmpRank) E1
 WHERE E1.EmpRank <= 5

 ORDER BY ROWNUM;
ROWNUM ENAME DEPTNO SAL EMPRANK
---------- ---------- ---------- ---------- ----------
1 KING 10 5000 1
2 FORD 20 3000 2
3 SCOTT 20 3000 2
4 JONES 20 2975 3
5 BLAKE 30 2850 4
6 CLARK 10 2450 5
6 rows selected.
SQL> SELECT ROWNUM, E1.*
 FROM (SELECT EName, Deptno, HireDate,
 DENSE_RANK()
 OVER(ORDER BY HireDate) HireRank
 FROM Emp
 GROUP BY Deptno, EName, HireDate
 ORDER BY HireRank) E1
 WHERE E1.HireRank <= 5
 ORDER BY ROWNUM;
ROWNUM ENAME DEPTNO HIREDATE HIRERANK
---------- ---------- ---------- --------- ----------
1 SMITH 20 17-DEC-80 1
2 ALLEN 30 20-FEB-81 2

3 WARD 30 22-FEB-81 3
4 JONES 20 02-APR-81 4
5 BLAKE 30 01-MAY-81 5

LEAD and LAG
LEAD has the ability to compute an expression on the next rows (rows which are going to come after the
current row) and return the value to the current row. The general syntax of LEAD is shown below:
LEAD (<sql_expr>, <offset>, <default>) OVER (<analytic_clause>)
<sql_expr> is the expression to compute from the leading row.
<offset> is the index of the leading row relative to the current row.
<offset> is a positive integer with default 1.
<default> is the value to return if the <offset> points to a row outside the partition range.
The syntax of LAG is similar except that the offset for LAG goes into the previous rows.
SQL> SELECT Ename, HireDate, Sal,
 LAG(Sal, 1, 0)
 OVER(ORDER BY HireDate) PreSal

 FROM Emp;
ENAME HIREDATE SAL PRESAL
---------- --------- ---------- ----------
SMITH 17-DEC-80 800 0
ALLEN 20-FEB-81 1600 800
WARD 22-FEB-81 1250 1600
JONES 02-APR-81 2975 1250
BLAKE 01-MAY-81 2850 2975
CLARK 09-JUN-81 2450 2850
TURNER 08-SEP-81 1500 2450
MARTIN 28-SEP-81 1250 1500
KING 17-NOV-81 5000 1250
JAMES 03-DEC-81 950 5000
FORD 03-DEC-81 3000 950
ENAME HIREDATE SAL PRESAL
---------- --------- ---------- ----------
MILLER 23-JAN-82 1300 3000
SCOTT 09-DEC-82 3000 1300
ADAMS 12-JAN-83 1100 3000
14 rows selected.
SQL> ed
Wrote file afiedt.buf

 SELECT Ename, HireDate, Sal,
 LAG(Sal, 1, 0)
 OVER(ORDER BY HireDate) PreSal1,
 LAG(Sal, 2, 0)
 OVER(ORDER BY HireDate) PreSal2,
 LAG(Sal, 3, 0)
 OVER(ORDER BY HireDate) PreSal3,
 LAG(Sal, 4, 0)
 OVER(ORDER BY HireDate) PreSal4
 FROM Emp
SQL> /
SQL> ed
Wrote file afiedt.buf
 SELECT Ename, HireDate, Sal,
 LEAD(Sal, 1, 0)
 OVER(ORDER BY HireDate) PreSal1,
 LEAD(Sal, 2, 0)
 OVER(ORDER BY HireDate) PreSal2,
 LEAD(Sal, 3, 0)
 OVER(ORDER BY HireDate) PreSal3,
 LEAD(Sal, 4, 0)
 OVER(ORDER BY HireDate) PreSal4
 FROM Emp
SQL> /

SQL> cl scr
FIRST and LAST
The FIRST and LAST functions can be used to return the first or last value from an ordered sequence. Say
we want to display the salary of each employee, along with the lowest and highest within their
department we may use something like.
SELECT empno,
deptno,
sal,
MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
FROM emp
ORDER BY deptno, sal;
EMPNO DEPTNO SAL Lowest Highest
---------- ---------- ---------- ---------- ----------
7934 10 1300 1300 5000
7782 10 2450 1300 5000
7839 10 5000 1300 5000
7369 20 800 800 3000
7876 20 1100 800 3000
7566 20 2975 800 3000
7788 20 3000 800 3000
7902 20 3000 800 3000
7900 30 950 950 2850
7654 30 1250 950 2850
7521 30 1250 950 2850

7844 30 1500 950 2850
7499 30 1600 950 2850
7698 30 2850 950 2850
SQL>
SQL> SELECT Ename, HireDate, Sal,
 Sal - LAG(Sal, 1, 0)
 OVER(ORDER BY HireDate) DiffPreSal
 FROM Emp;
ENAME HIREDATE SAL DIFFPRESAL
---------- --------- ---------- ----------
SMITH 17-DEC-80 800 800
ALLEN 20-FEB-81 1600 800
WARD 22-FEB-81 1250 -350
JONES 02-APR-81 2975 1725
BLAKE 01-MAY-81 2850 -125
CLARK 09-JUN-81 2450 -400
TURNER 08-SEP-81 1500 -950
MARTIN 28-SEP-81 1250 -250
KING 17-NOV-81 5000 3750
JAMES 03-DEC-81 950 -4050
FORD 03-DEC-81 3000 2050
ENAME HIREDATE SAL DIFFPRESAL
---------- --------- ---------- ----------

MILLER 23-JAN-82 1300 -1700
SCOTT 09-DEC-82 3000 1700
ADAMS 12-JAN-83 1100 -1900
14 rows selected.
SQL> ed
Wrote file afiedt.buf
 SELECT Ename, HireDate, Sal,
 Sal - LAG(Sal, 1, Sal)
 OVER(ORDER BY HireDate) DiffPreSal
 FROM Emp
SQL> /
ENAME HIREDATE SAL DIFFPRESAL
---------- --------- ---------- ----------
SMITH 17-DEC-80 800 0
ALLEN 20-FEB-81 1600 800
WARD 22-FEB-81 1250 -350
JONES 02-APR-81 2975 1725
BLAKE 01-MAY-81 2850 -125
CLARK 09-JUN-81 2450 -400
TURNER 08-SEP-81 1500 -950
MARTIN 28-SEP-81 1250 -250
KING 17-NOV-81 5000 3750
JAMES 03-DEC-81 950 -4050

FORD 03-DEC-81 3000 2050
ENAME HIREDATE SAL DIFFPRESAL
---------- --------- ---------- ----------
MILLER 23-JAN-82 1300 -1700
SCOTT 09-DEC-82 3000 1700
ADAMS 12-JAN-83 1100 -1900
14 rows selected.
SQL> SELECT Ename, HireDate, Sal,
 Sal - LEAD(Sal, 1, 0)
 OVER(ORDER BY HireDate) DiffNextSal
 FROM Emp;
SQL> SELECT E1.Deptno, E1.DeptSalSum,
 ABS(E1.DeptSalSum - NextSal)||
 DECODE(NVL(SIGN(E1.DeptSalSum - NextSal), 0),

 1, ' More Budget Than Next Department',
 -1, ' Less Budget Than Next Department',
 0, ' Terminating Department') Remarks
 FROM (SELECT Deptno, SUM(Sal) DeptSalSum,
 LEAD(SUM(Sal), 1, NULL)
 OVER(ORDER BY Deptno) NextSal
 FROM Emp
 GROUP BY Deptno) E1;
DEPTNO DEPTSALSUM REMARKS
---------- ---------- ----------------------------------------
10 8750 2125 Less Budget Than Next Department
20 10875 1475 More Budget Than Next Department
30 9400 Terminating Department
SQL> cl scr
SQL> BREAK ON Deptno SKIP 1
SQL> COLUMN DaysDiff FORMAT A40
SQL> COLUMN DEPTNO FORMAT 99
SQL> COLUMN ENAME FORMAT A10
SQL> SELECT Deptno, Ename, HireDate,
 LAG(HireDate, 1, NULL)
 OVER(PARTITION BY Deptno
 ORDER BY HireDate, Ename) Last_Hire,
 NVL(HireDate - LAG(HireDate, 1, Null)
 OVER (PARTITION BY Deptno

 ORDER BY HireDate, Ename), 0)||' Days of Difference.' DaysDiff
 FROM Emp
 ORDER BY DeptNo, HireDate;
DEPTNO ENAME HIREDATE LAST_HIRE DAYSDIFF
------ ---------- --------- --------- ----------------------------------------
10 CLARK 09-JUN-81 0 Days of Difference.
KING 17-NOV-81 09-JUN-81 161 Days of Difference.
MILLER 23-JAN-82 17-NOV-81 67 Days of Difference.
20 SMITH 17-DEC-80 0 Days of Difference.
JONES 02-APR-81 17-DEC-80 106 Days of Difference.
FORD 03-DEC-81 02-APR-81 245 Days of Difference.
SCOTT 09-DEC-82 03-DEC-81 371 Days of Difference.
ADAMS 12-JAN-83 09-DEC-82 34 Days of Difference.
30 ALLEN 20-FEB-81 0 Days of Difference.
DEPTNO ENAME HIREDATE LAST_HIRE DAYSDIFF
------ ---------- --------- --------- ----------------------------------------
30 WARD 22-FEB-81 20-FEB-81 2 Days of Difference.
BLAKE 01-MAY-81 22-FEB-81 68 Days of Difference.
TURNER 08-SEP-81 01-MAY-81 130 Days of Difference.
MARTIN 28-SEP-81 08-SEP-81 20 Days of Difference.
JAMES 03-DEC-81 28-SEP-81 66 Days of Difference.

14 rows selected.
SQL> cl scr
SQL> SELECT Ename, Deptno, Sal,
 FIRST_VALUE(Ename)
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp ORDER BY Deptno, Sal DESC, Ename DESC

SQL> BREAK ON Deptno DUP
SQL> /
ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
KING 10 5000 KING
CLARK 10 2450 KING
MILLER 10 1300 KING
SCOTT 20 3000 FORD
FORD 20 3000 FORD
JONES 20 2975 FORD
ADAMS 20 1100 FORD
SMITH 20 800 FORD
BLAKE 30 2850 BLAKE
ALLEN 30 1600 BLAKE
TURNER 30 1500 BLAKE

ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
WARD 30 1250 BLAKE
MARTIN 30 1250 BLAKE
JAMES 30 950 BLAKE
14 rows selected.
SQL> ed
Wrote file afiedt.buf
 SELECT Ename, Deptno, Sal,
 FIRST_VALUE(Ename)
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp
 --ORDER BY Deptno, Sal DESC, Ename DESC
SQL> /
ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
KING 10 5000 KING
CLARK 10 2450 KING
MILLER 10 1300 KING
FORD 20 3000 FORD
SCOTT 20 3000 FORD
JONES 20 2975 FORD

ADAMS 20 1100 FORD
SMITH 20 800 FORD
BLAKE 30 2850 BLAKE
ALLEN 30 1600 BLAKE
TURNER 30 1500 BLAKE
ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
MARTIN 30 1250 BLAKE
WARD 30 1250 BLAKE
JAMES 30 950 BLAKE
14 rows selected.
SQL> ed
Wrote file afiedt.buf
 SELECT Ename, Deptno, Sal,
 FIRST_VALUE(Ename)
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp
 ORDER BY Deptno, Sal DESC, Ename DESC
 SELECT Ename, Deptno, Sal,
 FIRST_VALUE(Ename)
 OVER(PARTITION BY DeptNo

 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp
 ORDER BY Deptno, Sal DESC, Ename
SQL..>
 SELECT Ename, Deptno, Sal,
 FIRST_VALUE(Ename)
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp
 WHERE Deptno = 30
 ORDER BY Deptno, Sal DESC, Ename
SQL> /
ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
BLAKE 30 2850 BLAKE
ALLEN 30 1600 BLAKE
TURNER 30 1500 BLAKE
MARTIN 30 1250 BLAKE
WARD 30 1250 BLAKE
JAMES 30 950 BLAKE
6 rows selected.
SQL> ed
Wrote file afiedt.buf

 SELECT Ename, Deptno, Sal,
 LAST_VALUE(Ename)
 OVER(PARTITION BY DeptNo
 ORDER BY Sal DESC) Max_Sal_Name
 FROM Emp
 WHERE Deptno = 30
 ORDER BY Deptno, Sal DESC, Ename
SQL> /
ENAME DEPTNO SAL MAX_SAL_NA
---------- ------ ---------- ----------
BLAKE 30 2850 BLAKE
ALLEN 30 1600 ALLEN
TURNER 30 1500 TURNER
MARTIN 30 1250 WARD
WARD 30 1250 WARD
JAMES 30 950 JAMES
6 rows selected.
SQL> ed
FIRST and LAST
The FIRST and LAST functions can be used to return the first or last value from an ordered sequence. Say
we want to display the salary of each employee, along with the lowest and highest within their
department we may use something like.
SELECT empno,
deptno,
sal,
MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
FROM emp
ORDER BY deptno, sal;
EMPNO DEPTNO SAL Lowest Highest
---------- ---------- ---------- ---------- ----------
7934 10 1300 1300 5000
7782 10 2450 1300 5000
7839 10 5000 1300 5000
7369 20 800 800 3000
7876 20 1100 800 3000

7566 20 2975 800 3000
7788 20 3000 800 3000
7902 20 3000 800 3000
7900 30 950 950 2850
7654 30 1250 950 2850
7521 30 1250 950 2850
7844 30 1500 950 2850
7499 30 1600 950 2850
7698 30 2850 950 2850

Monday, 1 May 2017

oracle sql and plsql questions and answers part 4

Q. What is RDBMS? What are different database models?
  
   RDBMS: Relational Database Management System.

   In RDBMS the data are stored in the form of tables
   i.e. rows & columns.

 The different database models
 are 1. HDBMS = Hierarchical Database Management system.
     2. NDBMs = Network Database Management System.
     3. RDBMS = Relational Database Management System.


Q. What is SQL?

  SQL stands for Structured Query Language. SQL was derived from the
 Greek word called "SEQUEL". SQL is a non- procedural language that
 is written in simple English.

Q. What is a transaction?

  Transaction is a piece of logical unit of work done
  between two successive commits or commit and rollback.

Q. What is a commit?

  Commit is transaction statements that make the changes permanent
  into the database.

Q. What is a Rollback?

 Rollback is a transaction statement that undoes all changes to a savepoint or since the beginning of the transaction.

Q. What is DDL?

 DDL  - Data Definition Language.
  
   It is a set of statements that is used to define or alter the
User_defined objects like tables, views, procedures, functions etc.,
present in a tablespace.

Q. What is DML?

  DML - Data Manipulation Language.

   It is a set of statements that is used for manipulation of data.

 E.g. inserting a row into a table, delete a row from a table etc.

Q. What is locking?

 The mechanism followed by the SQL to control concurrent operations
On a table is called locking.

Q. What is a Dead lock?

When two users attempt to perform actions that interfere with one
another,this situation is defined as Deadlock.

E.g.: - If two users try to change both a foreign and its parent key
value at the same time.

Q. What is a Shared Lock?

The type of lock that permits other users to perform a query, but
could not manipulate it, i.e. it cannot perform any modification
or insert or delete a data.

Q. What is Exclusive Lock?

The type of lock that permits users to query data but not change
it and does not permits another user to any type of lock
on the same data. They are in effect until the end of the transaction.

Q. What is Share Row-Exclusive lock?

Share Row Exclusive locks are used to look at a whole table and to
allow others to look at rows in the table but to prohibit others
from locking the table in Share mode or updating rows.


Q. What is Group - Functions?

 The Functions that are used to get summary information’s about group
 Or set of rows in a table.
 The group functions are also termed as aggregate functions.

 Following are the examples of aggregate functions:

  1. AVG () - To find the average value        
  2. MIN () - To find the minimum value of the set of rows.
  3. MAX () - To find the maximum value of the set of rows.
  4. COUNT () - To find the total no of rows that has values.
  5. SUM () - To find the summation of the data of a given column.

Q. What is indexing?

An index is an ordered list of the contents of a column or a group of
columns of a table.
By indexing a table, it reduces the time in performing queries,
especially if the table is large.

Q. What are clusters?

A Cluster is a schema object that contains one or more tables that have
one or more columns in common. Rows of one or more tables that share
the same value in these common columns are physically stored together
within the database.


Q. What is a View?

View is like a window through which you can view or change the information in table. A view is also termed as a 'virtual table'.

Q. What is a Rowid?

  For each row in the database, The ROWID pseudo column returns a row's
address. ROWID values contain information necessary to locate a row:

    * Which datablock in the data file
    * Which row in the datablock (first row is 0)
    * Which data file (first file is 1)
Values of the Rowid pseudocolum have the datatype ROWID.

Q. What is a PRIMARY KEY?

PRIMARY KEY CONSTRAINT:

Q. Identified the columns or set of columns, which uniquely identify each row of a table and ensure that no duplicate rows exist in the table.
    2. Implicitly creates a unique index for the column (S) and
           specifies the column(s) as being NOT NULL.
    3. The name of the index is the same as the constraint name.
    4. Limited to one per table.

    Example:
        CREATE TABLE loans (account NUMBER (6),
                                    loan_number NUMBER(6),
                     ...
                        CONSTRAINT loan_pk PRIMARY KEY
                     (account, loan_number));

Q. What is a Unique constraint?

UNIQUE Constraint:

    1. Ensures that no two rows of a table have duplicate values
       in the specified columns(s).
    2. Implicitly creates a unique index on the specified columns.
    3. Index name is the given constraint name.

        Example:
         CREATE TABLE loans (
        Loan_number NUMBER (6) NOT NULL UNIQUE,
                ...
                );

Q. What is the difference between a unique and primary key?

The Primarykey constraint is a constraint that takes care maintaining
the uniqueness of the data, enforcing the not null characteristic,
creates a self-index.
The Unique key constraint maintains only the uniqueness of the
data and does not enforce the not null characteristic to the
data column.

Q. What is a foreign key?


FOREIGN KEY Constraint:

Q. Enforces referential integrity constraint, which requires that for each row of a table, the value in the foreign key matches a value in the primary key or is null.
    2. No limit to the number of foreign keys.
    3. Can be in the same table as referenced primary key.
    4. Can not reference a remote table or synonym.

        Examples:
       
    1. Explicit reference to a PRIMARY KEY column

        CREATE TABLE accounts (
            account NUMBER(10) ,
            CONSTRAINT borrower FOREIGN KEY (account)
                REFERENCES customer (account),
                        ...);

    2. Implicit reference to a PRIMARY KEY column

        CREATE TABLE accounts (
                account NUMBER(10),
                CONSTRAINT borrower FOREIGN KEY (account)
        REFERENCES customer,
          ...);

Q. What is data integrity? What are the types of integrity?

         1. A mechanism used by the RDBMS to prevent invalid data entry
       into the base tables of the database.
    2. Defined on tables so conditions remain true regardless of
       method of data entry or type of transactions.

 The following are the type of integrity


             * Entity integrity
         * Referential Integrity   
          * General Business rules


Q. What is a Referential Integrity?

    1. Enforces master/detail relationship between tables based on keys.

        * Foreign key
        * Update Delete restricts action
        * Delete Cascade action



Q. What are different data types?

The following are the different data types available in Oracle
1. Internal Data types
2. Composite Data types

Internal Data types                                 
1. Character Datatype
2. Date Datatype
3. Row and long row data types
4. Rowid Datatype

Composite Data types

1. Table Data type
2. Record Data type

Q. What is VARCHAR2? How is it different CHAR?

The Varchar2 datatype specifies a variable length character string. When you create a varchar2 column, you can supply the maximum number of bytes of data that it can hold. Oracle Subsequently stores each value in the column exactly as you specify. If you try to insert a value that exceeds this length, Oracle returns an error.

The Char datatype length is 1byte. The maximum size of the Char datatype is 255. Oracle compares Char values using the blank-padded comparison semantics. If you insert a value that is shorter than the column length, Oracle blank-pads the value to the column length.   


Q. What is datatype mixing?

 There are two data types %TYPE and  %ROWTYPE. The first one declares
 a variable to be of the data type of the column of the table to which       it is referring.

   For example, if you declare a variable like this:

            my_empno   emp.empno%TYPE

       then, my_empno will have the data type of the empno column of the table emp.

   Similarly if you declare the variable like this:

              my_emprec  emp%ROWTYPE

         then, my_emprec will have the data type of all the fields of the emp table.

         For example. Suppose employee table is like this:
      empno number(2),
      empname varchar2(10),
      Sal number (10,2).

           Then my_emprec will be of a data type whose first 2 positions will be of number data type, the next 10 will be of varchar2 data type while the last 10 will be of data type number.

       One can refer to the individual fields of this record variable as
    my_emprec.empno, my_emprec.empname, my_emprec.sal.

   

Q. What is NULL?

 A data field without any value in it is called a null value.

 A Null can arise in the following situation
 * Where a value is unknown.
 * Where a value is not meaningful (i.e.) in column representing
   commission for a row that does not represent salesman.

Q. What is a sequence?

A sequence is a database object from which multiple users may generate
unique integers.


Q. What are pseudo-columns in ORACLE?

   The columns that are not part of the table are called as pseudo columns.
 
Q. What is like operator? How is it different from IN operator?

   The type of operator that is used in character string comparisons
  with pattern matching.

 Like operator is used to match a portion of the one character string
 to another whereas IN operator performs equality condition between
 two strings.

Q. What is Single Row numbers Functions?

  The type of function that will return value after every row is being
  processed.

  Following are some of the row number functions.

   Function Name             Purpose

   1. ABS (n)            returns the absolute value of a number

   2. Floor (n)            returns the largest integer value
                    equal or less than  n.
   3. Mod (m, n)             returns the remainder of m divided by n.

   4. Power (m, n)        returns m raised to the n power.

   5. Round (n)            returns n rounded to m places
                    right of a decimal point.

   6. Sqrt (x)            returns the sqrt value of x.

   7. Trunk (n, m)        Returns n truncated to m decimal
                    places.

Q. What are single row character functions?
           
The function that processes at value of data, which is of character datatype, and returns a character datatype after every row is being processed are termed as single row character functions.

Function Name                    Purpose.

Q. Char (n)                returns the character having
                    an ASCII value.

2. Initcap (n)            returns character with first
                    letter of each argument in
                    UPPERCASE.
3. Lower (n)            returns characters with
                    all the letters forced to
                    lower case.

4. ltrim(n)                Removes the spaces towards
                    the left of the string.

5. upper(n)                Returns characters with
                    all the letters forced to
                    upper case.

Q. What are Conversion Functions?

The functions used to convert a value from one datatype to another
are being termed as conversion functions.

Function Name             Purpose

To_char (n, (fmt))        converts a value of number datatype
                    to a value of character datatype.

To_number (n)            converts a character value into a number.

Rowidtochar (n)    converts rowid values to character datatype.
                the result of this conversion is always
                18 character long.

Q. What are Date functions?

Functions that operate on Oracle Dates are termed as Date functions.

All date functions return a value of date datatype except the \
function months_between returns a numeric value.

Function            Purpose

ADD_MONTHS (d, n)        returns the date 'd' plus n months.
                n must be an integer.
                n can be positive or negative.

LAST_DAY (d)        returns the date of the last day
                of the month containing the date 'd'.

NEXT_DAY (d, char)    returns date of first day of week
                named after char that is later than
                d, char must be a valid day of the
                week.

MONTHS_BETWEEN (d, e)    returns no of months between dates
                d & e.

Q. What is NEW_TIME function?

SYNTAX:  New_time (d, a, b)
  
New_time function returns date and time in a time zone b and time in time zone. a and b are character expressions.

Following are the some of the character expressions:

Character expression            Description

AST                    Atlantic Stand or daylight time
BST, BDT                Burning stand or daylight time
GMT                    Greenwich Mean Time.
PST, PDT                Pacific Standard Time.
YST, YDT                Yukon standard or daylight time.

Q. What is Convert function?

Convert function converts two different implementations of the
same character set .

For instance: from DEC 8 bit multi-lingual characters to HP 8 bit
Multi-lingual character set.

Following are the character sets

US7ASCII - US7bit ASCII character set
WE8DEC   - Western European 8 bit ASCII set
WE8HP    - HP's Western European 8 bit ASCII set
F7DEC    - DEC's French 7-bit ASCII set

Convert (char [destination], [source])

Q. What is a translate function?

The function that returns a character after replacing all occurrences
of the character specified with the corresponding character is called
as translate function.

E.g. TRANSLATE ('Hello','l','L') gives you HeLLo

Q. What is a soundex function?

Soundex is a function that returns a character string representing
the sound of the words in char. This function returns a phonetic
representation of each word and allows you to compare words
that are spelled differently but sound alike.

Soundex (char);

Q. What is a replace function?

Replace function returns character with every occurrence of the
search string replaced with the replacement string. If the replacement
string is not supplied, all occurrences of search_string are being
removed. Replace allows you to substitute one string from another.

Q. What is a Floor function?

Floor Function returns the largest integer equal to or than n

Syntax: floor (n);

Q. What is INITCAP Function?

The initcap function returns char,with first letter of each word in uppercase, all other letters in lowercase. A word is delimited by white space

Q. What is ASCII Function?

The ASCII function returns the collating sequence of the first character of lchar. There is no corresponding EBCDIC function.
On EBCDIC systems, the ASCII function will return EBCDIC collating
sequence values.

Q. What is a Decode Function?

The Decode function is used to compare an expression to each search
value and returns the result if expr equals the search value.

E.g.: Decode (expr, search1, result1, [search2, result2], [default]);

Q. What is Greatest Function?

The Greatest function returns the greatest of a list of values. All expr after the first are converted to the datatype of the first before
comparison is done.

Q. What are Format models?

Format models are used to affect how column values are displayed when
a format retrieved with a select command. Format models
do not affect the actual internal representation of the column.

Q. Give 5 examples for DATE, Number function?

Examples for Number Function:

Q. Select abs (-15) "Absolute:" from dual
2. Select mod (7,5)  "Modula" from dual
3. Select round (1235.85,1) from dual
4. Select power (2,3) from dual
5. Select floor (7.5) "Floor" from dual

Examples for Date Function

1. Select sysdate from dual
2. Select sysdate-to_date (23-Sep-93) from dual
3. Select sysdate + 90 from dual
4. Select sysdate -90 from dual
5. Select next_day (sysdate,"Friday") from dual

Q. What is an expression?

An expression is a group of value and operators which may be evaluated a single values.

Q. What are the types of expression?

The different types of expressions are

1. Logical expression
2. Compound expression
3. Arithmetic expression
4. Negating expression.

Q. What is a synonym?

The synonym is a user-defined object that is used to define an alias name for the user defined objects like table view etc.

Q. What is a condition?

A Condition could be said to be of the logical datatype that evaluates
the expression to a True or False value.


Q. What are the 7 forms of condition?

There are totally 7 forms of condition
Q. A comparison with expression or subquery results.
Q. A comparison with any or all members in a list or a subquery
3. A test for membership in a list or a subquery
4. A test for inclusion in a range
5. A test for nulls.
6. A test for existence of rows in a subquery
7. A test involving pattern matching
8. A combination of other conditions

Q. What are cursors?

Oracle uses work areas called private SQL areas to execute SQL statements and store processing information. This private SQL work area is known as cursors.

Q. What are explicit cursors?

Cursors that are defined for performing a multiple row select are known
as explicit cursors.

Implicit cursors are the type of cursors that is implicitly opened
by the Oracle itself whenever you perform any DML statements like
Update, delete, insert or select into statements.

Q. What is a PL/SQL?

PL/SQL is a transaction processing language that offers procedural
solutions.

Q.What is an embedded SQL?

All the SQL statements written in a Host language are known
as Embedded SQL statements.

Q. What are the different conditional constructs of PL/SQL?

 The statements that are useful to have a control over the set
of the statements being executed as a single unit are called as
conditional constructs.

The following are the different type of conditional constructs
of PL/SQL

1. if <condition>       
   then
   elsif<condition> then
   end if

2. While <condition>
   loop
   end loop

3. loop
   exit when<conditon>
   end loop

4.  for <var> in range1..range2
   loop
   end loop

5.  for i in <query/cursor identifier>
   loop
   end loop

Q. How is an array defined in PL/SQL?

    Typedef <identifier> table of <datatype>
        Index by binary_integer;
Q. How to define a variable in PL/SQL?

     Variablename datatype<size> <not null> <: = value>

Q. How to define a cursor in PL/SQL?

Cursor variable is <query>

Q. What are exceptions?

The block where the statements are being defined to handle internally
 and userdefined PL/SQL errors.

Q. What are the systems exceptions?

When an Oracle error is internally encountered PL/SQL block
raises an error by itself. Such errors are called as internal
or system defined exception. 
Following are some of the internal exceptions:
1. Zero_divide, 2. No_data_found 3. Value_error 4. Too_many_rows

Q. How to define our own exceptions in PL/SQL?

Define a PL/SQL variable as an exception in the variable declaration section.

 In order to invoke the variable that is an exception type
 use the raise statement.

 Declare a exception;
 Begin
 statements....
-----
if x > y
 then
  raise a;
 end if;
exception
 when a then
  statements,
  rollback;
 when others then
  commit;
end;

Q. How is the performance of Oracle improved by PL/SQL in Oracle?

Without PL/SQL the ORACLE RDBMS must process SQL statements one at a time, Each SQL statement results in another call to RDBMS and higher performance overhead. This overhead can be significant when you are issuing many statements in a network environment.
With the PL/SQL all the SQL statements can be sent to RDBMS at one time.
This reduces the I/O operations.  With PL/SQL a tool like Forms can do
all data calculations quickly and efficiently without calling on
the RDBMS .

Q. What is SCHEMA?

A SCHEMA is a logical collection of related items of tables and Views.

Q. What are profiles?

A Profile is a file that contains information about the areas that a user can access.    

Q. What are roles?

A role is a collection of related privileges that an administrator can grant collectively to database users.

Q. How can we alter a user's password in ORACLE?

Inorder to Alter the password of the user we have to use the following statement:

ALTER USER user_name identified by passwd

E.g.: Alter user sam identified by Paul

Q. What is a tablespace in Oracle?

A tablespace is a partition or logical area of storage in a database that directly corresponds to one or more physical data files.

Q. What is an extent?

An extent is nothing more that a number of contiguous blocks that ORACLE-7 allocates for an object when more space is necessary for the object data.

Q.    What are PCTFREE and PCTUSED parameters?

PCTFREE: - PCTFREE controls how much of the space in a block is reserved for statements that update existing rows in the object.
PCTUSED: - PCTUSED is a percentage of used space in a block that triggers the database to return to the table's free space list.

Q. What is a block in Oracle?

The Place where the data related to Oracle are stored physically in an Operating System is known as block.

Q. What is Client-server architecture?

A client/server system has three distinct components
•    Focusing on a specific job
•    A database server
   A client application and a network.

A server (or back end) focuses on efficiently managing its resource Such as database information. The server's primary job is to manage its resource optimally among multiple clients that concurrently request the server for the same resource.

Database servers concentrate on tasks such as

    * Managing a single database of information among many concurrent
      users.
    * Controlling database access and other security requirements.
* Protecting database information with backup and recovery features.
    * Centrally enforces global data integrity rules across all
      Client applications.

A client application ("the front end") is the part of the system that users employ to interact with data. The client applications in a client/server database system focus on jobs such as

* Presenting an interface a user can interact with to accomplish work.
    * Managing presentation logic such as popup lists on a
      data entry form or bar graphs in a graphical data presentation
      tool.
        * Performing application logic, such as calculating fields
      in a dataentry form.
    * Validating data entry.
    * Requesting and receiving information from a database server.

A network and communication software is the vehicle that transmit
data between the clients and the server in a system. Both the clients
and the server run communication software that allows them to
talk across a network.

Types of Client Server Architecture:

1.  Dedicated Client Server Architecture
2.  Multi-threaded Client Server Architecture
3.  Single- Task Client Server Architecture

Dedicated Server: Connects the Client Directly to the dedicated server

Multi-Threaded Server: It is a type of architecture that is a combination of dispatcher, listener and front-end server process to serve the requests of many clients with minimal process overhead on the database server.

Single-Task server: In host-based database server system a user
employs a dumb terminal or terminal emulator to establish a session
on the host computer and run the client database application.


73. What is a segment in Oracle? Explain the different types?

The places where the data are stored in the allotted tablespace are called as segments. The data may be a table or index data required by DBMS to operate. Segments are the next logical level of a storage tablespace.

There are basically 5 types of segments
* Data segment: Contains all the data of each table
* Index segment: Contains all the index data for one or more indexes
Created for a table.

* Rollback segment: Contains the recorded actions, which should be undone under certain circumstances like
* Transaction rollback
* Read consistency
* Temporary segment:

Whenever a processing occurs Oracle often requires temporary workspace for intermediate stages of statement processing. These areas are known as temporary segments.

* Bootstrap segment: Contains information of the data dictionary definition     for the tables to be loaded whenever a database is opened.



Q. What is the use of Rollback segment?

It is a portion of a database that records the information about the actions that should be undone under certain circumstances like

* Transaction Rollback
* Read consistency

Q. What is read-consistency in Oracle?

Read consistency in Oracle is a process that ignores the changes by others in a table whenever a table is queried. Read consistency in Oracle is achieved by a statement
SET TRANSACTION READ ONLY

Q. What is SGA?

SGA is System Global Area.

The library cache and dictionary cache makes up the shared pool. The shared pool combined with buffer-cache make up the System Global Area.
Library Cache: - It stores the SQL Statements and PL/SQL Procedures.
Dictionary Cache: - Holds dictionary information in memory.
Buffer and Cache: - the place where the data related to recently requested transaction is stored.

Q. What is Back Ground Process?

The Process of server is being classified into two processes namely Foreground and Background.
   
Foreground handles the request from client processes while background handle other specific row of the database server like writing data to data and transaction Log Files.

Q. System Userid?

Whenever you create a database an Userid is automatically created related with database administration connections. This account/userid is called System Userid.

Q. SYS Userid?

It is a special account through which DBA can execute special database administration connections.    SYS is the owner of database's data dictionary table.

Q. Data Dictionary?

It provides the details on the database objects such as columns, views Etc., the oracle users, the privileges and the rights of users over different objects.


Q. SQL*DBA?

SQL*DBA is a utility through which you can manage a database system effectively.

Q. ORACLE ADMINISTRATOR?

The person who takes care of monitoring the entering performances of the database system is called, as an Oracle Administrator.Oracle Administrator is the main person who takes care of assigning the set of to act as DBA for monitoring certain jobs like
    1. Creating primary database storage structure.
    2. Monitoring database performance and efficiency.
    3. Backing up and restoring.
    4. Manipulating the physical location of the database.
TO CREATE DATABASE:
    1. Determining appropriate values for the file limit parameters of the create database command.
    Parameters
    Max data files: Determines the maximum number of data files that can ever be allocated for the database
    Max Log Files: Determines the maximum number of log groups for the database.
    Max Log Members: Maximum number of members for each log group.

Q. What are database files?
  
    The physical files of Oracle are known as database files. 

Q. What is a Log File?

The files that contains information about the information of   recovery of oracle database at the event of a SYSTEM CRASH or  a MEDIA Failure.


Q. What is an Init file?

Init files are known as Initialization Parameter files.
Init files are used for setting the parameters
* For an Oracle instance
* For Log files



Q. What is a control file? What is its significance?

A control is a small binary file. It contains the entire system executable code named as ORACLE.DCF.

  A control file always consists of the following
    1: Name of the database
    2: Log files
    3: Database creation

Q. What does an UPDATE statement does?
  
   To update rows in a table.

Q. What does a Delete statement does?
 
   To remove the rows from the table.

Q. What does an insert statement do?

   To insert new rows into a database.

Q. What does a Select statement do?
 
   To query data from tables in a database
 
Q. How to create a table using selects and inserts statements?

Using Select statement:

Create table tablename
as
<Query >

Using insert statement we cannot create a table but can only append
the data into the table

Using Insert statement:

Insert into tablename
<Query>

Q. How to delete duplicate rows in a table?

Delete from tablename where rowid not in
(Select min (rowid) from tablename group by column1, column2...)

Q. What is an instance?
  An Oracle instance is a mechanism that provides the mechanism for processing and controlling the database.     

Q. What is startup and shutdown?

Startup is a process making the Oracle Database to be accessed by all
the users
There are three phases to database startup
Q. Start a new instance for the database
2. Mount the database to the instance
3. Opening the mounted database

Shutdown is a process making the Oracle Database unavailable for all
the users.

There are three phases to database shutdown

1. Close database

2. Dismount the database from the instance

3. Terminate the instance.

Q. What is mounting of database?


Q. What is a two-phase commit?


Q. What are snap-shots?

A Snapshot is a stable that contains the results of query Of one or more tables or views, often located on a remote database.

Q. What are triggers and stored Procedures?

A procedure is a group of PL/SQL statement that you call by a name. Compiled version of procedure that is stored in a database are known as Stored Procedures.
A database trigger is a stored procedure that is associated with a table.
Oracle automatically fires or executes when a triggering statement is issued.

Q. What are Packages?

A package is an encapsulated collection of related program objects stored together in the database.

Q. What is SQL*Forms3.0? Is it a Client or a server?

Sql*Forms is a general-purpose tool for developing and executing forms based interactive applications. The component of this tool is specially
designed for application developers and programmers and it is used for the following tasks :

* Define transactions that combine data from multiple tables into a single form.
* Customize all aspects of an application definition using std-fill-in- interface to enhance the productivity and reduce learning time.

Sql*Forms3.0 is a Client.

Q. What are Packaged Procedures?

A packaged procedure is a built in PL/SQL procedure that is available in all forms.

Using packaged procedure we can build triggers to perform the following
Tasks to
* Reduce the amount of repetitive data entry.
* Control the flow of application
* Ensuring the operators always follow sequence of actions when
they use a form.

Q. What are different types of triggers?

The following are the different type of triggers they are

1. Key-triggers
2. Navigational Triggers.
3. Transactional Triggers.
4. Query-based Triggers
5. Validation Triggers
6. Message - Error handling Triggers.


Q. What is the difference between the restricted and Un-Restricted Packaged Procedure?

Any packaged procedure that does not interfere with the basic function
of SQL*Forms is an unrestricted packaged procedure. The Un-restricted
Packaged procedure can be used in all types of triggers.

Any packaged procedure that affects basic SQL*FORMS function is a restricted packaged procedure. Restricted packaged procedure can be used only in key-triggers and user-named triggers.

Q. What is a system variable?

A System variable is a SQL*Forms variable that keeps track of some internal process of SQL*Forms in state. The system variable helps us to control the way an application behaves. SQL*Forms maintains the value of a system on a performance basis. That is the values of all the system variables correspond only to the current form.

Q. What are Global Variables?

A Global variable is a SQL*Form variable that is active in any trigger within a form and is active throughout SQL*Form (Run-Form) session. The variable stores string value upto 255 characters.

Q. What are the different types of objects in SQL*Forms?

A SQL*Form application is made up of objects. These objects contain all
the information that is needed and produce the SQL*Forms application.

Following are the objects of the SQL*Forms:

1. Form
2. Block
3. Fields
4. Pages
5. Triggers
6. Form-Level-Procedures.

Q. What are Pages?

Pages are collection of display information such as constant text and graphics. All fields are displayed in a page.

Q. What are a Block and its types? Explain the different types of blocks?

Block is an object of Forms that describes section of a form or a subsection of a Form and serve as the basis of default database interface.

Types of Blocks:

1. Control Block: Control block is not associated with any table in the
database. It is made up of fields that are base table fields, such as temporary data fields.

2. Detail Block: Detail Block is associated with a master block in
 Master-detail relationship. The detail block displays detail records associated with master records in a block.

3. Master-Block: A master block is associated with a master-detail relationship. The master block display master records associated with detail records in the detail block.

4. Multi-record Block: A multi-record block can display more than one record at a time.

5. Non-enterable Block: A non-enterable block consists of all non-enterable fields.

6. Single-record Block: A single record block can display only one record at a time.

Q. What is a Screen Painter?

This is a SQL Forms "work area" where you can modify the layout of forms. The screen painter displays one page area at a time.

Q. What are the different field types?

The different types of fields in SQL*Forms are
1. Base - table field
2. Control-field
3. Enterable-field
4. Hidden-field
5. Look-up field
6. Non-enterable field
7. Scrolled - field

Q.What is page Zero?

The place where the hidden fields are being placed in an application


Q. What does Message procedure do?

The Message procedure displays specified text on the message line.

Q. What does Name_in function do?

The Name_in packaged function returns the contents of the variable to which you apply it. The returned value is in form of a string.

Q. What does CLEAR_EOL procedure do?

Clear_Eol clears the current field's value from the current cursor position to the end of the line or field.

Q. What does On-Error trigger do?

The On-error trigger fires whenever SQL*Forms would normally cause an error message to display. The actions of an On-Error triggers is used for the following purposes:

* Trap and recover an error.
* Replace a standard error message with a customized message.

Q. What does copy procedure do?

The Copy procedure writes a value into a field. Copy exists specifically to write a value into that is referenced through NAME_IN packaged function.

Q. What is the Arraysize parameter?

The Array-Size parameter is a block-characteristic that specifies the Maximum number of records that SQL Forms (Run-Form) can fetch from the database at one time.

Q. What does Go_Block packaged procedures do?

The Go_Block packaged procedure navigates to the indicated Block.If the target is non-enterable an error occurs.

Q. What does ANCHOR_VIEW procedure do?

Anchor_view moves a view of a page to a new location on the screen. This procedure effectively changes where on the screen the operator sees the view.

Q. How to call a form from inside a form?

Inorder to call a form from inside a form we have to use the CALL packaged-procedure.
Inorder to call a form from inside a form the packaged procedure Call is used.
Syntax: CALL (Formname).

When call runs an indicated form while keeping the parent form active.
SQL*Forms runs the called form with the same SQL*Forms options as the
parent form.

Q. How to send parameters to another form?

Inorder to send parameters across the forms we use the global variables.

Q. How to give automatic hint text for fields?

Inorder to give automatic hint text for fields, In the field definition screen of the fields we are having an option called Hint value. Inorder to activate this option in the Select attribute section invoke the option called Automatic Hint.

Q. How to see key map sequences?

Inorder to see key map sequences we have to press the SHOW KEY screen
key function.

Q. What is SYNCHRONIZE procedure does?

The synchronize procedure synchronizes the terminal screen with the internal state of form, that is synchronize updates the screen display to reflect the information that SQL*Forms has in its internal representation of the screen.

Q. What is EXECUTE_QUERY procedure?

The Execute_query procedure flushes the current block, opens a query and fetches a number of selected records. If there are changes to commit, SQL*Forms prompts the operator to commit them during the execute_qury event.

Q. How to customize system message in SQL*Forms?

Inorder to customize the system messages the On-Message trigger is used.

Q.  How to define the fields in WYSIWYG Format?


Q.  What is an On-Insert trigger? How is it different from Pre-insert
trigger?

An On-insert trigger replaces the default SQL*Forms processing for handling inserted records during transaction posting. It fires once for each rows that is marked for insertion into the database. An On-insert Trigger fires during the Post and Commit Transactions event. Specifically it fires after the Pre-insert trigger and before the   
Post-insert trigger.  

Q. What is the difference between a Trigger and a Procedure?

Procedures can take in arguments where as Triggers cannot take in arguments.

Q. How to call a stored procedure from inside a form?

To call a Stored Procedure inside a form

    Trigger Text:

     Procdurename<paramaters>

Q. What are V2 Triggers?

V2 Triggers are the types of Triggers in which we can perform only a simple query. And we cannot write a PL/SQL block.

Q. How to rename a Form?

To rename a form select the rename option in the Action Menu.  Then give the form name.  Press Accept.  In the next field give the new name.  Press Accept to Execute.

Q. What is a Pop -up page? How to define one?

Pop-Up Pages: -
Pop-Up page is a SQL*Forms object which overlays on an area of the current displayed page in response to some event or for user call. To define a Pop-Up page use the page definition form which is in the Image-Modify option.  In that form put an X in the Pop-Up field to make the current page as Pop-Up.

Q. What is a Group in SQL * REPORTWRITER?

 Group in ReportWriter: -

Group is a collection of fields, or single field.  Usually by default a group will bare the field, which are references by a single query. But we can change from single query group  -multi groups.

Q. How do you define a Parent-child relationship in ReportWriter?

Parent - Child Relation: -

    To define a Parent-Child relationship first we need more that one
Query.  We should first enter the Parent Query and then the Child Query.  In the Child Query Form we should give the Parent Query Name in the desired position and the common columns in both queries.

Q. What is a Rowcount function in ReportWriter?

    It is a field level function that is used for generation of automatic row numbers related to database column that does not have null values.

Q. How do you define a matrix report?

 Matrix Report: -

Matrix Report is a Report that consists of Two Parent Queries and one Child Query.

Procedure for Defining a Matrix Report:

Q. Define Two Parent Queries.

2. Define a Child Query. In the Definition screen specific which column of the child is to be related to the Query1 and to Query2.

3. After defining the queries in the Query option, In the
Group option

Place All the Groups in the option called MatrixGroup
Define the Print Direction for Query1 as down
Define the Print Direction for Query2 as across
Define the Print Direction for Child Query as cross tab


Q. How do you execute a report from within a form?

    Use the following command to run a report from the FORM.

   Host ('runrep <rep_name> term<terminal_type> userid=<userid/passwd>);

Q. What are exp and imp utilities?

Export & Import: -
   
    Export utility is to write data from database to operating system files called Export Files. An export does this by changing the data and table structures in to ASCII or EBCDIC codes.

    Import is a utility with which we can write the data from Export file to database. Export Files can be only read by Import.