SQL Data Manipulation

[Updating Data | Querying Data]

Updating data

Insert Command

This command is used to add rows to a table. The format:

INSERT INTO table
Values (list of values separated by commas).

INSERT INTO table
Select statement that retrieves values from another table

INSERT INTO Patron
Values (100, 'Marsha', 'F')

Note that the default format for dates is day-month-year, where month is a three digit character abbreviation. The date should be between single quotes (e.g., 20-JUL-95).

Delete Command

This command removes rows from a table. The format:

DELETE FROM tablename
Where condition

DELETE FROM Patron
Where PID = 100

Update Command

This command changes data in one or more rows

UPDATE tablename
SET attributename = some expression (can be an equation)
Where condition

Note that you can have more than one set statement per UPDATE command.

UPDATE Checkout
SET DueDate = '10-Dec-95'
Where PID = 100

Data Querying

Select Query

The select query used in Oracle is standard SQL so you should look in your text book for syntax and examples. The following sections illustrate some capabilities or syntax variations in Oracle that are not in the text.

Outer Joins

Unlike Outer Joins in the text, outer joins in Oracle are declared in the Where clause through the use of the (+) symbol. An example follows:
Select b.title, c.pid
    From Book b, Checkout c
    Where b.callno = (+) c.callno
The =(+) says to join the book callno with the checkout callno. But if there is no checkout callno to match book callno, use a null in the checkout attributes. Notice that the above example would be considered a left outer join in our book even though the (+) is to the right of the equal sign.

Special Set Operators

Oracle supports union, intersect and minus set operations on two select statements.

The System Catalog

Oracle keeps the names of your tables and other information in a meta table called user_tables. To see this information, use a simple select statement. The following statement list the tablenames:
Select TABLE_NAME from USER_TABLES;
To find out all the information on your tables, type:
Select * from USER_TABLES;

Group Functions

Oracle supports the following group functions in a SQL query: All of the above can be used with the DISTINCT option.

Other Useful Functions

Mathematical Functions
String Functions
String to Number Functions
Date Functions

Last modified: September 1, 1998
Dirk Baldwin, MIS, UW-Parkside, dirk.baldwin@uwp.edu