Professional Documents
Culture Documents
Session #1
DAT615 Advanced Database
Programming
ORACLE TABLES
• For example:
INSERT INTO dept (DeptId, Deptname, Location,
EmployeeId)
VALUES (10, ‘Finance’, ’Charlotte’,123);
OR
INSERT INTO dept
VALUES (10, ‘Finance’, ’Charlotte’,123);
DAT615 Advanced Database Programming By 3
Dr. Mudasser F. Wyne
• Implicit Method:
INSERT INTO dept (DeptId, DeptNAme)
VALUES (50, ‘Production’);
SELECT DISTINCT
• SELECT DISTINCT a list of columns
• Get only the columns listed
• Put them in the order they are listed
• You can rename them
• p
Eliminate duplicate rows from the result
• Example:
SELECT DISTINCT Manager_Id
FROM L_Employees
WHERE Employee_id in (201, 208, 210);
WHERE Clause
• EQUAL and other Comparison Conditions
• Equal (=)
• Less than (<)
q ((<=))
• Less than or equal
• Greater than (>)
• Greater than or equal (>=)
• Not Equal (<>)(and others)
WHERE Clause
• SET INCUSION Test – list of specific values
• IN (In a Set)
• NOT IN (Not In a Set)
• RANGE Test – between two values
• BETWEEN (in a range)
• NOT BETWEEN (not within a range)
WHERE Clause
SELECT Employee_Id, First_Name, Last_Name, Manager_Id
FROM L_EMPLOYEES
WHERE NOT (Manager_Id = 203);
WHERE Clause
• BOOLEAN CONNECTORS – Joining simple conditions
together
• AND (both of the conditions are True)
• OR (one or both of the conditions is True)
• NOT (the condition is False)
ORDER BY Clause
• Syntax –
• ORDER BY a list of column names
• ORDER BY a list of numbers
• Sort Order Options for each column
• ASC means ascending order (default)
• DESC means descending order
• Example
ORDER BY last_name, first_name
SELECT Lname
FROM EMPLOYEE
WHERE Salary BETWEEN 35000 AND 40000;
RESTRICTING DATA
QUERY List last name of all the employees who draw salary 35K, 25K and 40K.
SELECT Lname
FROM EMPLOYEE
WHERE Salary IN ( 35000, 40000, 25000 ) ;
RESTRICTING DATA
QUERY List last name of all the employees who do not draw any salary.
SELECT Lname
FROM EMPLOYEE
WHERE Salary IS Null ;
SELECT List_of_Attributes
FROM Relation_names
WHERE join condition(s);
JOIN Operations
JOIN
DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE
EMPLOYEE
FNAME LNAME SSN SALARY SUPERSSN SEX
NON--EQUIJOIN
NON
JOIN Operations
CARTESIAN PRODUCT
SELECT Attributenames
FROM tablename1, tablename2
ALIASING
• Changes the attribute name to a different column heading
• TTITLE CENTER 'Lab Exercise # BY WYNE'
ALIASING
Relation/Table Alias:
• Appear in the FROM clause of the SELECT query
• Alias names can be used in SELECT clause
• It can be 1 to 30 character
SELECT e.Lname,
L s.Dname
D
FROM EMPLOYEE e, DEPARTMENT s
WHERE e.SSN = s.MGRSSN;
RELATION INFORMATION
Oracle keeps track of all the tables created by users using its
own system database (SQL statements)
• To view users tables
SELECT table_name FROM user_tables;
or
SELECT * FROM user_tables;
• To view the relation’s structure
DESCRIBE relation_name;
• To view all the tuples in a relation
SELECT * FROM relation_name;
TABLE INFORMATION
• To view the constraint information
AUTOCOMMIT
• AUTOCOMMIT is issued when –
• Oracle is exited
• A New Table is created
j is created
• A Database Object
• Oracle AUTOCOMMIT property –
Checkbox for Autocommit
Example of a Transaction
• Transferring of $5000 from Savings account to Checking
account
• Two SQL statements
• Decrease balance of Savings account by $5000
• Increase balance of Checking account by $5000
• Issue a Commit prior to First SQL statement
• If Second SQL fails, issue a Rollback
• If Second SQL works, issue a Commit
I
Insert
t N
No Y
Yes
Delete Yes No
Additional
Find The Names of all relations/views:
• SELECT table_name/view_name
• FROM user_tables/user_view;
List all relations yyou are ppermitted to use;;
• SELECT table_name
• FROM all_tables;
Find SELECT statement that Defines a view;
• SELECT view_name, text
• FROM user_views
• WHERE view_name = ‘SHIPPING_DEPT_VIEW’;
DAT615 Advanced Database Programming By 48
Dr. Mudasser F. Wyne