0% found this document useful (0 votes)
17 views6 pages

Oracle SQL Basics and Data Types Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Oracle SQL Basics and Data Types Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 1

Lab 1: Introduction

Objectives
Introduction to Oracle and SQL.

Introduction
Oracle has many tools such as SQL * PLUS, Oracle Forms, Oracle Report Writer, Oracle
Graphics etc.

• SQL * PLUS: The SQL * PLUS tool is made up of two distinct parts. These are

– interactive SQL: Interactive SQL is designed for create, access and manipulate
data structures like tables and indexes.
– PL/SQL: PL/SQL can be used to developed programs for different applications.

• Oracle Forms: This tool allows you to create a data entry screen along with the suitable
menu objects. Thus it is the oracle forms tool that handles data gathering and data
validation in a commercial application.

• Report Writer: Report writer allows programmers to prepare innovative reports using
data from the oracle structures like tables, views etc. It is the report writer tool that
handles the reporting section of commercial application.

• Oracle Graphics: Some of the data can be better represented in the form of pictures.
The oracle graphics tool allows programmers to prepare graphs using data from oracle
structures like tables, views etc.

SQL (Structured Query Language)


Structured Query Language is a database computer language designed for managing data
in relational database management systems(RDBMS), and originally based upon Relational
Algebra. Its scope includes data query and update, schema creation and modification, and
data access control. SQL was one of the first languages for Edgar F. Codd’s relational model
in his influential 1970 paper, "A Relational Model of Data for Large Shared Data Banks" and
became the most widely used language for relational databases.

• IBM developed SQL in mid of 1970’s.

• Oracle incorporated in the year 1979.

1
2 Lab 1: Introduction

• SQL used by IBM/DB2 and DS Database Systems.

• SQL adopted as standard language for RDBS by ASNI in 1989.

DATA TYPES
CHAR (Size) This data type is used to store character strings values of fixed length. The size
in brackets determines the number of characters the cell can hold. The maximum number of
character is 255 characters.

• VARCHAR (Size) / VERCHAR2 (Size): This data type is used to store variable length
alphanumeric data. The maximum character can hold is 2000 character.

• NUMBER (P, S): The NUMBER data type is used to store number (fixed or floating
point). Number of virtually any magnitude may be stored up to 38 digits of precision.
Number as large as 9.99 * 10 124. The precision (p) determines the number of places
to the right of the decimal. If scale is omitted then the default is zero. If precision is
omitted, values are stored with their original precision up to the maximum of 38 digits.

• DATE: This data type is used to represent date and time. The standard format is DD-
MM-YY as in 17-SEP-2009. To enter dates other than the standard format, use the
appropriate functions. Date time stores date in the 24-Hours format. By default the
time in a date field is 12:00:00 am, if no time portion is specified. The default date for a
date field is the first day the current month.

• LONG: This data type is used to store variable length character strings containing up
to 2GB. Long data can be used to store arrays of binary data in ASCII format. LONG
values cannot be indexed, and the normal character functions such as SUBSTR cannot
be applied.

• RAW: The RAW data type is used to store binary data, such as digitized picture or
image. Data loaded into columns of these data types are stored without any further
conversion. RAW data type can have a maximum length of 255 bytes. LONG RAW
data type can contain up to 2GB.

INTERACTIVE SQL
Syntax : VERB(Parameter _1,Parameter _2,Parameter _3,........Parameter _n); SQL language is
sub-divided into several language elements, including:

• Clauses, which are in some cases optional, constituent components of statements and
queries.

• Expressions, which can produce either scalar values or tables consisting of columns and
rows of data.

• Predicates which specify conditions that can be evaluated to SQL three-valued logic
(3VL) Boolean truth values and which are used to limit the effects of statements and
queries, or to change program flow.

• Queries which retrieve data based on specific criteria.

• Statements which may have a persistent effect on schemas and data, or which may
control transactions, program flow, connections, sessions, or diagnostics.
3

• SQL statements also include the semicolon (";") statement terminator. Though not re-
quired on every platform, it is defined as a standard part of the SQL grammar.

• Insignificant white space is generally ignored in SQL statements and queries, making
it easier to format SQL code for readability.

There are five types of SQL statements. They are:

• DATA DEFINITION LANGUAGE (DDL)

• DATA MANIPULATION LANGUAGE (DML)

• DATA RETRIEVAL LANGUAGE (DRL)

• TRANSATIONAL CONTROL LANGUAGE (TCL)

• DATA CONTROL LANGUAGE (DCL)

The Data Definition Language (DDL)


The Data Definition Language (DDL) is used to

• Creating a table

• Altering table structure by adding, deleting or modifying columns

• Destroy databases and database objects.

These commands will primarily be used by database administrators during the setup and
removal phases of a database project.

Create new Table


It defines each column of the table uniquely. Each column has minimum of three attributes,
a name , data type and size.

Syntax

CREATE TABLE <table name> (<col1> <datatype>(<size>),<col2> <datatype><size>));


Ex:CREATE TABLE emp(empno number(4) primary key, ename char(10));

Add new column to existing table


Once table created within a database, one may wish to modify the definition of it. The AL-
TER command allows you to make changes to the structure of a table without deleting and
recreating it.
4 Lab 1: Introduction

Syntax

ALTER TABLE <tablename> add(<new col><datatype(size),<new col>datatype(size));


Ex:ALTER TABLE emp add(sal number(7,2));

Drop Column
In an existing table, a column can be deleted or dropped using the ALTER command.

Syntax

ALTER TABLE <tablename> drop column <col>;


Ex:ALTER TABLE emp drop column sal;

Modify Column
In an existing table, a column can be modified using the ALTER command.

Syntax

ALTER TABLE <tablename> modify(<col><newdatatype>(<newsize>));


Ex:ALTER TABLE emp modify(ename varchar2(15));

Renaming the table


We can rename a table using RENAME command.

Syntax

RENAME <oldtable> to <new table>;


Ex. RENAME emp to emp1;

Destroying tables
A table can be destroyed or deleted using DROP command.

Syntax

DROP TABLE <tablename>;


Ex. DROP TABLE emp1;
5

Summary
1: Create a table named BRANCH with following Structure

Data Field Name Type Constraint


Branch Number branchno number(1) Primary Key
Branch branchname varchar2(30) Not Null
• Add the column ’emailid’ to table BRANCH with Constraint UNIQUE.

• Modify the column named ’branch name’ to Varchar2(25)

• Rename the table name to ’Branch Info’

• Delete the column named ’emailid’

2: Create a table named STUDENT with following Structure


Data Field Name Type Constraint
Student Name name varchar2(30) Not Null
Student Number registerno number(11) Primary Key
Branch Number branchno number(1) Foreign Key
Section sec varchar2(1) Not Null
Joined Date joindate date Not Null
Mark mark number(5,2) Not Null
• Add the column ’emailid’ to table STUDENT with Constraint UNIQUE.

• Modify the column named ’student name’ to Varchar2(25)

• Rename the table name to ’Branch student data’

• Delete the column named ’emailid’


6 Lab 1: Introduction

Practise Exercise
1: Create a table named MARKGRADE with following Structure

Data Field Name Type Constraint


Grade grade varchar2(1) Not Null
Lowest Mark lowmark number(5,2) Not Null
Highest Mark highmark number(5,2) Not Null
• Add the column ’student name’ to table STUDENT with Constraint varchar2(30).

• Modify the column named ’student name’ to Varchar2(25)

• Rename the table name to ’students marks grade’

2: Create a table named PROJECT with following Structure

Data Field Name Type Constraint


Project Number pno number(3) Primary Key
Project Name pname varchar2(60)
Project Manager pmgr number(4) Not Null
Persons persons number(3)
Budjet budjet number(8,2)
Project Start date pstart date Not Null
Project End Date pend date

Common questions

Powered by AI

Oracle Graphics complements other Oracle tools by allowing the creation of visual representations of data, such as graphs, using information from Oracle structures like tables and views. This visual representation is particularly beneficial for better understanding and interpreting data patterns or trends, which can aid decision-making processes—enhancing the raw data capabilities offered by other tools like Oracle Forms and Report Writer.

Using non-indexable data types like LONG in SQL databases has significant implications on performance and functionality. LONG data types can store large amounts of data (up to 2GB), but they cannot be indexed, which limits the efficiency of search operations. This can lead to slower data retrieval times and increased resource consumption when querying large datasets. Additionally, many character functions do not apply to LONG data types, which restricts their versatility in operations that require manipulation of character data. Opting for indexable types ensures better performance and broader functional support within SQL databases.

The introduction of SQL by IBM in the mid-1970s was a groundbreaking development in the field of RDBMSs. SQL enabled a standardized method of managing and querying data within databases, leading to widespread adoption across different systems. With its adoption as a standard language for RDBMS by ANSI in 1989, SQL facilitated a uniform approach to database management operations, improving compatibility and interoperability among diverse database systems. This standardization was pivotal in SQL becoming the predominant language for accessing and manipulating relational databases.

The SQL * PLUS tool in Oracle is composed of interactive SQL and PL/SQL. Interactive SQL is designed for creating, accessing, and manipulating data structures such as tables and indexes, enabling data queries and updates. PL/SQL, on the other hand, is used to develop programs for various applications, enhancing the functional capabilities of SQL by supporting procedural constructs.

SQL's basis on Edgar F. Codd’s relational model is significant because it aligns the language with a theoretical framework that defines data in terms of relations or tables. This adherence allows SQL to effectively handle complex transactions and queries while maintaining data integrity and consistency through relational algebra. This foundational model ensures that SQL can support robust database structures and operations, making it suitable for large shared data banks, which was the vision detailed in Codd's influential 1970 paper.

When creating a SQL table, each column must have a name, a data type, and a size. These attributes are crucial for maintaining database integrity and functionality. The name uniquely identifies the column within the table. The data type ensures that the data stored is consistent with the expected format, which can facilitate efficient querying and manipulation. The size attribute limits the amount of data stored, preventing storage bloating and maintaining optimal database performance. Collectively, these attributes preserve the accuracy, reliability, and efficiency of data handling in SQL databases.

The ALTER command in SQL is a versatile statement used to modify the structure of an existing database table without deleting and recreating it. It can add new columns, drop existing ones, or change the data and constraints of a column. For example, ALTER TABLE emp ADD (sal NUMBER(7,2)) adds a new column, while ALTER TABLE emp DROP COLUMN sal removes one. It can also modify existing columns, such as ALTER TABLE emp MODIFY (ename VARCHAR2(15)), which changes the data type and size of the 'ename' column.

The CHAR data type is used for storing character string values of a fixed length, with a maximum of 255 characters. Conversely, VARCHAR (or VARCHAR2) is used for variable-length alphanumeric data, supporting up to 2000 characters. CHAR is preferable for fields with consistently sized data, improving performance by avoiding length variability. VARCHAR is ideal when there is anticipated variability in the data length, optimizing storage space and efficiency by allocating only the necessary space for each entry.

SQL statements are categorized into several types based on their purposes. Data Definition Language (DDL) statements are used for defining or altering database structures, such as CREATE or ALTER commands. Data Manipulation Language (DML) encompasses operations like INSERT, UPDATE, or DELETE that modify the data itself. Data Retrieval Language (DRL) is primarily the SELECT statement for retrieving data. Transaction Control Language (TCL) commands like COMMIT or ROLLBACK manage transaction states, while Data Control Language (DCL) commands, such as GRANT or REVOKE, control access to data. Each type enriches database management with specific functionalities.

Oracle Forms is used for creating data entry screens with accompanying menu objects, focusing on data gathering and validation within commercial applications. The Report Writer, however, is utilized for preparing innovative reports, leveraging data from Oracle structures like tables and views, thus focusing on the reporting needs of commercial applications.

You might also like