Вы находитесь на странице: 1из 24

Oracle and SQL


Supervised by: Prof. Akshay Kumar Sharma

Submitted by:
Jasdeep Kaur


Oracle and SQL


This term assistance, department completing particularly

paper has been written with the kind guidance and active support of my teachers who have helped me a lot in this paper. I express my deep regards to my esteem guide and supervisor Prof. Akshay Kumar Sharma for his valuable advice and support to complete this work.

I appreciate the concern shown by Prof. Sharma. Who guided me from time to time in giving final shape to this paper. Last but not least I am thankful to my parents and who helped me lot in preparing this paper.


Oracle and SQL



Oracle and SQL


Oracle and SQL



Oracle and SQL


Oracle is currently one of the most widely used RDBMS that provides efficient solutions for the database applications. It is responsible for accurately storing the data and efficiently retrieving that data in response to a user query. The Oracle Database is an object-relational database management system produced and marketed by Oracle Corporation. Most Oracle database installations traditionally came with a default schema called SCOTT. After the installation process has set up the sample tables, the user can log into the database with the username Scott and the password tiger. The name of the SCOTT schema originated with Bruce Scott, one of the first employees at Oracle (then Software Development Laboratories), who had a cat named Tiger. Oracle provides a wide range of softwares designed for todays business that moves at speed of internet. Millions of application developers and database administrators around the world use oracle to built complex system that manage huge amount of data. Oracle consists of multitude of powerful features and components which makes it different from other rdbms. It include ecommerce, human resources, strategic enterprise management, mobile computing, manufacturing, high performance business intelligent services etc. oracle also provides open access to web servers through SQL, java, standard web interfaces. Oracle is supported over different operating environments ranging from IBM mainframes, UNIX based mini computers, Windows NT, DEC, VAX minicomputers etc. The Oracle RDBMS stores data logically in the form of table spaces and physically in the form of data files. Oracle Database software comes in 63 language-versions. Variations between versions cover the names of days and months, abbreviations, time-symbols such as A.M. and A.D., and sorting. Oracle Corporation has translated Oracle Database error-messages into Arabic, Catalan, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Greek, Hebrew, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Romanian, Russian, Slovak, Spanish, Swedish, Thai and Turkish. Oracle Corporation provides database developers with tools and mechanisms for producing internationalized database applications: referred to internally as "Globalization".


Oracle and SQL

The Oracle Database is commonly referred to as Oracle RDBMS or simply as Oracle. A relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd. Most popular commercial and open source databases currently in use are based on the relational database model. A short definition of an RDBMS may be a DBMS in which data is stored in the form of tables and the relationship among the data is also stored in the form of tables.


Larry Ellison and his friends and former co-workers Bob Miner and Ed Oates started the consultancy Software Development Laboratories (SDL) in 1977. SDL developed the original version of the Oracle software. The name Oracle comes from the code-name of a CIA-funded project Ellison had worked on while previously employed by Ampex



Oracle and SQL


In June 1970, Dr. E.F. Codd published a paper entitled A Relationship Model of data for large shared data banks. This relational model, sponsored by IBM, then came to accepted as the definitive model for Relational Database Management System. The language developed by IBM to manipulate the data stored with in Codds model as originally called Structured English Query Language, but then word English later being dropped in favor of STRUCTURED QUERY LANGUAGE. SQL originated with the system R project in 1974 at IBMs San Jose Research Center. The purpose of this project was to validate the feasibility of the rational model and to implement a DBMS based on this model. In addition to contributing to the concept of query complication and optimization and concurrency controlled mechanisms, the most salient result of this research project was the development of SQL. A large number of commercial relational DBMS products were released from IBM as a conclusion of system R project. In late 1970s Lawrence Joseph Ellison and Robert n minor were working on consulting project for the CIA in USA where CIA wanted to use SQL. The code name for the project was ORACLE. Initially, the oracle corporation was named as Relational Software Inc. in 1977. But later to avoid confusion with competitor RTI, the companys name RSI was changed to Oracle Corporation. Today Oracle is the gold standard for database technology and applications in enterprises throughout the worldthe company is the world's leading supplier of information management software and the world's second largest independent software company. The acquisition of Sun gives Oracle a leadership role in the hardware arena as well. Now more than ever before Oracle technology can be found in nearly every industry, and in the data centers of 100 of the Fortune Global 100 companies. Oracle is the first software company to develop and deploy 100 percent internet-enabled enterprise software across its entire product line: database, business applications, application development, and decision support tools. Before the acquisition of Sun was final, Oracle and Sun introduced the Sun Oracle Database Machine, the world's fastest machine for any type of database workload. Today, Sun Oracle Real Application Clusters, Oracle Applications, Oracle Grid Computing, support for enterprise Linux, and Oracle Fusion, all fuel a commitment to innovation and results that has defined Oracle for thirty years.


Oracle and SQL


environment : Oracle allows processing to be split between the client

application programs and the database server, the bulk of database processing is done on the backend i.e. database server that typically has more computing power and better access to data to enhance the processing capabilities.
2)Scalability: Oracle supports a large numbers of concurrent users executing different types

of application operating on the same data. It helps to add or remove users without interrupting the other users.

large databases and performs space management: Oracle provides

support for handling large amount of data stored in database. It allows full control of space to make efficient use of expensive hardware devices.

performance: Oracle maintains high degree of overall system performance by

implementing database task in parallel with speed up querying, tuning, maintenance of database.
5)Availability: Oracle provides high availability of data. Operations such as partial

computer system failures and database backup failures do not interrupt the availability of data to the users.
6)Security: Oracle provides safe-security features to protect database access against

unauthorized use from the intruders. It provides the security by: Account disablement after a specified number of failed attempts. Password expiration and forced password changes. Password history maintenance to prevent users from reusing previous passwords.
Complex password enforcement that forces users to choose passwords which cannot be

easily guessed by potential intruders.


enforced integrity: oracle enforces data integrity by providing the integrity

constraints thus restricting users from entering the data which do not validate the rules of integrity constraints.

Oracle and SQL 8)Openness

industry standards: Oracle follows the industry accepted standards for the

data access language network communication protocols, operating systems.



APPLICATION DEVELOPMENT TOOLS: Following tools are used for the

application development.
SQL* PLUS: A command line tool used to manipulate tables and other database

objects in a oracles database. In oracle 9i, it is named as ISQL *PLUS.

DEVELOPER/2000: It is a family of tools the supports the development client/server

applications. It includes forms, reports, and graphics.

Oracle forms: it is an enterprise tool used to develop data entry forms and menus that

access tables in an oracles database.

Oracle reports: It is a report writer tool used to develop reports that access tables in a

oracle database. Oracles graphics: A graphical tool used to develop charts and presentation graphics from database queries.
DESIGNER/2000: It is a family of tools that support the development of complex

applications that may span many organizations with in an enterprise

PROGRAMMER/2000: it includes the PRO* precompliers i.e. libraries routines and

utilities that can be linked with C, C++, java, Fortran, Cobol or other host languages to allow access to oracles database.



ENTERPRISE MANAGER: A GUI based collection of utilities for managing Oracle database. EXPORT/IMPORT: Command line utilities that allows a user or DBA to export data from an ORACLE database into a machine readable file to an Oracle database.


Oracle and SQL

SQL* LOADER: A command line utility to load ASCII data files into an Oracle database. SQL* DBA and SVRMGR: A utility that allows a DBA to monitor database activity and to tune the database for optimal performance.



SQL* NET: A communication driver that allows an Oracle tool running on an client

machine to access data on a separate server machine.

ORACLE ODBC DRIVERS: Open database connectivity drivers for connecting

software such as visual basic to oracle.


Oracle and SQL

Structured Query Language


Oracle and SQL


The SQL*Plus module of the ORACLE database management system is used to create, modify and query databases and to produce simple reports from them. This document is designed to be used while logged on to a computer system which runs ORACLE or while using a PC with ORACLE. It introduces SQL*Plus by giving examples of commands. Type the commands as indicated to see their effects. Some of the examples are complex; they have been included to illustrate the power of SQL. The examples are also available as files which can be used as described later. There are two types of command in SQL*Plus - standard SQL commands and commands specific to SQL*Plus. SQL*Plus commands SQL*Plus commands are used to control the way results are displayed, show the definition of a table, edit commands etc. They are one line long only. They can optionally be terminated by a semicolon. SQL commands SQL commands are used to create, query and maintain a database. A command may be continued over several lines and is stored in a buffer until it is overwritten. SQL*Plus prompts for the second and subsequent lines of the SQL command by displaying the current line number. The default buffer can contain only a single SQL command. The command is executed when a terminating semicolon is typed. It can be terminated without executing it by entering a blank line. The SQL*Plus run command lists then runs the command in the default buffer; a / (slash) executes the SQL command without listing it. Using it its users can connect to database, either on a same machine or a database located on a different server machine across a network. SQL*PLUS performs the following task along with manipulation of SQL commands and PL/SQL blocks. Administering the database Formatting, calculations, printing query results in the form of reports Copy data between databases. Creating script files to store SQL statements for future use. Listing tables and PL/SQL object in the database.


Oracle and SQL



Oracle and SQL

Data Definition Language (DDL) Statements Data definition language (DDL) statements let you to perform these tasks

Create, alter, and drop schema objects Grant and revoke privileges and roles Analyze information on a table, index, or cluster Establish auditing options Add comments to the data dictionary


Oracle and SQL

The CREATE; ALTER, and DROP commands require exclusive access to the specified object. For example, an ALTER TABLE statement fails if another user has an open transaction on the specified table. Data Manipulation Language (DML) Statements Data manipulation language (DML) statements access and manipulate data in existing schema objects. These statements do not implicitly commit the current transaction. The data manipulation language statements are: CALL, DELETE, EXPLAIN PLAN, INSERT LOCK, TABLE MERGE, SELECT UPDATE. The SELECT statement is a limited form of DML statement in that it can only access data in the database. It cannot manipulate data in the database, although it can operate on the accessed data before returning the results of the query. The CALL and EXPLAIN PLAN statements are supported in PL/SQL only when executed dynamically. All other DML statements are fully supported in PL/SQL. Transaction Control Statements Transaction control statements manage changes made by DML statements. The transaction control statements are: COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION. All transaction control statements, except certain forms of the COMMIT and ROLLBACK commands, are supported in PL/SQL. For information on the restrictions, see COMMIT and ROLLBACK . Data Control Language
DCL is

a computer language and a subset of SQL, used to control access to data in a database.

Examples of DCL commands include: GRANT, REVOKE, CONNECT, SELECT,INSERT,UPDATE,DELETE,EXECUTE,USAGE. In Oracle, executing a DCL command issues an implicit commit. In PostgreSQL, executing DCL is transactional, and can be rolled back.


In order to store and manage the data it is necessary to create tables. In Oracle, Tables are created using CREATE TABLE command which is one of the important DDL statement. This command specifies the name of table, name of columns in table as well as the data type and if required constraints associated with each column of table. To create the table in your schema, you must have the CREATE TABLE system privilege. To create table in another users schema. You must have CREATE ANY TABLE system privilege.


Oracle and SQL

SYNTAX CREATE TABLE [SCHEMA.]<table_name> ( <colomn_name1><data_type>[DEFAULT<expression>][<column constraints>] [, <colomn_name2><data_type>[DEFAULT<expression>][<column constraints>]] [,.] [, <colomn_namen><data_type>[DEFAULT<expression>][<column constraints>]] [, <table constraints>] );

You cannot only modify the columns that exist in your tables but you can also drop them entirely. You can also remove the constraints from the table using the ALTER TABLE statement. When a constraint is dropped, any associated index with that constraint is also dropped. SYNTAX ALTER TABLE<table name> DROP COLOMN <colomn name> (for dropping one colomn) ALTERTABLE<tablename> DROP (<colomnname1>, <colomnname2>); (for dropping multiple tables)

Sometime it is necessary to remove table from database completely that is no longer needed. It can be done by using DROP TABLE command. The DROP TABLE command removes the table from the database. All the table rows, indexes and privileges will also be removed. The CASCADE CONSTRAINT is the optional parameter which is used for tables which have foreign keys that reference the table being dropped. If cascade constraint is not specified and user attempts to drop a table that has records in child table, then error will occur. SYNTAX

Oracle and SQL

Drop Table<table name>[ CASCADE CONSTRAINTS];

Oracle provides the facility to change the name of table by using ALTER TABLE statement. When you rename the table, Oracle automatically updates foreign keys, in data dictionary but it does not updates a store code module, stored queries or reports client applications. So care must be taken when renaming the table. STNTAX ALTER TABLE<old_tablename> RENAMETO<new_tablename>; OR RENAME<old_tablename> to <new_tablename>;

The INSERT statement is used to add new row to the table. To insert new row into the table, table must be in your schema or you must have INSERT privilege on the table. Only one row is inserted at a time with this syntax. You can insert literal values, expressions containing operators and functions, null values etc. only. You can insert rows into table without specifying the column name because they are optional.

Oracle and SQL

SYNTAX INSERT INTO <tablename>[(<colmnname1>[, <colmnname2>][,<colomnnameN>])] VALUES (<colmnname1>[, <colmnname2>][,<colomnnameN>]);

The DELETE statement is used to remove the row from table. You do not need to know the physical ordering of the rows in a table to perform a DELETE. Oracle database engine determines the internal location of rows. To delete rows from table, it must be in your own schema or you must have delete privilege on the table. A condition is used in the WHERE clause to filter the records that are actually being removed. Zero or more rows can be removed from the table. If such expression will not be provided then DELETE statement will remove all rows from table. SYNTAX DELETE FROM<tablename> [WHERECONDITION]


As it is required to make changes or modifications in the records of table, so in order to make these changes, the UPDATE statement is used. With this statement the user can modify the existing data stored in table. It can update zero or more rows in table. To update rows in table, it must be in your schema or you must have update privilege on table. Following points should be remembered while executing UPDATE statement. It can only reference a single table. At least one column must be assigned an expression in SET clause.

Oracle and SQL

On omitting, the update statement automatically updates all the records of the table on execution. Multiple conditions should be given in where clause.



Oracle tables are used for storing data which consist of both rows and columns. The columns are used for storing an attributes data. Each column in a table has a column name and a data type. Following are the different data types:1 CHARCTER DATA TYPE Character data types are used to declare columns containing character data in the database. Following are the different character data type: o CHAR (n): This data type is used for storing fixed length character strings. Once a char column is defined, all values stored in that column will also have the length as specified in the length of declaration.

Oracle and SQL

o VARCHAR (n): This data type is used to store variable length character strings, but oracle recommends using VARCHAR2 (n) data type instead of VARCHAR (n) data type. o VARCHAR2 (n): This data type is used to store variable length character string. When declaring a column of data type VARCHAR2, you must specify its size. o NCHAR (n): This data type is used to store fixed length national character set. This character set enables developers and administrators to extend the standard database character set, in order to store data in language and characters set other than English. o NVARCHAR2 (n): This data type is used to store variable-length string in database national character set. When you create a table with it you define the column length either in characters or in bytes. o LONG (n): This data type is used to store a large amount of variable length character strings. It is mostly used to store long text strings. o RAW and LONGRAW: They both are used to store binary data such as sound, graphics, documents etc. 2 NUMBER DATA TYPES The NUMBER data types are used for storing numeric data such as integers, floating point numbers and real numbers. The NUMBER data types offer great flexibility for storing numeric data. o NUMBER: This data type is used to store zero, positive and negative fixed and floating point numbers. The NUMBER data type have a precision and a scale. The precision is the total number of digits in the number and can range from 1 to 38digits. The scale describes the number of digits to right of decimal point in any given number.

3 DATE/TIME DATA TYPE It stores data and time information.

o DATE: this data type is used to store data and time information. It is store

in specified internal oracle format that includes not only the month, day and year but also the hours, minutes and seconds.
o TIME STAMP: it is an extension of the date data type. It allows time to be

stored as date with fractional seconds. Its syntax is TIMESTAMP [(fract_second_precision)].


Oracle and SQL

o INTERVAL YEAR TO MONTH: it allows time to be stored as an interval of years and month. Its syntax: INTERVALYEAR [(year_percision)]TO MONTH. o INTERVAL DAY TO SECOND: it allows time to be stored as an interval of days to hours, minutes and seconds. 4 LOBS The large objects provide a more flexible storage mechanism for large amount of binary and character based data such as text, image video, sound etc. o BLOB: The binary large object data type is used to store binary data such as images, audio files, video etc. o CLOB: The character large object data type is used for storing large amount of character data. It is used in place of VARCHAR2 column to store text in applications when the size of data is 4000 characters.

o BFILE: the binary file data type when declared for a column contains pointers to large binary files stored on the file system of the data base server.

An operator manipulates individual data item and returns a result. The data items on which operators act upon are called operands. Some operators require two operand while other act upon only one operand. The operators which act upon one operand are called unary operators and operators that act upon two operand are called binary operators. The operators are represented by special characters and keywords. For example: the addition operator is represented by plus sign and operator that test for nulls is represented by IS NULL. 1) ARITHMATIC OPERATORS

Oracle and SQL

These operators are used in an expression to add, subtract, multiply, negative, divide numeric values. Result of operation is also a numeric value.+ and operators are also used in date arithmetic. +: donates the positive expression when used as unary operators. E.g. + 5 add two operands when used as binary operators. -: donates a negative expression when used as unary expression *: Multiplies two operands. E.g. 6*5 is a Binary operator. /: Divides two operands. It is a binary operator e.g. 10/5 2) COMPARISON OPERATORS These are used to compare one expression with other. The result for such comparison can be TRUE, FALSE, or UNKNOWN. >: if (expr 1> expr 2) then the greater than comparison operator results TRUE if expr 1 is greater than expr 2, otherwise false <: if (expr 1<expr 2) then the less than comparison operator results TRUE if expr 1 is less than expr 2, otherwise false >=: if(expr 1>= expr 2) then the greater than equal to comparison operator results TRUE if expr 1 is greater than equal to expr 2, otherwise false. <=: if(expr 1<= expr 2) then the less than equal to comparison operator results TRUE if expr 1 is less than equal to expr 2, otherwise false. IN: to check whether the value is equal to any member of set. BETWEEN: to test whether the value is within the range or not. LIKE: used in character string comparisons with pattern matching. ANY: compares a value to each value in the list on being returned by a query. ALL: compares a value to every value in the list on being returned by a query. EXISTS: it returns TRUE if sub query returns at least one row. ISNULL: it checks whether the value of a specified column is NULL or not.

3) LOGICAL OPERATORS These are used to combine the individual logical expressions into more complex conditions that are either TRUE or FALSE. In other words, a logical operator combines the result of two component conditions to produce a single result based on them or to invert the result of single condition. AND: if the both logical expression evaluates to be TRUE, then the result is TRUE. Returns FALSE if either is FALSE otherwise return UNKNOWN. OR: if either logical expression evaluates to be TRUE, then the result is TRUE. Returns FALSE if either is FALSE otherwise return UNKNOWN.

Oracle and SQL

NOT: it is urinary operators which return TRUE, if the condition is FALSE. Returns FALSE if either is FALSE otherwise return UNKNOWN. 4) CONCATENATION OPERATORS (ii) The concatenation operator is used to concatenate two or more strings. 5) SET OPERATORS These operators combine the result of two component queries into single result. UNION: It returns all rows selected by either query excluding all duplicates. UNIONALL: It returns all rows selected by either query including all duplicates. INTERSECT: It returns all distinct rows selected by both queries. MINUS: It returns all distinct rows selected by the first query but not the second. 6) Other in-built operators Some other in built operators include(+) which used in outer join operators, PRIOR used in tree structure queries.