Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
SQL

SQL

Ratings: (0)|Views: 136|Likes:
Published by Prudhvi Raj

More info:

Published by: Prudhvi Raj on Sep 19, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

12/23/2012

pdf

text

original

 
SQL Structured Query Language
Page
1
of 
164
 
History
 
Dr. E. F. Codd
published the paper, "A Relational Model of Data for Large Shared Data Banks", in June 1970in the Association of Computer Machinery (ACM) journal,
Communications of the ACM 
. Codd's model is nowaccepted as the definitive model for relational database management systems (RDBMS). The language, StructuredEnglish Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model. SEQUELlater became SQL (still pronounced "sequel"). In 1979, Relational Software, Inc. (now Oracle) introduced the firstcommercially available implementation of SQL. Today, SQL is accepted as the standard RDBMS language.
Introduction
Structured Query Language (SQL) is the set of statements with which all programs and users access data in anOracle database. Application programs and Oracle tools often allow users access to the database without usingSQL directly, but these applications in turn must use SQL when executing the user's request. This chapter provides background information on SQL as used by most database systems.
Basic Elements of Oracle SQL:-
Below are elements in Oracle SQL:
Datatypes
Literals
Format Models
 Nulls
Comments
Database Objects
Schema Object Names and Qualifiers
Syntax for Schema Objects and Parts in SQL StatementsData Types:-
Sno Datatype Description
1VARCHAR2(
 size
[BYTE |CHAR])Variable-length character string having maximum length
 size
bytes or characters.Maximum
 size
is 4000 bytes or characters, and minimum is 1 byte or 1 character. You mustspecify
 size
for VARCHAR2.BYTE indicates that the column will have byte length semantics; CHAR indicates that thecolumn will have character semantics.2NVARCHAR2(
 size
)Variable-length Unicode character string having maximum length
 size
characters. Thenumber of bytes can be up to two times
 size
for AL16UTF16 encoding and three times
 size
for UTF8 encoding. Maximum
 size
is determined by the national character set definition,with an upper limit of 4000 bytes. You must specify
 size
for NVARCHAR2.3NUMBER[(
 precision
[, Number having precision
 p
and scale
 s
. The precision
 p
can range from 1 to 38. The scale
 s
© Copy rights are reserved. Author: Chandu
 
SQL Structured Query Language
Page
2
of 
164
Sno Datatype Description
 scale
]])can range from -84 to 127.4LONGCharacter data of variable length up to 2 gigabytes, or 2
31
-1 bytes. Provided for backwardcompatibility.5DATEValid date range from January 1, 4712 BC to December 31, 9999 AD. The default format isdetermined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This datatype contains thedatetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It does not havefractional seconds or a time zone.6BINARY_FLOAT32-bit floating point number. This datatype requires 5 bytes, including the length byte.7BINARY_DOUBLE64-bit floating point number. This datatype requires 9 bytes, including the length byte.8TIMESTAMP[(
 fractional_seconds
)]Year, month, and day values of date, as well as hour, minute, and second values of time,where
 fractional_seconds_precision
is the number of digits in the fractional part of theSECOND datetime field. Accepted values of 
 fractional_seconds_precision
are 0 to 9. Thedefault is 6. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The sizes varies from 7 to 11 bytes, depending on the precision. This datatype contains the datetime fields YEAR,MONTH, DAY, HOUR, MINUTE, and SECOND. It contains fractional seconds but doesnot have a time zone.9TIMESTAMP[(
 fractional_seconds
)] WITHTIME ZONEAll values of TIMESTAMP as well as time zone displacement value, where
 fractional_seconds_precision
is the number of digits in the fractional part of the SECONDdatetime field. Accepted values are 0 to 9. The default is 6. The default format isdetermined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 13 bytes. This datatype contains thedatetime fields YEAR, MONTH, DAY, HOUR, MINUTE, SECOND,TIMEZONE_HOUR, and TIMEZONE_MINUTE. It has fractional seconds and an explicittime zone.10TIMESTAMP[(
 fractional_seconds
)] WITHLOCAL TIME ZONEAll values of TIMESTAMP WITH TIME ZONE, with the following exceptions:
Data is normalized to the database time zone when it is stored in the database.
When the data is retrieved, users see the data in the session time zone.The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The sizes varies from 7 to 11 bytes,depending on the precision.11INTERVAL YEA[(
 year_precision
)] TOMONTHStores a period of time in years and months, where
 year_precision
is the number of digitsin the YEAR datetime field. Accepted values are 0 to 9. The default is 2. The size is fixedat 5 bytes.12INTERVAL DAY[(
day_precision
)] TOSECOND[(
 fractional_seconds
)]Stores a period of time in days, hours, minutes, and seconds, where
day_precision
is the maximum number of digits in the DAY datetime field.Accepted values are 0 to 9. The default is 2.
 fractional_seconds_precision
is the number of digits in the fractional part of theSECOND field. Accepted values are 0 to 9. The default is 6.The size is fixed at 11 bytes.13RAW(
 size
)Raw binary data of length
 size
bytes. Maximum
 size
is 2000 bytes. You must specify
 size
© Copy rights are reserved. Author: Chandu
 
SQL Structured Query Language
Page
3
of 
164
Sno Datatype Description
for a RAW value.14LONG RAWRaw binary data of variable length up to 2 gigabytes.15ROWIDBase 64 string representing the unique address of a row in its table. This datatype is primarily for values returned by the ROWID pseudocolumn.16UROWID [(
 size
)]Base 64 string representing the logical address of a row of an index-organized table. Theoptional
 size
is the size of a column of type UROWID. The maximum size and default is4000 bytes.17CHAR [(
 size
[BYTE |CHAR])]Fixed-length character data of length
 size
bytes. Maximum
 size
is 2000 bytes or characters.Default and minimum
 size
is 1 byte.BYTE and CHAR have the same semantics as for VARCHAR2.18NCHAR[(
 size
)]Fixed-length character data of length
 size
characters. The number of bytes can be up to twotimes
 size
for AL16UTF16 encoding and three times
 size
for UTF8 encoding. Maximum
 size
is determined by the national character set definition, with an upper limit of 2000 bytes. Default and minimum
 size
is 1 character.19CLOBA character large object containing single-byte or multibyte characters. Both fixed-widthand variable-width character sets are supported, both using the database character set.Maximum size is (4 gigabytes - 1) * (database block size).20NCLOBA character large object containing Unicode characters. Both fixed-width and variable-width character sets are supported, both using the database national character set.Maximum size is (4 gigabytes - 1) * (database block size). Stores national character setdata.21BLOBA binary large object. Maximum size is (4 gigabytes - 1) * (database block size).22BFILEContains a locator to a large binary file stored outside the database. Enables byte stream I/Oaccess to external LOBs residing on the database server. Maximum size is 4 gigabytes.
SQL is divided into the following.
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Retrieval Language (DRL)
Transaction Control Language (TCL)
Data Control Language (DCL)DDL -- create, alter, drop, truncate, renameDML -- insert, update, deleteDRL -- selectTCL -- commit, rollback, savepoint
© Copy rights are reserved. Author: Chandu

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->