Professional Documents
Culture Documents
Introduction
ORACLE
It is a DBMS, which manages a large amount of data in a multi user environment so that many users concurrently access the data. It Also provides security and Recovery. It stores and manages data using relational model. Oracle is the name of database management system developed by Oracle corporation.
Tools of Oracle
SQL commands
Data Definition Language (DDL) : CREATE, ALTER, DROP, TRUNCATE Data Manipulation Language (DML) : INSERT, UPDATE, DELETE Transaction Control Language (TCL) : COMMIT, ROLLBACK, SAVEPOINT
Data Types
Data Type VARCHAR2(size) bytes) CHAR (size) chars NUMBER (p,s) DATE LONG CLOB RAW and LONG RAW Description Variable-length character data(4000 default is 1 Fixed-length character data up to 2000 Default is 1 Variable-length numeric data. Maximum we can store upto 38 digits. Date and time values Variable-length character data upto 2 GB Character data up to 4 GB Raw binary data (Raw is 2000 bytes and Long Raw is 2 GB. Allows to store pictures)
Data Types
BLOB BFILE
NVARCHAR2(size)
Variable-length character data(4000 bytes/chars) depending upon National Character Set TIMESTAMP (precision) Date plus time
DESC[RIBE] DEPT
SQL statements are not case sensitive. SQL statements can be on one or more lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Indents are used to enhance readability.
null is a value that is unavailable, unassigned, unknown, or inapplicable. A null is not the same as zero or a blank space.
Concatenation Operator
A concatenation operator: Concatenates columns or character strings to other columns Is represented by two vertical bars (||) Creates a resultant column that is a character expression
A literal is a character, a number, or a date included in the SELECT list. Date and character literal values must be enclosed within single quotation marks. Each character string is output once for each row returned.
Duplicate Rows
The default display of queries is all rows, including duplicate rows.
SELECT DEPTNO FROM EMP;
Objectives
After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query Sort the rows retrieved by a query
Character strings and date values are enclosed in single quotation marks. Character values are case sensitive, and date values are format sensitive. The default date format is DD-MON-RR.
Comparison Conditions
Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
IN(set)
LIKE IS NULL
MGR
Use the LIKE condition to perform wildcard searches of valid search string values. Search conditions can contain either literal characters or numbers:
You can use the ESCAPE identifier to search for the actual % and _ symbols.
Logical Conditions
Operator AND OR
Meaning Returns TRUE if both component conditions are true Returns TRUE if either component condition is true Returns TRUE if the following condition is false
NOT
SELECT EMPNO, ENAME, JOB, SAL FROM WHERE AND EMP SAL >=10000 JOB LIKE '%MAN%';
OR
Rules of Precedence
Order Evaluated Operator 1 Arithmetic operators 2Concatenation operator 3Comparison conditions 4IS [NOT] NULL, LIKE, [NOT] IN 5[NOT] BETWEEN 6NOT logical condition 7AND logical condition 8OR logical condition Override rules of precedence by using parentheses.
Rules of Precedence
Use parentheses to force priority.
SELECT ENAME, JOB, SAL FROM WHERE OR AND EMP (JOB = 'SALESMAN' JOB = 'PRESIDENT') SAL > 15000;
ORDER BY Clause
SELECT FROM
ORDER BY HIREDATE ;
ORDER BY annsal;
Rules of Precedence
OR
AND
JOB = 'PRESIDENT'
SAL > 15000;
Exercise
1) Display the names with single word 2) Display the names with two words 3) Display the names with exactly three words 4) Display all the salaries beginning with digit 2 5)DisplayallthenameswithsecondletterasA 6) Display the employees who joined between any two given dates 7) Display the names and experience of all the employees 8) How many employees does not draw salary between 5000 and 10000 9) Display all the names whose names contain underscore(_) 10)Calculate the experience in years for each employee and display along with their names, in descending order.