Homework Week 7 Answers (2)

4
IS562 – Database Applications and Programming. Week 7 Homework Answers Part 1 Using the following Data Dictionary views write the statements that will perform the following actions. Be sure to test your statements. (Do not use SELECT *) ROLE_ROLE_PRIVS ROLE_SYS_PRIVS ROLE_TAB_PRIVS USER_ROLE_PRIVS USER_SYS_PRIVS USER_TAB_PRIVS 1. Determine what privileges your account has been granted through a role. (3 points) select username, granted_role from user_role_privs; USERNAME GRANTED_ROLE -------------- ------------- D01012172 CONNECT D01012172 DVONLINE PUBLIC PLUSTRACE 2. Determine what system privileges your account has been granted. (3 points) SQL> select * from user_sys_privs; no rows selected 3. Execute the following statement then determine what table privileges your account has been granted. (3 points) Grant select on student to public; select table_name, privilege from user_tab_privs;

Transcript of Homework Week 7 Answers (2)

Page 1: Homework Week 7 Answers (2)

IS562 – Database Applications and Programming.

Week 7 Homework Answers

Part 1

Using the following Data Dictionary views write the statements that will perform the following actions. Be sure to test your statements. (Do not use SELECT *)

ROLE_ROLE_PRIVSROLE_SYS_PRIVSROLE_TAB_PRIVSUSER_ROLE_PRIVSUSER_SYS_PRIVSUSER_TAB_PRIVS

1. Determine what privileges your account has been granted through a role. (3 points)

select username, granted_role from user_role_privs;

USERNAME GRANTED_ROLE-------------- -------------D01012172 CONNECTD01012172 DVONLINEPUBLIC PLUSTRACE

2. Determine what system privileges your account has been granted. (3 points)

SQL> select * from user_sys_privs;

no rows selected

3. Execute the following statement then determine what table privileges your account has been granted. (3 points)

Grant select on student to public;

select table_name, privilege from user_tab_privs;

TABLE_NAME PRIVILEGE----------- ------------STUDENT SELECT

4. Determine what system privileges the DVONLINE role has. (3 points)

Page 2: Homework Week 7 Answers (2)

select privilege from role_sys_privs where role = 'DVONLINE';

PRIVILEGE----------------------------------------CREATE TABLECREATE TRIGGERCREATE CLUSTERCREATE SEQUENCECREATE DATABASE LINKCREATE PROCEDURECREATE ANY DIRECTORYCREATE TYPECREATE SYNONYMCREATE VIEWALTER SESSION

11 rows selected.

5. Analyze the following query and write a description of the output it produces. (3 points)

SELECT COUNT(DECODE(SIGN(total_capacity-20),-1,1,0,1)) “<=20”, COUNT(DECODE(SIGN(total_capacity-21), 0, 1, -1, NULL, DECODE(SIGN(total_capacity-30), -1, 1)))"21-30", COUNT(DECODE(SIGN(total_capacity-30), 1, 1)) "31+" FROM (SELECT SUM(capacity) total_capacity, course_no FROM section GROUP BY course_no)

Determine the total capacity for each course and order them in three columns. List the number of courses with a total capacity of 20 or less in one column, the number of courses with a total capacity between 21 and 30 in another, and lastly show the number of courses with a capacity of over 31 in the third column. The result shows that there are two courses with a total capacity of 20 or less, 10 courses with a capacity between 21 and 30, and 16 courses with a capacity over 31 students.

6. Determine the top three zip codes where most of the students live. Use an analytical function. The query will product 10 rows. (5 points)

SELECT * FROM (SELECT zip, COUNT(*), DENSE_RANK() OVER(ORDER BY COUNT(zip) DESC) AS rank FROM student GROUP BY zip) WHERE rank <=3

ZIP COUNT(*) RANK----- ---------- ----------07024 9 107010 6 2

Page 3: Homework Week 7 Answers (2)

11373 6 211368 6 207042 5 311355 5 311209 5 307047 5 311375 5 311372 5 3

10 rows selected.

Part 2

This function sets the default password resource parameters and is used whenever passwords are created or changed. The rules for an acceptable password are evaluated against the new password. If an exception is found, an error message is produced.

This function makes checks for:

Checks if the password is same as the username Check for the minimum length of the password Checks if the password is too simple. A dictionary of words may be

maintained and a check may be made so as not to allow the words that are too simple for the password.

Check if the password contains at least one letter, one digit and one punctuation mark.

Checks if the password differs from the previous password by at least 3 letters

This “alter profile” statement alters the default parameters for Password Management. This means that all the users on the system have Password Management enabled and set to the following values unless another profile is created with parameter values set to different value or UNLIMITED is created and assigned to the user.