Escolar Documentos
Profissional Documentos
Cultura Documentos
9. PL/SQL concepts:
Cursors,Stored Procedures,Stored function,Database Triggers Reference Book: SQL-PL/SQL by IVAN BAYROSS
What is Database?
It is collection of information(records) that is organized so that it can easily be accessed,managed and updated. What is Database Mangement System? It is set of computer programs that controls the creation,maintenance and the use of the database of an organization. Eg. Oracle
Introduction to SQL
What is SQL?
SQL stands for Structured Query Language. Originally developed by IBM in the early 1970s. It was initially spelt and pronounced as SEQUEL but now popularly called SQL. It has an ANSI as well as ISO standard.
In DBMS a group of similar information or data which is of interest to an organization is called an Entity. Entity information is stroed in an object called Table. Eg. Student (entity) & information about student stored in student_master table. Table is two dimentsional matrix that consists of rows and columns. Table must have a unique name(i.e student_master).
Each entity can have a number of characteristics. Eg. Student have characteristics name,address,telephon number etc The values for these characteristics are called Attributes values.
Tuple/record/row:
An organization will deal with many clients and the same information must be record for each student. Multiple fields placed in a horizontal plane, is called a record or row or typle.
Introduction to SQL
Different Components of SQL: Data Defination Language(DDL) Data Manipulation Language(DML) Data Control Language(DCL) Transaction Control Data Retrieval(Queries)
DDL (Data Defination Language): The DDL commands related to structure of an object (table ,view etc.) i.e creating an object, modifying structure of an object, removing an object or changing the name of object E.g. CREATE,ALTER,DROP,RENAME,TRUNCATE DML (Data Manuplation Language): The DML commands are those related to the content of the table (i.e data). They deal with the insertion, updation and deletion of rows in a table. E.g. INSERT,UPDATE,DELETE.
The DCL commands are required to give or take back access rights on objects. eg. GRANT,REVOKE
TRANSACTION CONTROL:
Handle the unit of work i.e a transcation A transcation either exectues as a whole or none of its statements execute. eg. COMMIT,ROLLBACK,ROLLBACK TO SAVEPOINT
Data retirval:
-To display data(records,columns)in required fields. Eg. SELECT(many options with the select command)
DATA TYPES:
1)CHAR (size): To store character strings values of fixed length. Max no:255
oracle compares CHAR values using blank comparison semantics i.e if a value that is inserted in a cell CHAR data type is shorter than the size it is defined for then it will be padded with spaces on the right until it reaches the size characters in length.
2)VARCHAR/VARCHAR2(size): To store variable length alphanumeric data. max no: 2000characters
4) DATE:
To reprent date and time. Standard format: DD-MON-YY & 24 hour time format.eg. 21-JUL-09. By default time is 12:00:00 If no time portion is specified. The default date : first day of the current month. Variable length character string (2 GB)
5) LONG:
6)RAW/LONG RAW: To store binary data like digitalized picture or image.(255bytes for raw and 2 GB for long raw)
a) CREATE TABLE COMMAND: CREATE TABLE tablename (columnname size,columnname size); b) INSERT VALUES COMMAND: INSERT INTO tablename (column1,column2)VALUES(value1,value2); OR INSERT INTO tablename VALUES(value1,value2); NOTE:Values in between .
c)
d)
Retriving Data:
Retriving all rows and all columns: SELECT * FROM tablename; Retriving particular columns and all rows: SELECT column1 (AS newcolumnname),column2 FROM tablename; Retriving selected rows and all columns(with some condition) SELECT * FROM tablename WHERE search condition; Retriving selected columns and selected rows: SELECT columnname1,columnname2 FROM tablename WHERE search condition;
Elimination of duplicates from the select statement: SELECT DISTINCT columnname,columname FROM tablename; SELECT DISTINCT * FROM tablename; Sorting data in a table: SELECT * FROM tablename ORDER BY columnname desc/asc; (by default order is ascending order)
Creating table from a table: Syntax: CREATE TABLE tablename (columnname,columnname) AS SELECT columnname,columnname FROM tablename; Inserting data into a table from another table: Syntax: INSERT INTO tablename SELECT columnname,columnname FROM tablename; INSERT INTO tablename SELECT columnname,columnname FROM tablename WHERE column=expression;
Update command:
used to change or modify data values in a table Updating all rows: UPDATE tablename SET columnname=expression,columnname=expression; Update records conditionally: UPDATE tablename SET columnname=expression,columnname=expression; WHERE columnname=expression;
Renaming tables: RENAME oldtablename TO newtablename; Destroying tables: DROP TABLE client_master;