You are on page 1of 6

COMPUTER PROGRAMMING

ORACLE

PREPARE BY:
MR. JEROME C. AGUILAR
SHS FACULTY
Good day our dear students!
Welcome to Computer Programming Oracle: Module 3 for Grade 11!
This module was created and designed for you to learn and for you to be provided with fun and meaningful
activities which will enhance your skills in independent learning.
Please be reminded of the important activities to be accomplished upon the use of this module:
1. Please do the OPENING PRAYER before proceeding to the entire lessons and activities given for the day.
Please take a moment of silence and proceed to the opening prayer.
Opening Prayer
Heavenly Father, who by the light of the Holy Spirit, did instruct the hearts of the faithful, grant that by the same
spirit that we may be truly wise and ever enjoy His consolation. All of these we pray in Jesus name. Amen.
2. Please use and answer your module with love, eagerness and care.
3. All the instructions are clearly written on your module. Please read them carefully and make sure to follow
them faithfully.
4. Please read and understand the intended lesson for the day.
5. Please observe honesty and integrity in accomplishing the tasks given.
6. Please practice to have a motivating mood, patience and perseverance in understanding and accomplishing
the self – learning module.
7. You have to finish the tasks at hand before proceeding to the next. Make sure no activities will be neglected.
8. Please be reminded that all the activities and lessons on the module must be finished on the given time
frame.
9. After finishing the module, make sure to submit this on the given schedule.
10. Once all the lesson and activities were accomplished, please do not forget to do the CLOSING PRAYER.
Please take another moment of silence and proceed to the closing prayer.
If you encounter problems or difficulties in answering this module, please do not hesitate to address your
concerns to the responsible teacher. The contact number of the teacher and the consultation hours are
provided in this module. Please bear in mind that you have someone that will guide and will help you in
finishing your module.
It is with a positive mind that this material will really help you to have meaningful learning and gain deep
understanding of the most essential learning competencies intended for this subject. We hope that you will be
fully equipped with the necessary knowledge that will enhance you into a wholesome human being.
TOGETHER EVERYONE ACHIEVES MORE!
Enjoy your module! Thank you and God bless!

SENIOR HIGH SCHOOL SELF-LEARNING MODULE


Grade: 11 Semester: First Semester
Core Subject Title: Computer Programming - Oracle No. of Hours/Semester: 80
hours
MODULE 3

Topic/ Lesson Name Table Creation and Management


Content Standards The learners demonstrate an understanding of the principles and concepts in
demonstrating knowledge of fundamentals of SQL using Oracle Database
technology. Specifically, it teaches the concepts of relational databases and
the SQL programming language. It teaches how to write queries against single
and multiple tables, manipulate data in tables, and create database objects. It
also teaches how to use single row functions to customize output, use
conversion function, and conditional expressions.
Performance Standards The learners independently apply the fundamentals of SQL using Oracle
Database technology. Specifically, it teaches the concepts of relational
databases and the SQL programming language. It teaches how to write
queries against single and multiple tables, manipulate data in tables, and
create database objects. It also teaches how to use single row functions to
customize output, use conversion functions and conditional expressions based
on TESDA Training Regulations.
Most Essential Learning  The learner will be able to use DDL Statements to Create and Manage
Competencies Tables in accordance with PL/SQL framework.
References (Books and Oracle 11g by Joan Casteel pp. 59-83
other learning portals or https://www.w3schools.com/sql/default.asp Online simulator
websites)

LEARNING OBJECTIVES:
Upon the completion of this module, you will be able to:

 identify the table name and structure.


 create a new table with the CREATE TABLE command.
 modify the definition of a column in an existing table.
 delete a column from an existing table.

LET’S WARM- UP!


You’re able to query the existing database; however, now you need to address some requested database
modifications. In the previous module, try to add another column in the table in activity and name it as “Book
Price”.
KEY TAKEAWAYS
This module addresses methods for creating tables and modifying existing tables. Commands used to create
or modify database tables are called data definition language (DDL) commands. These commands are
basically SQL commands used specifically to create or modify database objects. A database object is a
defined, self-contained structure in Oracle 11g.
DISCUSSION
Before issuing an SQL command to create a table, you must complete the entity design. For each entity, you
must choose the table’s name and determine its structure—that is, what columns to include in the table. In
addition, you need to determine the width of any character or numeric columns.
Rules for Naming Both Tables and Columns:

 The names of tables and columns can be up to 30 characters and must begin with a letter. These
limitations apply only to a table or column name, not to data in a column.
 The names of tables and columns can’t contain any blank spaces.
 Numbers, the underscore symbol (_), and the number sign (#) are allowed in table and column names.
 Each table owned by a user should have a unique table name, and the column names in each table
should be unique.
 Oracle 11g “reserved words,” such as SELECT, DISTINCT, CHAR, and NUMBER, can’t be used for
table or column names.
Now that the table’s contents have been determined, the columns can be designed. When you create a table in
Oracle 11g, you must define each column. Before you can create the columns, however, you must do the
following:

 Choose a name for each column.


 Determine the type of data each column stores.
 Determine (in some cases) the column’s maximum width.
You need to identify the type of data to be stored in each column so that you can assign an appropriate
datatype for each column.
Oracle Datatypes
1. VARCHAR2(n)
 Variable-length character data, and the n represents the column’s maximum length. The
maximum size is 4000 characters. There’s no default size for this datatype; a minimum value
must be specified. Example: VARCHAR2(9) can contain up to nine letters, numbers, or
symbols.
2. CHAR(n)
 Fixed-length character column, and the n represents the column’s length. The default size is 1,
and the maximum size is 2000. Example: CHAR(9) can contain nine letters, numbers, or
symbols. However, if fewer than nine are entered, spaces are added to the right to force the
data to reach a length of nine.
3. NUMBER(p, s)
 Numeric column. The p indicates precision, the total number of digits to the left and right of the
decimal position, to a maximum of 38 digits; the s, or scale, indicates the number of positions to
the right of the decimal. Example: NUMBER(7, 2) can store a numeric value up to 99999.99. If
precision or scale isn’t specified, the column defaults to a precision of 38 digits.
4. DATE
 Stores date and time between January 1, 4712 BC and December 31, 9999 AD. Seven bytes
are allocated to the column to store the century, year, month, day, hour, minute, and second of
a date. Oracle 11g displays the date in the format DD-MON-YY. Other aspects of a date can be
displayed by using the TO_CHAR format. Oracle 11g defines the field width as seven bytes.
A datatype identifies the type of data Oracle 11g is expected to store in a column. Identifying the type of data
helps you verify that you input the correct data and allows you to manipulate data in ways specific to that
datatype. For example, you need to calculate the difference in number of days between two date values, such
as the Orderdate and Shipdate columns from the ORDERS table. To accomplish this task, the system needs to
be able to associate the date values to a calendar. If the columns have a DATE datatype, Oracle 11g
associates the values to calendar days automatically.
Table Creation
Basic syntax of the SQL command to create a table in Oracle 11g.

The keywords CREATE TABLE instruct Oracle 11g to create a table. Optionally, a schema can be included to
indicate who “owns” the table. For example, if the person creating the table is also the person who owns the
table, the schema can be omitted, and the current username is assumed by default.
Defining Columns
After entering the table name, you define the columns to be included in the table. A table can contain a
maximum of 1000 columns. The CREATE TABLE syntax requires enclosing the column list in parentheses. If
the table contains more than one column, the name, datatype, and width (if applicable) are listed for the first
column before the next column is defined. Commas separate columns in the list. The CREATE TABLE
command also allows assigning a default value to a column. The default value is the one Oracle 11g stores
automatically if the user makes no entry in the column.
Viewing a List of Tables: USER_TABLES
Recall that you can query the data dictionary to verify all existing tables in your schema. The USER_TABLES
data dictionary object maintains information on all your tables.
SELECT table_name FROM user_tables;
Table Creation with Subqueries
A nested query, or subquery, is required to create this new table based on the existing CUSTOMERS table. A
subquery is a SELECT statement used in another SQL command. Any type of action you can perform with a
SELECT statement (such as filtering rows, filtering columns, and calculating aggregate amounts) can be
performed when creating a table with a subquery.
To create a table containing data from existing tables, you can use the CREATE TABLE command with an AS
clause containing a subquery.

Modifying an Existing Table


At times, you need to make structural changes to a table. For example, you might need to add a column,
delete a column, or simply change a column’s size. Each of these changes is made with the ALTER TABLE
command. A useful feature of Oracle 11g is that you can modify a table without having to shut down the
database. Even if users are accessing a table, it can still be modified without disruption of service.
Whether you should use an ADD, MODIFY, or DROP COLUMN clause depends on the type of change being
made.
ALTER TABLE . . . ADD Command
Using an ADD clause with the ALTER TABLE command allows a user to add a new column to a table. The
same rules for creating a column in a new table apply to adding a column to an existing table. The new column
must be defined by a column name and datatype (and width, if applicable). A default value can also be
assigned. The difference is that the new column is added at the end of the existing table—it will be the last
column.

ALTER TABLE . . . MODIFY Command


To change an existing column’s definition, you can use a MODIFY clause with the ALTER TABLE command.
The changes that can be made to a column include the following:

 Changing the column size (increase or decrease)


 Changing the datatype (such as VARCHAR2 to CHAR)
 Changing or adding the default value of a column (such as DEFAULT SYSDATE)

You should be aware of three rules when modifying existing columns:

• A column must be as wide as the data fields it already contains.


• If a NUMBER column already contains data, you can’t decrease the column’s precision or scale.
• Changing the default value of a column doesn’t change the values of data already in the table.

ALTER TABLE . . . DROP COLUMN Command


To delete an existing column from a table, you can use the DROP COLUMN clause with the ALTER TABLE
command. This clause deletes both the column and its contents, so it should be used with extreme caution.

You should keep the following rules in mind when using the DROP COLUMN clause:

• Unlike using ALTER TABLE with the ADD or MODIFY clauses, a DROP COLUMN clause can
reference only one column.
• If you drop a column from a table, the deletion is permanent. You can’t “undo” the damage if you delete
the wrong column accidentally. The only option is to add the column back to the table and then
manually reenter all the data it contained previously.
• You can’t delete the last remaining column in a table. If a table contains only one column and you try to
delete it, the command fails, and Oracle 11g returns an error message.
• A primary key column can’t be dropped from a table

Renaming a Table
Oracle 11g allows changing the name of any table you own by using the RENAME . . . TO command.

Truncating a Table
When a table is truncated, all rows in the table are removed, but the table itself remains. In other words, the
columns still exist, even though no values are stored in them. This action is basically the same as deleting all
rows in a table. However, if you simply delete all rows in a table, the storage space these rows occupy is still
allocated to the table. To delete the rows stored in a table and free up the storage space they occupied, use
the TRUNCATE TABLE command.
Deleting a Table
You can remove a table from an Oracle 11g database by issuing the DROP TABLE command.

Closing Prayer
We give you thanks Almighty Father through your son Jesus Christ for all the benefits you have given us to you
who live and reign forever and ever. Amen.
Well done! So you have successfully completed the activities and tasks for Module 3. It is expected that you
have gained insights and meaningful experiences. What a great achievement! Again, CONGRATULATIONS
AND GOD BLESS!

Name of Teacher Contact No. Consultation Day Consultation Hours

Mr. Jerome C. Aguilar 09953674865 Monday – Friday 7:00 p.m. to 8:00 p.m.

You might also like