Thursday

Changing Permissions on files,Changing Owners,Groups

Chmod command is used to change file permissions. chmod -- Changing The File Permissions To change the file permissions , you must be the owner of the file or you must be the root user. The root user can change any permission bit. This may not be true of the owner. The one bit that the owner may not be able to switch on is the SGID bit. To turn on that bit, the owner must be a member of the group that the file is in. If this restriction was not in place, a user could simply create an SGID program to give himself access to files controlled by groups other than those to which he belongs. Remember that, as we mentioned above, the SGID bit has been often overloaded into also being used for file locking. A version of Unix may or may not allow a file owner to switch on the SGID bit of a file in a different group if no execute bit is set. Simply turning on an execute bit may result in the SUID and SGID bits being cleared (even for root). This is a security feature to ensure that the user intends for the SUID and SGID bits to be set. The user can switch them back on explicitly. Or the user can simply explicitly set all the bit at once. Also be aware that writing to a file may, on some versions of Unix, clear the SUID and SGID bits. See below for the effect of changing the owner or group of a file. In Unix access classes and access types specifies how to establish file permissions, different types of access to a file. Access classes are groups of users, and each may be assigned specific access types. The access classes are "user", "group", "other", and "all". These refer to the user who owns the file, a specific group of users, the other are users who are not in the group, and all are three sets of users. Access types (read, write, and execute) determines the access method of file by each access class. The general syntax is chmod -R/c/f/v [u / g / o / a] [+ / - / =] [rwxXstugo..] There are two basic ways of using chmod to change file permissions: Symbolic method: --------------- The first and probably easiest way is the relative (or symbolic) method, which lets you specify access classes and types with single letter abbreviations. A chmod command with this form of syntax consists of at least three parts from the following lists: Access Class Operator Access Type u (user) + (add access) r (read) g (group) - (remove access) w (write) o (other) = (set exact access) x (execute) a (all: u, g, and o) For example, to add permission for everyone to read a file in the current directory named myfile, at the Unix prompt, you would enter: chmod a+r filename Where 'a' stands for "all", the '+' for "add", and the 'r' for "read". Note: This assumes that everyone already has access to the directory where filename is located and its parent directories; that is, you must set the directory permissions separately. If you omit the access class, it is assumed to be all, so you could also enter the previous example as: chmod +r filename You can also specify multiple classes and types with a single command. For example, to remove read and write permission for group and other users (leaving only yourself with read and write permission) on a file named filename, you would enter: chmod go-rw filename You can also specify that different permissions be added and removed in the same command. For example, to remove write permission and add execute for all users on filename, you would enter: chmod a-w+x filename In each of these examples, the access types that aren't specified are unchanged. The previous command, for example, doesn't change any existing settings specifying whether users besides yourself may have read ( r ) access to filename. You could also use the exact form to explicitly state that group and other users' access is set only to read with the = operator: chmod go=r filename The chmod command also operates on directories. For example, to remove write permission for other users on a subdirectory named mydir, you would enter: chmod o-w mydir To do the same for the current directory, you would enter: chmod o-w Be careful when setting the permissions of directories, particularly your home directory; you don't want to lock yourself out by removing your own access. Also, you must have execute permission on a directory to switch ( cd ) to it. Absolute Form: -------------- The other way to use the chmod command is the absolute form. In this case, you specify a set of three numbers that together determine all the access classes and types. Rather than being able to change only particular attributes, you must specify the entire state of the file's permissions. The three numbers are specified in the order: user (or owner), group, other. Each number is the sum of values that specify read (4), write (2), and execute (1) access, with 0 (zero) meaning no access. For example, if you wanted to give yourself read, write, and execute permissions on filename; give users in your group read and execute permissions; and give others only execute permission, the appropriate number would be calculated as (4+2+1)(4+0+1)(0+0+1) for the three digits 751. You would then enter the command as: chmod 751 filename As another example, to give only yourself read, write, and execute permission on the current directory, you would calculate the digits as (4+2+1)(0+0+0)(0+0+0) for the sequence 700, and enter the command: chmod 700 If it seems clearer to you, you can also think of the three digit sequence as the sum of attributes you select from the following table: 400 read by owner 200 write by owner 100 execute by owner 040 read by group 020 write by group 010 execute by group 004 read by others 002 write by others 001 execute by others To create an access mode, sum all the accesses to permit. For example, to give read privileges to all, and write and execute privileges to the owner only for a file, you would sum: 400+200+100+040+004 = 744. Then, at the Unix prompt, you would enter: chmod 744 filename Some other frequently used examples are: 777 anyone can do anything (read, write, or execute) 755 you can do anything; others can only read and execute 711 you can do anything; others can only execute 644 you can read and write; others can only read chown -- Changing The File Owner -------------------------------- Originally, Unix allowed a file owner to give away a file. A file's owner could change the owner to someone else. There was no way for a non-root user to undo this operation. When Unix split into a Berkeley/AT&T versions, the USG (Unix Support Group, part of AT&T) versions of Unix tended to inherit this behavior. Meanwhile BSD (Berkeley Software Distribution, part of University of California, Berkeley) removed chown from non-root users. BSD had implemented disk quotas which could limit how much disk space a user could have in a filesystem. Naughty users could give away large files to sneek past the quotas. Today, it is not easy to say if a non-root can chown a file. Many versions of Unix allow both behaviors. HP-UX has a setprivgroup facility that can control whether or not members of a particular group can invoke chown. Solaris has a global paramter rstchown which can be set to allow global chown. Setting this parameter also disables a change-group limitation described below (without affecting the SGID limitations described above). Recent Linux version have a CAP_CHOWN capability to control this feature. You will need to consult your documentation for other versions of Unix. And you will need to consult your System Administrator to see how your particular system is configured. The default with most OS's is for chown to be restricted to root only. And there is a consensus that it should stay this way for security considerations. If a non-root user does change the owner of a file and any execute bit is on, the SUID and SGID bits must be cleared. This may or may not happen with root. The chown command The chown command is used to change the user and/or group which owns one or more files or directories. Its general format is : chown [-Rcfv] [username][:.][groupname] foo.txt The flags used above are same as those used in the chmod command . The following are the different ways in which this command can be used : The username followed by a dot or colon followed by a groupname changes both the user and group ownerships to those specified. The username followed by a dot or colon and no groupname changes the user ownership as specified and changes the group ownership to the specified user?s login group. If the colon or dot and groupname are specified without a username, then only the groupownership is changed. This is effectively the same as the chgrp command. If the username is not followed by a dot or a colon, then only the user ownership is changed. chown, chgrp -- Changing The File Group The chown command can (with any modern, Posix compliant version of Unix) also attempt a group change. And there is a chgrp command. Both of these invoke the chown() system call to change a group. The fact that a common system call is involved helps explain why some OS versions jointly enforce or relax restrictions on non-root users for both owner and group changes. A non-root user can change the group of file he owns to a group of which he is a member. Posix prohibits a non-root user from changing a files group to a group of which he is not a member. But some OS's lift this restriction if the restriction against changing a file's owner has been lifted. If the group is changed by a non-root user and one or execute bits are set, the SUID and SGID bits are cleared. The chgrp command The chgrp command is used to change the group ownership of one or more files or directories. Its general syntax is : chgrp [-Rcfv] groupname foo.txt The flags used here are also the same as those in the chmod command. The changes in ownership are applied to the groupname and the filename specified.

Friday

Oracle Explain Plan

The EXPLAIN PLAN statement displays execution plans chosen by the Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements. A statement's execution plan is the sequence of operations Oracle performs to execute the statement. An execution plan defines how Oracle finds or writes the data. The components of execution plans include:

  • An ordering of the tables referenced by the statement
  • An access method for each table mentioned in the statement
  • A join method for tables affected by join operations in the statement

The general syntax of EXPLAIN PLAN is: explain plan for your- sql-statement;

EXPLAIN PLAN output shows how Oracle executes SQL statements. To determine the execution plan Oracle follows to execute a specified SQL statement. This statement inserts a row describing each step of the execution plan into a specified table. EXPLAIN PLAN results alone, however, cannot differentiate between well-tuned statements and those that perform poorly. For example, if EXPLAIN PLAN output shows that a statement uses an index, this does not mean the statement runs efficiently. Sometimes using indexes can be extremely inefficient. It is thus best to use EXPLAIN PLAN to determine an access plan and later prove it is the optimal plan through testing. If you execute an EXPLAIN PLAN, Oracle will analyze the statement and fill a special table with the Execution plan for that statement. Before issuing an EXPLAIN PLAN statement, verify whether PLAN_TABLE exits or create a table to hold its output . Use one of the following approaches:

1)Run the SQL script UTLXPLAN.SQL to create a sample output table called PLAN_TABLE in your schema. The exact name and location of this script depends on your operating system. PLAN_TABLE is the default table into which the EXPLAIN PLAN statement inserts rows describing execution plans.

2)Issue a CREATE TABLE statement to create an output table with any name you choose. When you issue an EXPLAIN PLAN statement you can direct its output to this table.

Any table used to store the output of the EXPLAIN PLAN statement must have the same column names and datatypes as the PLAN_TABLE: CREATE TABLE plan_table (statement_id VARCHAR2(30), timestamp DATE, remarks VARCHAR2(80), operation VARCHAR2(30), options VARCHAR2(30), object_node VARCHAR2(128), object_owner VARCHAR2(30), object_name VARCHAR2(30), object_instance NUMERIC, object_type VARCHAR2(30), optimizer VARCHAR2(255), search_columns NUMERIC, id NUMERIC, parent_id NUMERIC, position NUMERIC, cost NUMERIC, cardinality NUMERIC, bytes NUMERIC, other_tag VARCHAR2(255) other LONG); To issue an EXPLAIN PLAN statement, you must have the privileges necessary to insert rows into an existing output table that you specify to hold the execution plan. To examine the execution plan produced by an EXPLAIN PLAN statement, you must have the privileges necessary to query the output table. EXPLAIN PLAN SET STATEMENT_ID (optional) INTO TABLE_NAME FOR YOUR- SQL-STATEMENT; If you omit the INTO TABLE_NAME clause, Oracle fills a table named PLAN_TABLE by default.

Keywords and Parameters :

SET STATEMENT_ID : Specifies the value of the STATEMENT_ID column for the rows of the execution plan in the output table. You can then use this value to identify these rows among others in the output table. Be sure to specify a STATEMENT_ID value if your output table contains rows from many execution plans. If you omit this clause, the STATEMENT_ID value defaults to null.

INTO : Specifies name of the output table, and optionally its schema and database. This table must exist before you use the EXPLAIN PLAN statement.

FOR statement : Specifies a SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, or CREATE INDEX statement for which the execution plan is generated. Note: If statement includes the parallel_clause, the resulting execution plan will indicate parallel execution. However, EXPLAIN PLAN actually inserts the statement into the plan table, so that the parallel DML statement you submit is no longer the first DML statement in the transaction. This violates the Oracle restriction of one parallel DML statement per transaction, and the statement will be executed serially. To maintain parallel execution of the statements, you must commit or roll back the EXPLAIN PLAN statement, and then submit the parallel DML statement.

The EXPLAIN PLAN statement is a data manipulation language (DML) statement, rather than a data definition language (DDL) statement. Therefore, Oracle does not implicitly commit the changes made by an EXPLAIN PLAN statement. If you want to keep the rows generated by an EXPLAIN PLAN statement in the output table, you must commit the transaction containing the statement. The Plan Table: The plan table is the table that Oracle fills when you issue an execution plan for an SQL statement. You must make sure such a plan table exists. Oracle ships with the script UTLXPLAN.SQL which creates this table, named PLAN_TABLE (which is the default name used by EXPLAIN PLAN.You can also choose any other name for the plan table, as long as you have been granted insert on it and its table structure should be similar to Plan Table.

The PLAN_TABLE used by the EXPLAIN PLAN statement contains the following columns: PLAN_TABLE Columns :

STATEMENT_ID : The value of the optional STATEMENT_ID parameter specified in the EXPLAIN PLAN statement.

TIMESTAMP : The date and time when the EXPLAIN PLAN statement was issued.

REMARKS : Any comment (of up to 80 bytes) you wish to associate with each step of the explained plan. If you need to add or change a remark on any row of the PLAN_TABLE, use the UPDATE statement to modify the rows of the PLAN_TABLE.

OPERATION : The name of the internal operation performed in this step. In the first row generated for a statement, the column contains one of the following values: DELETE STATEMENT ,INSERT STATEMENT ,SELECT STATEMENT ,UPDATE STATEMENT .

OPTIONS : A variation on the operation described in the OPERATION column.

OBJECT_NODE : The name of the database link used to reference the object (a table name or view name). For local queries using parallel execution, this column describes the order in which output from operations is consumed.

OBJECT_OWNER : The name of the user who owns the schema containing the table or index.

OBJECT_NAME : The name of the table or index.

OBJECT_INSTANCE : A number corresponding to the ordinal position of the object as it appears in the original statement. The numbering proceeds from left to right, outer to inner with respect to the original statement text. View expansion will result in unpredictable numbers.

OBJECT_TYPE : A modifier that provides descriptive information about the object; for example, NON-UNIQUE for indexes.

OPTIMIZER : The current mode of the optimizer.

SEARCH_COLUMNS : Not currently used.

ID : A number assigned to each step in the execution plan.

PARENT_ID : The ID of the next execution step that operates on the output of the ID step.

POSITION : The order of processing for steps that all have the same PARENT_ID.

OTHER : Other information that is specific to the execution step that a user may find useful.

OTHER_TAG : Describes the contents of the OTHER column

DISTRIBUTION : Stores the method used to distribute rows from "producer" query servers to "consumer" query servers.

Pstart : The start partition of a range of accessed partitions. It can take one of the following values: n indicates that the start partition has been identified by the SQL compiler and its partition number is given by n. KEY indicates that the start partition will be identified at execution time from partitioning key values. ROW LOCATION indicates that the start partition (same as the stop partition) will be computed at execution time from the location of each record being retrieved. The record location is obtained by a user or from a global index. INVALID indicates that the range of accessed partitions is empty.

Pstop : The stop partition of a range of accessed partitions. It can take one of the following values: n indicates that the stop partition has been identified by the SQL compiler and its partition number is given by n. KEY indicates that the stop partition will be identified at execution time from partitioning key values. ROW LOCATION indicates that the stop partition (same as the start partition) will be computed at execution time from the location of each record being retrieved. The record location is obtained by a user or from a global index. INVALID indicates that the range of accessed partitions is empty.

PID : The step that has computed the pair of values of the Pstart and Pstop columns.

COST : The cost of the operation as estimated by the optimizer's cost-based approach. For statements that use the rule-based approach, this column is null. Cost is not determined for table access operations. The value of this column does not have any particular unit of measurement, it is merely a weighted value used to compare costs of execution plans.

CARDINALITY : The estimate by the cost-based approach of the number of rows accessed by the operation.

BYTES : The estimate by the cost-based approach of the number of bytes accessed by the operation.

Examples

Using the EXPLAIN PLAN Statement:

The following example shows a SQL statement and its corresponding execution plan generated by EXPLAIN PLAN. The sample query retrieves names and related information for employees whose salary is not within any range of the SALGRADE table:

SELECT ename, job, sal, dname FROM emp, dept WHERE emp.deptno = dept.deptno AND NOT EXISTS (SELECT * FROM salgrade WHERE emp.sal BETWEEN lowsal AND highsal);

This EXPLAIN PLAN statement generates an execution plan and places the output in PLAN_TABLE:

EXPLAIN PLAN SET STATEMENT_ID = 'Emp_Sal' FOR SELECT ename, job, sal, dname FROM emp, dept WHERE emp.deptno = dept.deptno AND NOT EXISTS (SELECT * FROM salgrade WHERE emp.sal BETWEEN losal AND hisal);

Selecting PLAN_TABLE Output in Table Format

This SELECT statement:

SELECT operation, options, object_name, id, parent_id, position, cost, cardinality, other_tag, optimizer FROM plan_table WHERE statement_id = 'Emp_Sal' ORDER BY id;

Generates this output:

OPERATION OPTIONS OBJECT_NAME ID PARENT_ID POSITION COST CARDINALITY BYTES OTHER_TAG OPTIMIZER

----------------------------------------------------------------------------------------------- SELECT STATEMENT 0 2 2 1 62

CHOOSE

FILTER 1 0 1

NESTED LOOPS 2 1 1 2 1 62

TABLE ACCESS FULL EMP 3 2 1 1 1 40

ANALYZED TABLE ACCESS FULL DEPT 4 2 2 4 88 ANALYZED TABLE ACCESS FULL SALGRADE 5 1 2 1 1 13 ANALYZED

Thursday

Data Stage Enterprise Edition Server Routines

Routine to Read no of records in a file: ---------------------------------------- Parameters to be passed are Arg1(path),Arg2(file name) Code: ---- vParamFile = Arg1 : "/" : Arg2 vCountVal = 0 OpenSeq vParamFile To FileVar Else Call DSLogWarn("Cannot open ":vParamFile , "Cannot Open ParamFile") End Loop ReadSeq Dummy From FileVar Else Exit ;* at end-of-file vCountVal = vCountVal + 1 Repeat CloseSeq FileVar Ans=vCountVal Return (vCountVal) To send mail: ----------------- Four parameters are to be passed for this routine: Message,Subject,Sendto(Mail id),From (lan id) command = "echo ":Message:" | mail -s ":Subject:" ":SendTo:",":From Call DSExecute("UNIX",command, output, returncode) Ans = returncode To rename the files with timestamp and move files from one directory to another: ----------------------------------------------------------------- $INCLUDE DSINCLUDE JOBCONTROL.H Call DSExecute("UNIX",'mv /path1/path2/filename.txt /newpath/newpath1/filename_`date +"%Y%m%d%H%M%S"`.txt ', Output, SystemReturnCode) if SystemReturnCode <> 0 Then Call DSLogFatal("Unix Command Error", "JobControl") Abort End Else ErrorCode = 0 To connect to db2 database from routine: --------------------------------------- $INCLUDE DSINCLUDE JOBCONTROL.H Call DSExecute("UNIX",'. /export/home/db2inst8/sqllib/db2profile', Output, SystemReturnCode) Call DSExecute("UNIX",'db2 "connect to db2 DSNNAME user USERNAME using PASSWORD"', Output, SystemReturnCode) If SystemReturnCode <> 0 Then Call DSLogFatal("Unix Command Error", "JobControl") Abort End Else ErrorCode = 0 To get record count from a table: --------------------------------------- PgmName = "CountfromTable" * Set default to empty string Ans = "" T_NAME = Oconv(TableName,"ABC") If Len(Trim(T_NAME)) = 0 Then Message = "No Table name supplied... Abort" Call DSLogFatal(Message,PgmName) ErrorCode = @TRUE Goto TheEnd End Continue: * Format SQL to select count(*) from table Ans = "SELECT COUNT(*) FROM schemaname.":Trim(T_NAME) Return = Ans To find a file in a path1 and moving the file to path2 : ------------------------------------------------------------ $INCLUDE DSINCLUDE JOBCONTROL.H Call DSExecute("UNIX",'find /path/path1/':Arg1, Output, SystemReturnCode) if SystemReturnCode <> 0 Then Call DSLogInfo("No Files found for Rename","JobControl") End Else Call DSExecute("UNIX",'mv /path/path1/':Arg1:' /path/path2/':Arg1, Output,SystemReturnCode) if SystemReturnCode <> 0 Then Call DSLogFatal("Unix Command Error","Output is " : Output, "JobControl") Abort End End ErrorCode = 0 Ans = 0

Monday

Oracle certification Questions and Answers

QUESTION NO: 1 You need to create a report to display the ship date and order totals of your ordid table. If the order has not been shipped your report must display not shipped. If the total is not available your report must say not available. In the ordid table the ship date column has a data type of date the total column has a data type of number. Which statement do you use to create this report? A. Select ordid, shipdate “Not shipped”, total “Not available” FROM order; B. Select ordid, NVL (shipdate ‘Not shipped’), NVL (total, “Not available”) FROM order; C. Select ordid, NVL (TO_CHAR (shipdate), ‘Not shipped’), NVL (TO_CHAR (total), ‘Not available’) FROM order; D. Select ordid, TO_CHAR (shipdate, ‘Not shipped’) TO_CHAR (total, ‘Not available’) FROM order; Guaranteed stuff for all IT certification exams: mail at certking@certificationking.net Answer: C Explanation: Answer C shows correct syntax of command NVL Incorrect Answers: A: This command will show ALL data with name substitution of columns shipdate and total. B: Incorrect usage for NVL command, because shipdate and total are needed to be converted into VARCHAR2 type with TO_CHAR function. Both parameters of NVL command have to have the same data type. D: Incorrect syntax. TO_CHAR command is used just to convert data type into VARCHAR2 data type, it have nothing to do with NULL values in columns. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 10-11 Chapter 1: Selecting Data from Oracle QUESTION NO: 2 You want of display the details or all employees whose last names is Smith. But you are not sure in which case last names are stored. Which statement will list all the employees whose last name is Smith? A. Select last name, first name. FROM emp 4 WHERE last name= ‘smith’; B. Select last name, first name. FROM emp WHERE UPPER (last name)= ‘smith’; C. Select last name, first name. FROM emp WHERE last name=UPPER (‘smith’); D. Select last name, first name. FROM emp WHERE LOWER (last name)= ‘smith’; Answer: D Explanation: Select last name, first name. FROM emp WHERE LOWER (last name)= ‘smith’ Answer D shows all records with last name Smith because function LOWER returns the column value passed as x into all lowercase Incorrect Answers: A: This command will show only records with last name ‘smith’. B: Command UPPER converts all data in last_name column into uppercase. C: This command will show only records with last name ‘SMITH’. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 22 Chapter 1: Selecting Data from Oracle QUESTION NO: 3 You need to analyze how long your orders to be shipped from the date that the order is placed. To do this you must create a report that displays the customer number, date order, date shipped and the number of months in whole numbers from the time the order is placed to the time the order is shipped. Which statement produces the required results? A. SELECT custid, orderate, shipdate, ROUND(MONTHS_BETWEEN(shipdate,orderate)) “Time Taken” FROM ord; B. SELECT custid, orderate, shipdate, ROUND(DAYS_BETWEEN(shipdate,orderate))/30. FROM ord; C. SELECT custid, orderate, shipdate, 5 ROUND OFF (shipdate-orderate) “Time Taken” FROM ord; D. SELECT custid, orderate, shipdate, MONTHS_BETWEEN (shipdate,orderate) “Time Taken”. FROM ord; Answer: A Explanation: Answer A shows the number of months (rounded to integer) between the date of order and the date of shipment. Incorrect Answers: B: Function, function DAYS_BETWEEN shows number of days between shipping date and order date. C: Incorrect function ROUND OFF. D: This command will show not rounded to integer value, like 8.6451613. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 30 Chapter 1: Selecting Data from Oracle QUESTION NO: 4 The employee table contains these columns: Last_name Varchar2 (25) First_name Varchar2 (25) Salary Number7, 2 You need to display the names of employees on more than an average salary of all employees. Evaluate the SQL statement. SELECT, LAST_NAME, FIRST_NAME from employee where salary< avg(salary); Which change should you make to achieve the desired results? A. Change the function in the Where clause. B. Move the function to the select clause and add a group clause. C. Use a sub query in the where clause to compare the average salary value. D. Move the function to the select clause and add a group by clause and a having clause. Answer: C Explanation: Answer C shows the correct way to change query, because function AVG can not be used in WHERE clause. 6 Incorrect Answers: A: Usage of function AVG is correct B: This query does not require grouping to extract correct information from the table. D: This query does not require to use GROUP BY and HAVING clauses to extract correct information from table Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 57 Chapter 2: Advanced Data Selection in Oracle QUESTION NO: 5 The employee table contains these columns: FIRST-NAME VARCHER2(25) COMISSION NUMBER(3,2) Evaluate this SQL statement SELECT first-name,commission FROM employee WHERE commission= (SELECTcomission FROM employee WHERE UPPER(first-name)= ‘scott’) Which statement will cause this statement to fail? A. Scott has a null commission resolution. B. Scott has a zero commission resolution. C. There is no employee with the first name Scott. D. The first name values in the data base are in the lower case. Answer: A Explanation: Answer A is correct because if Scott has a null commission expression in WHERE clause will cause error. Incorrect Answers: B: Query will work correctly. C: Query will work even without employee with the first name Scott. D: Name values will be converted to upper case by function UPPER, query will work, but for correct result you need to change UPPER to LOWER function. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 64 Chapter 2: Advanced Data Selection in Oracle 7 QUESTION NO: 6 You create the sales table with this command CREATE TABLE sale. (purchase-no NUMBER(9) CONSTRAINT sale-purchase-no-pk PRIMARY KEY, costumer-id NUMBER(9) CONSTRAINT sale-customer-id-nk NOT NULL); Which index or indexes are created for this table? A. No indexes are created for this table. B. An index is created for purchase_no column. C. An index is created for the customer_no column. D. An index is created for each column. Answer: B Explanation: Answer B is correct because index will be created for PRIMARY KEY column automatically during table creation. Also index is created for UNIQUE constraint, but this table creation statement does not include any UNIQUE constraint. Incorrect Answers: A: A system index will be created for PRIMARY KEY column. C: An index will not be created for customer_no column. D: Indexes will not be created for EACH column. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 110 Chapter 3: Creating Oracle Database Objects QUESTION NO: 7 How would you add a foreign key constraint on the dept_no column in the EMP table. Referring to the ID column in the DEPT table? A. Use the ALTER TABLE command with the ADD clause in the DEPT table. B. Use the ALTER TABLE command with the ADD clause on the EMP table. C. Use the ALTER TABLE command with the MODIFY clause on the DEPT table. D. Use the ALTER TABLE command with the MODIFY clause on the EMP table. E. This task cannot be accomplished. Answer: B 8 Explanation: Answer B is correct because constraint will be created for EMP table using ALTER TABLE command. Incorrect Answers: A: Foreign key constraint will not be created for DEPT table, only for EMP table. DEPT table needs to have PRIMARY KEY for successful creation foreign key for EMP table. C: Foreign key constraint will not be created for DEPT table and MODIFY clause is used for different purposes. D: MODIFY clause of ALTER TABLE command is used for different purposes. E: It’s possible to add foreign constraint after table creation. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 143 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 8 Examine the structure of student table: Name Null Type STU ID NOT NULL NUMBER(3) NAME VARCHER2(25) ADDRESS VARCHER2(50) GRADUATION DATE Currently the table is empty. You have decided that null values should not be allowed for the NAME column. Which statement restricts NULL values from being entered into column? A. ALTER TABLE student ADD CONSTRAINT name(NOT NULL); B. ALTER TABLE student ADD CONSTRAINT NOT NULL (name); C. ALTER TABLE student MODIFY CONSTRAINT name(NOT NULL); D. ALTER TABLE student MODIFY(name varcher2(25) NOT NULL); Answer: D Explanation: Answer D is correct because this query add NOT NULL constraint to Student table Incorrect Answers: A: Incorrect ADD CONSTRAINT clause in ALTER TABLE command. B: Incorrect ADD CONSTRAINT clause in ALTER TABLE command. C: Incorrect syntax using MODIFY clause of ALTER TABLE command. There is no MODIFY CONSTRAINT clause in ALTER TABLE command. 9 Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 143 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 9 You have decided to permanently remove all the data from the STUDENT table and you need the table structure in the future. Which single command performs this? A. DROP TABLE student; B. TRUNCATE TABLE student; C. DELETE* FROM student; D. TRUNCATE TABLE student KEEP STRUCTURE; E. DELETE* FROM student KEEP STRUCTURE. Answer: B Explanation: Answer B is correct because after truncating table you delete all data and keep table and its structure for future use. Also command TRUNCATE reset highwatermark level to zero for table. Incorrect Answers: A: This DDL operation will drop table and its structure without possibility to rollback this operation. C: This operation can be used to perform question task, but it works slowly and usually used when you need to delete NOT ALL table rows. It does not reset high water mark for table. D: Incorrect clause KEEP STRUCTURE inside TRUNCATE TABLE command. E: Incorrect clause KEEP STRUCTURE inside DELETE command. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 151 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 10 Examine this block of code: SET OUTPUT ON Declare X NUMBER; V_SAL NUMBER; V_found VARCHAR2(10):=’TRUE’; Begin X:=1; V_sal := 1000; 10 Declare V_found VARCHAR2(10); Y NUMBER Begin IF (V_Sal>500) THEN V_found := ’YES’; END IF; DBMS_OUTPUT.PUT_LINE(‘Value of V_found is ‘|| V_Sal); DBMS_OUTPUT.PUT_LINE(‘Value of V_Sal is ‘|| TO_CHAR (V_Sal)); Y:=20; END; DBMS_OUTPUT.PUT_LINE(‘Value of V_found is’ || V_found); DBMS_OUTPUT.PUT_LINE(‘Value of Y is’ || TO_CHAR(Y)); END; SET server OUTPUT if What is the result of executing this block of code? A. PLS-00201: identifier ‘Y’ must be declared. B. Value of V_found is YES Value of V_sal is 1000 Value of V_found is TRUE C. Value of V_found is YES Value of V_found is 1000 Value of V_found is TRUE Value of Y is 20 D. PLS-00201: identifier ‘V_sal’ must be declared PLS-00201: identifier ‘Y’ must be declared E. Value of V_found is YES Value of V_sal is 1000 Value of V_found is TRUE Value of Y is 20 Answer: A Explanation: Answer A is correct because PL/SQL variable ‘Y’ is not declared in DECLARE section of PL/SQL block, but only inside BEGIN … END block and executing of this block will return error. Incorrect Answers: B: This code does work because of V_found and V_sal are identified. C: This code does work because of V_found and V_sal are identified. D: Identifier V_sal is declared, so code will fail because of identifier ‘Y’, not V_sal, must be declared. E: This code does work because of all variables are declared and populated with values. 11 Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 209 Chapter 5: Introducing PL/SQL QUESTION NO: 11 You need to store currency data and you know that data will always have two digits to the right of the decimal points. However the number of digits to the left of the decimal place will vary greatly. Which data type would be most appropriate to store the data? A. NUMBER B. NUMBER(T) C. LANG D. LANGRA Answer: A Explanation: Answer A is correct because by default NUMBER is NUMBER(L, P) type, which is always stored as variable-length data, where 1 byte is used to store the exponent, 1 byte is used to store for every two significant digits of the number’s mantissa, and 1 byte is used for negative numbers if the number of significant digits is less than 38 bytes. Incorrect Answers: B: NUMBER(T) type will not allow to keep more than T numbers of digits to the left of the decimal place, but question says that it will vary greatly. C: There is no type LANG in Oracle 8i. D: Type LANGRA does not exists too. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 390 Chapter 8: Managing Database objects I QUESTION NO: 12 Examine the structure of STUDENT table. NAME NULL TYPE STUDENT ID NOT NULL NUMBER(3) NAME NOT NULL VARCHAR2(25) PHONE NOT NULL VARCHAR2(9) ADDRESS VARCHAR2(50) GRADUATION DATE 12 There are hundred records in the student table. You need to modify the Phone column to hold only numeric value. Which statement will modify the data type of the Phone column? A. ALTER TABLE student MODIFY phone NUMBER(9) B. ALTER STUDENT table MODIFY COLUMN phone NUMBER(9); C. You can not modify a VARCHAR2 data type to a NUMBER data type for a D. Column. E. You cannot modify the data type of a column if there is data in the column. Answer: E Explanation: Answer E is correct because Phone column in STUDENT table has NOT NULL constraint, which does not allows to modify data type of a column if there is data in the column. Incorrect Answers: A: The statement will fail because it is incorrect way to change data type for column with NOT NULL constraint on it. B: There is a wrong syntax ‘ALTER STUDENT table’ and ‘MODIFY COLUMN’ in the statement. C: It is possible to modify VARCHAR2 data type to NUMBER data type (with some restrictions). D: Does not exists in question Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 141-142 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 13 You need to update employee salaries if the salary of an employee is less than 1000. The salary needs to be incremented by 10%. Use SQL*Plus substitution variable to accept the employee number. Which PL/SQL block successfully updates the salaries? A. Declare V_sal emp.sal % TYPE; Begin SELECT Sal INTO V_sal FROM emp WHERE empno = and P_empno; IF (V_Sal<1000) THEN UPDATE emp INTO Sal := Sal*1.1 WHERE empno = and p_empno; 13 END IF; END; B. Declare V_sal emp.sal % TYPE; Begin SELECT Sal INTO V_sal FROM emp WHERE empno = and P_empno; IF (V_Sal<1000) THEN SAL := SAL * 1.1; END IF; END; C. Declare V_sal emp.sal % TYPE; Begin SELECT Sal INTO V_sal FROM emp WHERE empno = and P_empno; IF (V_Sal<1000) THEN UPDATE emp Sal := Sal*1.1 WHERE empno = and p_empno; END IF; END; D. Declare V_sal emp.sal % TYPE; Begin SELECT Sal INTO V_sal FROM emp WHERE empno = and P_empno; IF (V_Sal<1000) THEN UPDATE emp Set Sal := Sal*1.1 WHERE empno = and p_empno; END IF; END; Answer: D Explanation: Answer D is correct because it’s uses cursor and IF-THEN structure correctly to increase salary for all employees with current salary less than 1000. 14 Incorrect Answers: A: UPDATE INTO is wrong construction for UPDATE command B: There is no SAL variable defined in PL/SQL block, so SAL:=SAL*1.1 will fail and it’s wrong way to change value of column Sal in table EMP. C: Sal:=Sal*1.1 can not be inside UPDATE … WHERE command. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 215-217 Chapter 8: Introducing PL/SQL QUESTION NO: 14 The employee table contains these columns. LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) DEPT_ID NUMBER(9) You need to display the names of the employees that are not assigned to the department. Evaluate this SQL statement. SELECT last_name, first_name FROM employee WHERE dept_id is NULL Which change should you make to achieve the desired result? A. Create an outer join. B. Change the column in the where condition. C. Change the operator in the where condition D. Add a second condition to the where condition Answer: C Explanation: Answer C is correct because the NULL operator need to be changed in the WHERE condition to display correct result. Incorrect Answers: A: One table is used for query, so there is no reason to use outer join operation. B: The column in the WHERE condition is correct and don’t need to be changed. D: Query does not require additional condition to extract correct data. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 10-11 Chapter 1: Selecting data from Oracle QUESTION NO: 15 Which statement about SQL is true? 15 A. Null values are displayed last in the ascending sequences. B. Data values are displayed in descending order by default. C. You cannot specify a column alias in an ORDER BY clause. D. You cannot sort query results by a column that is not included in the SELECT list. E. The results are sorted by the first column in the SELECT list, if the ORDER BY clause is not provided. Answer: A Explanation: Answer A is correct because of null values are displayed last in the ascending sequences. Incorrect Answers: B: Data values are displayed in ASCENDING order by default. C: It is possible to specify a column alias in an ORDER BY clause (but not in a GROUP BY clause). D: You can sort query results by a column that is not included in the SELECT list. E: The results will not be sorted at all, if the ORDER BY clause was not used in query. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 18-19 Chapter 8: Selecting Data from Oracle QUESTION NO: 16 Written a PL/SQL loop, you need to test if the current FETCH was successful. Which SQL cursor attribute would you use to accomplish this task? A. SQL % ISOPEN B. SQL % ROWCOUNT C. SQL % FOUND D. This task cannot be accomplished with a SQL cursor attribute. E. A SQL cursor attribute cannot be used within a PL/SQL loop. Answer: C Explanation: Answer C is correct because of SQL%FOUND attribute returns TRUE if current FETCH have been successful. Incorrect Answers: A: SQL%ISOPEN attribute returns TRUE if cursor is OPEN and ready for use. B: SQL%ROWCOUNT returns the number of rows that were processed by the statement. D: This task can be successfully accomplished with a SQL%FOUND cursor attribute. 16 E: PL/SQL loop can contain a SQL cursor attribute. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 222-224 Chapter 5: Introducing PL/SQL QUESTION NO: 17 The structure of the DEPT table is as follows: NAME NULL TYPE Deptno Not Null NUMBER(2) Dname VARCHAR2(14) Loc VARCHAR2(13) Examine the code Declare Type dept_record_type is record (dno NUMBER, name VARCHAR2(20)); dept_rec dept_record; Begin Select deptno, dname INTO dept_rec FROM dept WHERE deptno=10; END Which statement displays the name of selected department? A. DBMS_OUTPUT.PUT_LINE (name); B. DBMS_OUTPUT.PUT_LINE (dname); C. DBMS_OUTPUT.PUT_LINE (dept_rec.name); D. DBMS_OUTPUT.PUT_LINE (dept_rec.dname); E. DBMS_OUTPUT.PUT_LINE (dept_rec (name)); Answer: C Explanation: Answer C is correct because it shows field NAME for record DEPT_REC of DEPT_RECORD type. Incorrect Answers: A: Statement does not specify that NAME is field of DEPT_REC record. B: DNAME is name of column in DEPT table and cannot be used this way to show data. D: There is not field DNAME in record DEPT_REC. E: This statement just has wrong syntax of function PUT_LINE in DBMS_OUTPUT package to represent data. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 211-213 17 Chapter 5: Introducing PL/SQL QUESTION NO: 18 Which privilege concerns with system level security? A. Drop any table. B. DELETE C. ALTER D. INDEX E. UPDATE Answer: A Explanation: Answer A is correct because of only DROP ANY TABLE privilege from all choices belongs to SYSTEM level security, all others – not. Incorrect Answers: B: DELETE is object privilege. Permits the grantee of this object privilege to delete data from a table or view. C: ALTER is object privilege. Permits the grantee of this object privilege to alter the definition of a table or sequence only. The ALTER privileges on all other database objects are considered system privileges. D: INDEX is object privilege. Permits the grantee of this object privilege to create an index on a table already defined. E: UPDATE is object privilege. Permits the grantee of this object privilege to update data into a table or view. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 485 Chapter 10: Managing Database Use QUESTION NO: 19 Evaluate the SQL statement. CREATE ROLE manager; CREATE ROLE clerk; CREATE ROLE inventory; CREATE USER scott IDENTIFIED BY tiger; GRANT inventory TO clerk; GRANT clerk TO manager; GRANT inventory TO scott; / 18 How many roles will user scott have access to? A. 0 B. 1 C. 2 D. 3 Answer: B Explanation: Answer B is correct because of only INVENTORY role will be granted to user SCOTT. Incorrect Answers: A: One role (INVENTORY) is granted to user SCOTT, not zero. C: This choice would be correct if role CLERK would be granted to SCOTT because this role includes INVENTORY role. D: This choice would be correct if role MANAGER would be granted to SCOTT because this role includes INVENTORY and CLERK roles. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 490-494 Chapter 10: Managing Database Use QUESTION NO: 20 Scott forgot his password while on location. Which command must be executed to set a password for scott? A. Scott must execute the command. ALTER USER scott PASSOWRD BY lion B. The DBA must execute the command. ALTER USER scott IDENTIFIED BY lion C. Scott must execute the command ALTER USER scott IDENTIFIED BY lion D. The scott must execute the command CHANGE password to lion WHERE “user=scott”; E. The DBA must execute the command CHANGE password to lion WHERE “user=scott”; Answer: B Explanation: Answer B is correct because of only DBA (not user himself) can change password for account if user forgot his password. Incorrect Answers: A: Clause ‘PASSWORD BY’ is wrong for ‘ALTER USER’ command. 19 C: User needs to be connected to change his password, but he cannot connect if he forgot password. D: Command CHANGE is incorrect to change password and user cannot connect himself to change password because he forgot it. E: Command CHANGE is incorrect to change password. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 182 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 21 You are updating the employee table. Jane has been granted the same privileges as you on the employee table. You ask Jane to logon to the database to check your world before you issue the commit command. What can Jane do to the employee table? A. Jane can access the table and verify your changes. B. Jane cannot access the table. C. Jane can access the table but she cannot see your changes, she can make the changes for you. D. Jane can access the table but she cannot see your changes and cannot make the changes to the roles that you are changing. Answer: D Explanation: Answer D is correct because before you committed changes in the employee table nobody can see changed data. Incorrect Answers: A: Jane can access table but she cannot verify changes because she does not see them before you commit data changes. B: Jane can access table because she has been granted the same privileges as you on the employee table. C: Jane cannot commit herself changes you did to the data. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 484-485 Chapter 10: Managing Database Use QUESTION NO: 22 Examine the structure of STUDENT table. Name Null? Type. 20 STUD-ID NOT NULL NUMBER(3) NAME NOT NULL VARCHER2(25) ADDRESS VARCHER2(50) GRADUATION DATE. Which statement inserts a new row into the STUDENT table? A. INSERT INTO student. VALUES(101, ‘Smith’); B. INSERT INTO student. VALUES(101, ‘100 Main Street’, ‘17-JUN-99’, ‘Smith’); C. INSERT INTO test. VALUES(101, ‘Smith’, ‘100 Main Street’, ‘17-JUN-99’); D. INSERT INTO student.(stud-id,address,gradulation) VALUES(101, ‘Smith’, ‘100 Main Street’, ‘17-JUN-99’); E. INSERT INTO student.(stud-id,address,name,gradulation) VALUES(101, ‘100 Main Street’,‘Smith’, ‘17-JUN-99’); Answer: E Explanation: Answer E is correct because you need to show ALL columns and in correct order for values which you try to insert into table STUDENT. Incorrect Answers: A: You need to show ALL columns for values, which you try to insert into table STUDENT. B: You need to show columns in correct order for values, which you try to insert into table STUDENT. In this statement Name is located in wrong place according table definition. C: This statement contains wrong table name TEST, not STUDENT. D: This statement shows list of only 3 columns when there are 4 values need to be inserted into table row. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 120-122 Chapter 4: Creating Oracle Database Objects QUESTION NO: 23 Examine the structure of the STUDENT table. NAME NULL TYPE STUDENT_ID NOT NULL NUMBER(3) NAME NOT NULL VARCHAR2(25) 21 ADDRESS VARCHAR2(50) GRADUATION DATE Graduation column is a foreign key column to the graduate table. Examine the data in the GRADE DATE table. Graduation 20-jan-1999 12-may-1999 19-jan-2000 25-may-2000 13-jan-2001 29-may-2001 Which update statement produces the following error: ORA-02291 integrity constraint(sys_c23) violated parent key not found? A. UPDATE student SET stud-id=999, graduation= ’29-MAY-2001’ WHERE stud-id=101;’ B. UPDATE student SET name= ‘Smith’, graduation= ’29-MAY-2001’ WHERE stud-id=101; C. UPDATE student SET name= ‘Smith’, graduation= ‘15-AUG-2000’ WHERE stud-id=101 D. UPDATE student SET stud-id=NULL, address= ‘100 Main Street’ WHERE graduation= ‘20-JAN-1999’ Answer: C Explanation: Answer C is correct because there is no ’15-AUG-2000’ value in the graduate table. Foreign constraint for this statement will be violated because parent key not found. Incorrect Answers: A: There is ’29-MAY-2001’ in the graduate table and foreign constraint will not be violated. B: There is ’29-MAY-2001’ in the graduate table and foreign constraint will not be violated. D: There is ’20-JUN-1999’ in the graduate table and foreign constraint will not be violated. 22 Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 428-433 Chapter 9: Managing Database Objects II QUESTION NO: 24 In SQL Plus You issued this command: Delete from dept where dept_id=901 You received an integrated constraint error because the child record was found. What could you do to make the statement execute? A. Delete the child record first. B. You cannot make the command execute. C. Add a fourth keyword to the command. D. Add the constraints cascade option to the command. Answer: A Explanation: Answer A is correct because you need first delete the child record in dependable table for avoid foreign constraint violation. Incorrect Answers: B: You can execute the command if you don’t have child records in other tables for record you need to delete in the parent table DEPT. C: Adding an additional keyword will not help because foreign constraint will be violated. D: CASCADE CONSTRAINTS option works only for DROP TABLE command, not for DELETE. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 398-399 Chapter 8: Managing Database Objects I QUESTION NO: 25 The view EMP-VIEW is created based on the EMP table as follows. CREATE OF REPLACE VIEW emp-view AS SELECT deptno,SUM(sal)TOT_SAL,COUNT(*)NOT-EMP FROM emp GROUP BY deptno; What happens when the command is used? 23 UPDATE emp-view SET tot-sal=20000 WHERE deptno=10; A. The base table cannot be updated through this view. B. The TOT_SAL column in the EMP table is updated to 20,000 for department 10. C. The TOT_SAL column in the EMP view is updated to 20,000 for department10. D. The SAL column in the EMP table is updated to 20,000 for employees in department 10. Answer: A Explanation: Answer A is correct because the user may not INSERT, DELETE, or UPDATE data on the table underlying the sample view if the SELECT statement creating the view contains GROUP BY, or a single-row operation. Incorrect Answers: B: TOT_SAL column in the EMP table will not be updated. C: TOT_SAL column in the EMP table will not be updated for any rows. D: UPDATE command does not contain SAL column for update. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 164 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 26 You have a view card ANN_SAL that is based on the employee table. The structure of the ANN_SAL view is: NAME NULL TYPE EMPNO NOT NULL NUMBER(4) YEARLY_SAL NUMBER(9,2) MONTHLY_SAL NUMBER(9,2) Which statement retrieves the data from the ANN_SAL view? A. SELECT * FROM ANN_SAL B. SELECT * FROM EMPLOYEE C. SELECT * FROM VIEW ANN_SAL D. SELECT * FROM VIEW ANN_SAL IS DON EMPLOYEE Answer: A 24 Explanation: Answer A is correct because correct syntax for SELECT command for view is SELECT * FROM Incorrect Answers: B: This statement will show data from table EMPLOYEE, not view ANN_SAL. C: It’s an incorrect statement because of usage word ‘VIEW’. D: It’s an incorrect statement because of usage words ‘VIEW’ and ‘IS DON EMPLOYEE’. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 160-169 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 27 Evaluate this IF statement. IF v_value>100 THEN v_new-value:=2*v-value; ELSIF v-value>200 THEN v-new-value:=3*v-value; ELSIF v-value>300 THEN v-new-value:=4*v-value; ELSE v-new-value:=5*v-value; END IF What would be assigned to v_new_value if v_value=250? A. 250 B. 500 C. 750 D. 1000 Answer: B Explanation: Answer B is correct because first IF condition v_value > 100 will be TRUE if v_value have been assigned with new value equal 250. Result of 2*v_value is 500. Incorrect Answers: A: All IF conditions multiple 250 on 2, 3, 4 or 5, so result cannot be 250. C: First IF condition will work not second one, so result will be 500, not 750. 25 D: First IF condition will work not second or third one, so result will be 500, not 750 or 1000. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 215-217 Chapter 5: Introducing PL/SQL QUESTION NO: 28 The PLAYER table contains these columns id number(9) name varchar(2) manager_id number(9) In this instance, managers are players with you need to display a list of players. Evaluate these TWO SQL statements: SELECT p.name,m.name FROM player p,player m WHERE m.id= m.manager_id; SELECT p.name,m.name FROM player p,player m WHERE m.manager_id=p.id; How would the results differ? A. Statement1 will not execute, statement2 will. B. Statement1 will execute, statement2 will not. C. Statement1 is self join, statement2 is not. D. The results will be same but the display will be different. Answer: D Explanation: Answer D is correct because the results of these queries will be same, just will look different. In first statement driving column is ID, in second – MANAGER_ID. Incorrect Answers: A: Both statements will be executed successfully. B: Both statements will be executed successfully. C: Both statements are self join, not only Statement1. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 55-56 Chapter 4: Advanced Data Selection in Oracle 26 QUESTION NO: 29 How would you declare a PL/SQL table of records to hold the rows selected from the EMP table? A. DECLARE emp-table is TABLE of emp%ROWTYPE. B. BEGIN TYPE emp-table is TABLE of emp%ROWTYPE emp-table emp-table-type; C. DECLARE TYPE emp-table is TABLE of emp%ROWTYPE INDEX BY WHOLE NUMBER: emp-table emp-table-type; D. DECLARE TYPE emp-table is TABLE of emp%ROWTYPE INDEX BY BINARY INTEGRATDE. emp-table emp-table-type; Answer: D Explanation: Answer D is correct because INDEX BY BINARY INTEGRATED clause need to be set for TABLE type. Incorrect Answers: A: INDEX BY clause is not used in definition statement of PL/SQL block. B: INDEX BY clause is not used in definition statement of PL/SQL block. C: INDEX BY clause uses WHOLE NUMBER option, which is incorrect for TABLE type definition. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 392 Chapter 8: Managing Database Objects I QUESTION NO: 30 You want to create a cursor that can be used several times in a block. Selecting a different active set each time that it is opened. Which type of cursor do you create? A. A cursor for loop. B. A multiple selection cursor. C. A cursor for each active set. 27 D. A cursor that uses parameters. Answer: D Explanation: Answer D is correct because a cursor with parameters can be used several times in a block, selecting active set each time that it was opened depending on parameters’ values. Incorrect Answers: A: A cursor for loop used for different purpose. B: A multiple selection cursor does not exist. C: A cursor for each active set does not allow to use the same cursor several times in a block. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 231-233 Chapter 5: Introducing PL/SQL QUESTION NO: 31 Which statement is true when writing a cursor for loop? A. You must explicitly fetch the rows within a cursor for loop. B. You must explicitly open the cursor prior to the cursor for loop. C. You must explicitly close the cursor prior to the end of program. D. You do not explicitly open, fetch or close a cursor within a cursor for loop. E. You must explicitly declare the record variable that holds the row returned from the cursor. Answer: D Explanation: Answer B is correct because when using a cursor for loop you don’t need explicitly open, fetch or close a cursor (by definition of a cursor for loop). Incorrect Answers: A: You don’t need explicitly fetch the cursor within a cursor for loop. B: You don’t need explicitly open the cursor within a cursor for loop. C: You don’t need explicitly close the cursor within a cursor for loop. E: You don’t need to declare the record variable to hold the row from the cursor if you use a cursor for loop. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 233-234 Chapter 5: Introducing PL/SQL 28 QUESTION NO: 32 The structure of the DEPT table as: Name Null? Type DEPT NO Not NULL Number(25) DNAME VARCHER2(14) LOC VARCHER2(13) Examine the code: DECLARE Dept_rec dept%ROWTYPE: BEGIN SELECT* INTO dept_rec FROM dept. WHERE deptno=10; END; Which PL/SQL statement displays the location of selected department? A. DBMS_OUTPUT.PUT-LINE(dept_rec); B. DBMS_OUTPUT.PUT-LINE(dept_rec.loc); C. DBMS_OUTPUT.PUT-LINE(dept_rec(1).loc); D. You can’t display a single field in the record because they are not specially identified in declarative section. Answer: B Explanation: Answer B is correct because PUT_LINE function from DBMS_OUTPUT package will show LOC field from DEPT_REC record. Incorrect Answers: A: You cannot show ALL record fields using DEPT_REC. C: Syntax ‘dept_rec(1).loc’ is wrong to display the location of selected department. D: You can display a single field of record. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 211-213 Chapter 5: Introducing PL/SQL 29 QUESTION NO: 33 Which statement about implicit cursors is true? A. Implicit cursors are declared implicitly only for DML statements. B. Implicit cursors are declared implicitly for all the DML and SELECT statements. C. Programmers need to close all the implicit cursors before the end of the PL/SQL program. D. Programmers can declare implicit cursors by using the cursor type in the declaration section. Answer: B Explanation: Answer B is correct because implicit cursors are declared implicitly for all DML and SELECT statements. Incorrect Answers: A: Implicit cursors are declared implicitly not only for all DML, but for SELECT statements too. C: Programmers don’t need to close the implicit cursor, because it will be closed automatically at the end of the PL/SQL block. D: Programmers cannot declare implicit cursors, only explicit cursors. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 222-224 Chapter 5: Introducing PL/SQL QUESTION NO: 34 Evaluate this PL/SQL block: DECLARE v-result NUMBER(2); BEGIN DELETE FROM employee WHERE dep_id IN (10,20,30); v-result:= SQL%ROWCOUNT; COMMIT; END; What will be the value of v_result if no rows are deleted? A. 0 B. 1 30 C. True D. Null Answer: A Explanation: Answer A is correct because if no rows are deleted SQL%ROWCOUNT attribute of cursor will return 0 – number of deleted rows. Incorrect Answers: B: No rows are deleted so SQL%ROWCOUNT will return 0, not 1. C: SQL%ROWCOUNT attribute of cursor returns always a numeric value, not BOOLEAN. D: SQL%ROWCOUNT attribute of cursor returns always a numeric value, which cannot be a NULL. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 224 Chapter 5: Introducing PL/SQL QUESTION NO: 35 Which two conditions in a PL/SQL block cause an exception error to occur? (Choose two) A. Select statement does not return a row. B. Select statement returns more than one row. C. Select statement contains a group by clause. D. Select statement does not have where clause. E. The data type in the select list are inconsistent with the data types in the into clause. Answer: A, B Explanation: Answers A and B is correct because there are two common exceptions can cause an error : NO_DATA_FOUND, if no rows were selected or changed by the SQL operation or TOO_MANY_ROWS, if more than one row was obtained by a single-row subquery, or in another SQL statement operation where Oracle was expecting one row. Incorrect Answers: C: It will not be an exception error if SELECT statement contains a GROUP BY clause. D: It will not be an exception error if SELECT statement contains a WHERE clause. E: It will ROWTYPE_MISMATCH an exception error if the datatypes of the record to which data from the cursor is assigned are INCOMPATIBLE, but not INCONSISTENT as answer E says. 31 Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 239 Chapter 5: Introducing PL/SQL QUESTION NO: 36 You need to create a PL/SQL program to insert records into employee table. Which block of code successfully uses the insert command? A. DECLARE v_hiredate DATE:=SYSDATE: BEGIN INSERT INTO emp(empnp, ename, hiredate, deptno) VALUES(empno_sequence.nextval, ‘and name’,v_hirerdate and deptno) B. DECLARE v-hiredate DATE:=SYSDATE: BEGIN INSERT INTO emp(empnp,ename,hiredate,deptno) C. DECLARE v-hiredate DATE:=SYSDATE: BEGIN INSERT INTO emp(empnp,ename,hiredate) VALUES(empno_sequence.nextval, name, v_hirerdate) END: D. DECLARE v-hiredate DATE:=SYSDATE: BEGIN INSERT INTO emp(empnp,ename,heridate,deptno) VALUES(empno_sequence.nextval, ‘and name’,v_herdate and deptno) Job=Clerk END: Answer: C Explanation: Answer C is correct because expression EMPNO_SEQUENCE.NEXTVAL will calculate next value for EMPNP column automatically after each insert. Incorrect Answers: A: Syntax ‘v_iredate and deptno’ is incorrect in INSERT VALUES statement. B: Statement does not display VALUES which need to be inserted into table. 32 D: Using ‘Job=Clerk’ is incorrect syntax in the INSERT statement and in the PL/SQL block. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 153-160 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 37 Evaluate this PL/SQL block. BEGIN FOR i IN 1..10 LOOP IF I=4 OR I=6 THEN null; ELSE INSERT INTO test(result) VALUES (I) ; END IF; COMMIT; END LOOP; ROLL BACK; END. How many values will be inserted into the TEST table? A. 0 B. 4 C. 6 D. 8 E. 10 Answer: D Explanation: Answer D is correct because loop will be executed 10 times, but 2 times IF-THEN condition will not allow to insert 2 values into TEST table, so result is 8. Incorrect Answers: A: Loop will be executed exactly 10 times, because I will change value from 1 to 10 by LOOP-FOR definition. B: Loop will be executed exactly 10 times, not 4. C: Loop will be executed exactly 10 times, not 6. E: This answer would be correct if the condition IF-THEN have been absent inside this PL/SQL block. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 219-220 33 Chapter 5: Introducing PL/SQL QUESTION NO: 38 You issue this command: CREATE public synonym EMP for ed.employee; Which task has been accomplished? A. The object can now be accessed by all the users. B. All users were given object privileges to the table. C. The need to qualify the object name with its schema is eliminated only for you. D. The need to qualify the object name with its schema is eliminated for all users. Answer: D Explanation: Answer D is correct because the public synonym will be created for table EMPLOYEE of ED owner. After that other users will not need to use object owner prefix to access data inside this table. Incorrect Answers: A: Creation public synonym will not open access for ALL users, but will make more easy access for user, which have access to EMPLOYEE table of user ED. B: Creation public synonym for table does not provide objects privileges for ALL users to the table. C: Because of creation PUBLIC synonym for ED.EMPLOYEE need to qualify the object name with its owner name is eliminated for ALL users who have already access to this table, not only for you. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 183-185 Chapter 4: Creating Other Database Objects in Oracle QUESTION NO: 39 Which statement about multiple sub-queries is True? A. A pair wise comparison produces a cross product. B. A non-pair wise comparison produces a cross product. C. In a pair wise subquery, the values returned from the subquery are compared individually to the values in the outer query. D. In a non-pair wise subquery, the values returned from the subquery are compared as a group to the values in the outer query. 34 Answer: B Explanation: Answer B is correct because a non-pair wise comparison really produces a cross product. Incorrect Answers: A: A pair comparison does not produces a cross product because of a non-pair wise comparison does. C: In a pair wise subquery, the values returned from the subquery are compared as a GROUP, not INDIVIDUALLY to the values in the outer query. D: In a non-pair wise subquery, the values returned from the subquery are compared INDIVIDUALLY to the values in the outer query, not as a GROUP. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 64-72 Chapter 2: Advanced Data Selection QUESTION NO: 40 You attempt to query to the database with this command: SELECT dept_no,AVG(MONTHS_BETWEEN(SYSDATE,hire-data)) FROM employee WHERE AVG(MONTHS_BETWEEN(SYSDATE,hire_date))>60 GROUP BY by dept_no ORDER BY AVG(MONTHS_BETWEEN(SYSDATE,hire_date)); Why does this statement cause an error? A. A select clause cannot contain a group function. B. A where clause cannot be used to restrict groups. C. An order by clause cannot contain a group function. D. A group function cannot contain a single row function. Answer: B Explanation: Answer B is correct because function AVG cannot be used in a WHERE clause of SELECT statement. Incorrect Answers: A: SELECT clause can contain a group function. C: ORDER BY clause can contain a group function. D: A GROUP function can contain a single row function. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 57 35 Chapter 5: Advanced Data Selection in Oracle QUESTION NO: 41 The path table contains these columns: ID NUMBER(7) PK COST NUMBER(7,2) PRODUCT_ID NUMBER(7) Evaluate these SQL statements: SELECT ROUND(max(cost),2), ROUND(min(cost),2), round(sum(cost),2), ROUND(AVG(cost),2) FROM part; SELECT product_id, ROUND(max(cost),2), ROUND(min(cost),2), ROUND(sum(cost),2), ROUND(AVG(cost),2) FROM part GROUP BY product_id; How will the results differ? A. The results will be same but the display will differ. B. The statement1 will only display one row of results, statement2 can display more than one. C. Statement1 will display a result for each part, statement2 will display a result for each product. D. One of the statements will generate an error. Answer: B Explanation: Answer B is correct because Statement2 uses GROUP BY function to calculate aggregated functions for each PRODUCT_ID while Statement1 returns one row result. Incorrect Answers: A: The results will not be the same. C: Statement1 will not display a result for each part, but only one row. D: Both statements will be successfully completed without errors. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 58-64 Chapter 5: Advanced Data Selection in Oracle 36 QUESTION NO: 42 In which section of a PL/SQL block is a user defined exception waste? A. Heading B. Executable C. Declarative D. Exception handling Answer: B Explanation: Answer B is correct because in the executable section of PL/SQL block a user-defined exception waste. Incorrect Answers: A: Heading section of PL/SQL block is used for function, procedure, package naming, not for exceptions. C: Declarative section of PL/SQL block, which is optional, identifies all variables constructs that will be used in the code block. D: Exception handling section of PL/SQL block defines all errors that may occur in the block and specifies how they should be handled. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 209 Chapter 5: Introducing PL/SQL QUESTION NO: 43 Examine the code: SET SERVER OUTPUT ON DECLARE v_char_val varchar2(100); BEGIN v_char_val:= ‘Hello World’, DBMS_OUTPUT.PUT_LINE(v_char_val); END SET SERVER OUTPUT OFF This code is stored in a script file name “myproc,sql”. Which statement executes the code in the script file? A. Myproc.sql B. RUN myproc,sql 37 C. START myproc.sql D. EXECUTE myproc.sql E. BEGIN myproc.sql END; Answer: C Explanation: Answer C is correct because command START is used to execute the code in the script file. Incorrect Answers: A: This statement will not start execution of the script. C: Command RUN is not used to start the stored script. D: Command EXECUTE is used to execute function or procedure, but not a stored script E: Structure BEGIN … END represent executable section of PL/SQL block, it will not start to execute a stored script. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 16 Chapter 1: Selecting data from Oracle QUESTION NO: 44 Examine this block F code Set server output ON Declare X NUMBER; V_SAL NUMBER; V_found VARCHAR2(10) := ‘TRUE’ Begin X:=1; V_SAL :=1000; Declare V_found VARCHAR2(10); Y NUMBER; Begin IF (V_sal>500) THEN V_found := ‘YES’; END IF; DBMS_OUTPUT.PUT_LINE(‘value f V_found is’ || V_found); DBMS_OUTPUT.PUT_LINE (‘value f V_found is’ || V_found); Y:20; END DBMS_OUTPUT.PUT_LINE (‘value f V_found is’ || V_found); DBMS_OUTPUT.PUT_LINE (‘value f Y is’ || TO_CHAR (Y); END Why does this code produce an error when executed? 38 A. The value f V_found cannot be YES. B. Variable V_found is declared at more than one location. C. Variable Y is declared in the inner block and referenced in the outer block. D. Variable V_sal is declared in the outer block and referenced in the inner block. Answer: C Explanation: Answer C is correct because the usage of variable Y, which have been defined in the inner block, in the outer block (second line of code from the bottom) will cause the error. Incorrect Answers: A: V_found variable is VARCHAR2 type, so it can have value ‘YES’. B: Variable V_found is declared at more that one location, in the inner and the outer blocks, but it is correct usage of the variables in PL/SQL block. Each of it has its own scope. There is no error in this situation. D: All variables defined in the outer block can be referenced in the inner block, but not vice versa. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 213 Chapter 5: Introducing PL/SQL QUESTION NO: 45 Which statement is valid within the executable section of Pl/SQL block? A. BEGIN emp_rec emp%ROWTYPE END; B. WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT.LINE(‘No records found’); C. Select ename,sal into v_ename,v_sal from emp where empno=101; D. Procedure cal_max(n1 NUBER n2 NUMBER, p_max OUT NUMBER) IS BEGIN If n1>n2 then p_max:=n1; Else p_max=n2; END. 39 Answer: C Explanation: Answer C is correct because this statement populates variables v_ename and v_sal with data from EMP table. Syntax is correct. Incorrect Answers: A: Record cannot be defined inside the executable section of PL/SQL block, only inside the declarative section. B: Exception NO_DATA_FOUND can be used only inside the exception handler block, not inside the executable block. D: It represents header section of the PL/SQL block, not the executable block. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 209 Chapter 5: Introducing PL/SQL QUESTION NO: 46 How do you send the output of your SQL* Plus session to a text operating system file called MYOUTPUT.LST? A. SAVE MYOUTPUT.LST B. SPOOL MYOUTPUT.LST C. PRINT MYOUTPUT.LST D. SEND MYOUTPUT.LST Answer: B Explanation: Answer B is correct because command SPOOL is used in SQL * Plus to send output of the session to a text operation system file. Incorrect Answers: A: Command SAVE is not used for output generation in SQL * Plus. C: Command PRINT is used for printing from SQL * Plus. D: Command SEND does not exist. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 7 Chapter 1: Selecting data from Oracle QUESTION NO: 47 The product table contains these columns. 40 ID NUMBER(9) PK COST NUMBER(7,2) SALE_PRICE NUMBER(7,2) Management has asked you to calculate the net revenue per unit for each product, if the cost of each product is increased by 10% and the sale price of each product is increased by 25%. You issue this SQL statement. SELECT id, sale_price * 1.25 – cost * 1.10 FROM product; Which conclusion can you draw from the results? A. Only the required results are displayed. B. The results provide more information than management requested. C. A function needs to be included in the SELECT statement to achieve the desired result. D. The order on the operations in the calculation needs to be changed to achieve the required results. Answer: A Explanation: Answer A is correct because only the requested results will be displayed. Incorrect Answers: B: This query returns only information requested by management. C: There is no need to use additional function to display desired results. D: The order of operations is correct and does not need to be changed. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 6-8 Chapter 1: Selecting data from Oracle QUESTION NO: 48 You want to create report to show different jobs in each department. You do not want to display any duplicate roles in the report. Which SELECT statement do you use to create the report? A. SELECT deptno, job FROM emp; B. SELECT no duplicate deptno, job FROM emp; C. SELECT distinct deptno, job FROM emp; 41 D. CREATE report DISPLAY deptno, job FROM emp; E. SELECT distinct deptno, distinct job FROM emp; Answer: C Explanation: Answer C is correct because this query uses keyword DISTINCT which allows to avoid duplications in displayed results. Incorrect Answers: A: This statement returns results with duplications. B: NO DUPLICATE is wrong syntax in SELECT statement. D: CREATE REPORT is wrong syntax in SELECT statement. E: Keyword DISTINCT does not need to be used for each column in the list of SELECT statement. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 70-71 Chapter 2: Advanced Data Selection in Oracle QUESTION NO: 49 Which SELECT statement displays employee names, salary, department numbers and average salaries for all employees who earn more than the average salary in their department? A. SELECT ename, sal, deptno, AVG(sal) FROM emp GROUP BY ename, sal, deptno Answer: A QUESTION NO: 50 Mr. King is the president of a company. Five managers report to him. All other employees report to these managers. Examine the code. SELECT employee.ename FROM emp employee WHERE employee. empno not in SELECT manager.mgr FROM emp manager; 42 The above statement returns no rows selected as the result why? A. All employees have a manager. B. None of the employees have a manager. C. A null value is returned from the sub query. D. Operator is not allowed in sub queries. Answer: C Explanation: Answer C is correct because a null value is returned from the sub query (president of a company does not have manager for himself). Incorrect Answers: A: Not ALL employees have a manager. B: Some of the employees have a manager. D: Statement is correct, all operators is used correctly. Oracle 8, DBA Certification Exam Guide, Jason S. Couchman, p. 64-72 Chapter 5: Advanced Data Selection in Oracle