You are on page 1of 16

COLLEGE OF COMPUTER STUDIES

CCS0021L
(INFORMATION MANAGEMENT)

[F5-FORMATIVE]
Formative Assessment 5
EXERCISE

9
DATA CONTROL LANGUAGE

Rollen A.Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:

I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE


a. Apply knowledge through the use of current techniques and tools necessary for the IT profession. [PO: I]

II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE


 Create SQL statements that retrieve information requirements of the organization needed for reports generation.
[CLO: 4]

III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE


At the end of this exercise, students must be able to:
 Use SQL command to manipulate the data in the table

CCS0021L-Information Management Page 2 of


16
SELECT table1.column, table2.column
FROM table1
[NATURAL JOIN table2] |
[JOIN table2 USING (column_name)] |
[JOIN table2
ON (table1.column_name = table2.column_name)]|
 Use the commit, rollback and save point table2
as transaction control
[LEFT|RIGHT|FULL OUTER JOIN
ON (table1.column_name = table2.column_name)]|
[CROSS JOIN table2];
IV. BACKGROUND INFORMATION

• Join–a relational operation that causes two or more tables with a common domain to be combined into a single table or
view
• Equi-join–a join in which the joining condition is based on equality between values in the common columns;
common columns appear redundantly in the result table
• Natural join–an equi-join in which one of the duplicate columns is eliminated in the result table
• Outer join–a join in which rows that do not have matching values in common columns are
nonetheless included in the result table (as opposed to inner join, in which rows must have
matching values in order to appear in the result table)
• Union join–includes all columns from each table in the join, and an instance for each row of each
table

Figure 7-2
Visualization of different join types with
results returned in shaded area

V. GRADING SYSTEM / RUBRIC

CCS0021L-Information Management Page 3 of


16
CCS0021L-Information Management Page 4 of
16
VI. LABORATORY ACTIVITY

Scenario
Team up with other students for this exercise about controlling access to database objects.

Task
Write the appropriate SQL statement for the following queries. The result of the queries will be checked from your
computer.

1. What privilege should a user be given to log on to the Oracle server? Is this a system privilege or an object privilege?
- The CREATE SESSION system privilege

2. What privilege should a user be given to create tables?


- The CREATE SESSION system privilege

3. If you create a table, who can pass along privileges to other users on your table?
- You can, or anyone you have given those privileges to by using the WITH GRANTOPTION.

4. You are the DBA. You are creating many users who require the same system privileges. What should you use to make
your job easier?

Create a role containing the system privileges and grant the role to the users

5. What command do you use to change your password?


The ALTER USER statement

6. User1 is the owner of the EMP table and grants the DELETE privilege to User2 by using the WITH GRANT OPTION
clause. User2 then grants the DELETE privilege on EMP to User3. User1 now finds that User3 has the privilege and
revokes it from User2. Which user can now delete from the EMP table?
- User1 only
7. You want to grant SCOTT the privilege to update data in the DEPARTMENTS table. You also want to enable SCOTT
to grant this privilege to other users. What command do you use?
GRANT UPDATE on departments TO Scott WITH GRANT OPTION

8. Grant another user query privilege on your table. Then, verify whether that user can use the privilege. Note: For this
exercise, team up with another group. For example, if you are user ora21, team up with another user ora22.
a. Grant another user privilege to view records in your REGIONS table. Include an option for this user to further
grant this privilege to other users.
GRANT UPDATE on departments TO Scott WITH GRANT OPTION
b. Have the user query your REGIONS table.
SELECT * FROM Regions;
c. Have the user pass on the query privilege to a third user (for example, ora23).
SELECT * FROM Regions;
d. Take back the privilege from the user who performs step b.
SELECT * FROM Regions;

CCS0021L-Information Management Page 5 of


16
Note: Each team can run exercises 9 and 10 independently.
9. Grant another user query and data manipulation privileges on your COUNTRIES table. Make sure that the user cannot
pass on these privileges to other users.
GRANT select, update, insert ON Countries TO;

10. Take back the privileges on the COUNTRIES table granted to another user.
GRANT select, update, insert ON Countries TO;

Note: For exercises 11 through 17, team up with another group.


11. Grant another user access to your DEPARTMENTS table. Have the user grant you query access to his or her
DEPARTMENTS table.
Team 2 executes the GRANT statement.GRANT select ON departments TO <user1>;- Team 1 executes the GRANT
statement.GRANT select ON departments TO <user2>;WHERE user1 is the name of team 1 and user2 is the name of
team 2.

12. Query all the rows in your DEPARTMENTS table.


SELECT *FROM departments;

13. Add a new row to your DEPARTMENTS table. Team 1 should add Education as department number 500. Team 2
should add Human Resources as department number 510. Query the other team’s table.
Team 1 executes this INSERT statement.INSERT INTO departments(department_id, department_name)
VALUES (500,’Education’);COMMIT;- Team 2 executes this INSERT statement.INSERT INTO
departments(department_id, department_name) VALUES (510,’Administration’);COMMIT;

14. Create a synonym for the other team’s DEPARTMENTS table.


Team 1 creates a synonym named team2.
CREATE SYNONYM team2 FOR <user2>.DEPARTMENTS;- Team 2 creates a synonym named team1

15. Query all the rows in the other team’s DEPARTMENTS table by using your synonym.

CREATE SYNONYM team2 FOR <user2>.DEPARTMENTS;- Team 2 creates a synonym named team1:

CCS0021L-Information Management Page 6 of


16
16. Revoke the SELECT privilege from the other team.

Team 1 revokes the privilege.CCS0021L-Information Management Page7 of 20


REVOKE select ON departments FROM user2;- Team 2 revokes the privilege.

17. Remove the row you inserted into the DEPARTMENTS table in step 13 and save the changes.

VII. QUESTION AND ANSWER

1. What is the difference between a Join and a Natural Join?

VIII. REFERENCES

 Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
 Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.

CCS0021L-Information Management Page 7 of


16
EXERCISE

10
INTRODUCTION TO PL/SQL AND OTHER SCHEMA
OBJECTS

Rollen A. Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:

I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE


b. Apply knowledge through the use of current techniques and tools necessary for the IT profession. [PO: I]

II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE


 Create SQL statements that retrieve information requirements of the organization needed for reports generation.
[CLO: 4]

III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE


At the end of this exercise, students must be able to:
 Use SQL command to manipulate the data in the table

CCS0021L-Information Management Page 8 of


16
 Use the commit, rollback and save point as transaction control

IV. BACKGROUND INFORMATION

In order to accomplish this exercise, the student must have a clear understanding of the following topics:
 Create simple and complex views.
 Retrieve data from views.
 Create, maintain, and use sequences.
 Create and maintain indexes.
 Create private and public synonyms.

V. GRADING SYSTEM / RUBRIC

CCS0021L-Information Management Page 9 of


16
VI. LABORATORY ACTIVITY

1. Create a view that would contain the department id and department name of the departments table, wherein
the manage id is null. Name this view as DeptIDName.
SOURCE CODE:CREATE VIEW DeptIDName ASSELECT department_id, department_name FROM
departmentsWHERE manager_id IS NULL

2. Create view that would contain the employee id, first name, last name, salary of the employee, including his/
her department name and job title of employees that has an employee id that starts with 200 and above.
Name this view as EMPLOYEE_DET.
SOURCE CODE:CREATE VIEW DeptIDName ASSELECT department_id, department_name FROM
departmentsWHERE manager_id IS NULL
3. Write the code the show the content of the view EMPLOYEE_DET.
SOURCE CODE: SELECT * FROM EMPLOYEE_DET

4. Create a view that would contain the street address, postal code, city, and state province of the countries
Brazil, Belgium and Mexico. Name this view as AddressofCountries.
SOURCE CODE:CREATE VIEW AddressofCountries ASSELECT l.Street_Address, l.Postal_Code, l.City,
l.State_Province FROM locations lINNER JOIN countries C ON l.Country_id = C.country_id WHERE
C.Country_Name IN('Brazil','Mexico','Belgium')

5. Edit the view AddressofCountries. Create an alias for each columns of the view. Here are the aliases:
Street address = ST
Postal Code = PC
City = City
State Province = S_Province

SOURCE CODE:SELECT Street_Address AS "ST", Postal_Code AS "PC",city AS "City",State_Province AS


"S_Province" FROM AddressofCountries;

CCS0021L-Information Management Page 10


of 16
6. Create a sequence named Dept_Seq1. This sequence increases by 5 and begins with number 600. Its
biggest value is 10000. There should be no cache nor cycle.
SOURCE CODE:CREATE SEQUENCE Dept_Seq1 START WITH 600INCREMENT BY 5MAXVALUE 10000
NOCYCLE NOCACHE;

7. Using the new sequence Dept_Seq1, insert a new record on the departments table using the sequence as the
department id value.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);

8. Change the starting number of Dept_Seq1. The sequence should start at 700.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);

9. Create an index to optimize the column of the Commision PCT in the employees table. Name this index as
INDEX_comm.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);

10. Create a synonym for the table countries. Name this synonym as BANSA.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);

VII. QUESTION AND ANSWER

1. What are the parts of a PL/SQL block? Define each ones purposes?
The block is the most fundamental program unit in PL/SQL. The phrasesDECLARE, BEGIN, EXCEPTION, and END
define a PL/SQL block. Variables,cursors, and user-defined functions are all included in DECLARE. SQL andPL/SQL
statements are included in BEGIN. The EXCEPTION includes all stepsthat must be taken when mistakes occur. Finally, we use
Close to indicatethat the program has come to an end.The PL/SQL block is divided into three sections and these are:
● Declaration-It is where you declare variables, allocate memory for cursors, and definedata types.
● ExecutableBEGIN is the first keyword and END is the last keyword. Even if it's simplythe NULL statement, which accomplishes
nothing, it must have at least oneexecutable statement.
● Exception Handling Sections-It is where you catch and handle exceptions raised by the code in theexecution
section. Also starts with the keyword EXCEPTION. It is where youcatch and handle exceptions raised by the code in the
execution section.Also starts with the keyword EXCEPTION.

CCS0021L-Information Management Page 11


of 16
VIII. REFERENCES

 Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
 Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.

CCS0021L-Information Management Page 12


of 16
EXERCISE

11
WRITNG EXECUTABLE STATEMENTS

Rollen A. Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:

I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE


 Identify, Apply knowledge of computing appropriate to the discipline. [PO: A]

II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE


 Understand the fundamental concepts and principles of database management and database
administration. [CLO: 1]

III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE


At the end of this exercise, students must be able to:

 Explore the environment of Oracle DB application


 Apply the different database approach

CCS0021L-Information Management Page 13


of 16
IV. BACKGROUND INFORMATION

In order to accomplish this exercise, the student must have a clear understanding of the following topics:
 Declare and use variables.
 Declare, use, and print bind variables.
 Integrate SQL statements with PL/SQL program constructs.
 Write, test, and execute PL/SQL blocks.

V. GRADING SYSTEM / RUBRIC

CCS0021L-Information Management Page 14


of 16
VI. LABORATORY ACTIVITY

1. Create an anonymous block with the following specifications:


a. In the declarative section, declare the following variables:
i. variable v_today of type DATE. Initialize today with SYSDATE.
ii. variable v_tomorrow of type today. Use %TYPE attribute to declare this variable.
b. In the executable section, initialize the tomorrow variable with an expression, which calculates tomorrow’s
date (add one to the value in today). Print the value of today and tomorrow after printing “Hello World.”
c. Execute and save this script as lab_02_01_soln.sql. Sample output is as follows:

SOURCE CODE:
DECLARE_today DATE := SYSDATE;v_tomorrow v_today %TYPE :=SYSDATE+1;
BEGINDBMS_OUTPUT.PUT_LINE('Hello World'); DBMS_OUTPUT.PUT_LINE('TODAY IS: '|| v_today);
DBMS_OUTPUT.PUT_LINE('TOMORROW IS: '|| v_tomorrow); END;

2. Edit the lab_02_01_soln.sql script.


a. Add code to create two bind variables. Create bind variables b_basic_percent and b_pf_percent of type
NUMBER.
b. In the executable section of the PL/SQL block, assign the values 45 and 12 to b_basic_percent and
b_pf_percent, respectively.
c. Terminate the PL/SQL block with “/” and display the value of the bind variables by using the PRINT
command.
d. Execute and save your script file as lab_02_02_soln.sql. Sample output is as follows:

3. Edit lab_02_02_soln.sql.
a. Use single-line comment syntax to comment the lines that create the bind variables.
b. Use multiple-line comments in the executable section to comment the lines that assign values to the bind
variables.

CCS0021L-Information Management Page 15


of 16
c. Declare the v_basic_percent and v_pf_percent variables and initialize them to 45 and 12, respectively. Also,
declare two variables: v_fname of type VARCHAR2 and size 15, and v_emp_sal of type NUMBER and size
10.
d. Include the following SQL statement in the executable section:
SELECT first_name, salary
INTO v_fname, v_emp_sal
FROM employees
WHERE employee_id=110;
e. Change the line that prints “Hello World” to print “Hello” and the first name. You can comment the lines that
display the dates and print the bind variables, if you want to.
f. Calculate the contribution of the employee toward provident fund (PF).
PF is 12% of the basic salary and basic salary is 45% of the salary. Use the local variables for the
calculation. Try and use only one expression to calculate the PF. Print the employee’s salary and his
contribution toward PF.
g. Execute and save your script as lab_02_03_soln.sql. Sample output is as follows:

VII. QUESTION AND ANSWER

1. Differentiate between PL/SQL and non-PPL/SQL variables


A non-PL/SQL variable is a BIND that lets you declare in a host environmentand then use it to pass runtime
values. These values can be character ornumeric. On the other hand, PL/SQL lets you use all SQL data
manipulation,cursor control, transaction control statements, and all SQL functions,operators, and
pseudo columns. In addition, PL/SQL variable is nothing but aname given to a storage area that our
programs can manipulate.

VIII. REFERENCES

 Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
 Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.

CCS0021L-Information Management Page 16


of 16

You might also like