DAT
LITERALS
SQLLITERALS
A literal is a fixed value. It doesn‟t change its value. It is also called constant. In SQL, literals are
classified asfollows:
FLOATING
INTEGER
TEXT
NUMBER
Integer Literals:
Any number without fractional part is called an integer
constant. The integer numbers can contain digits (0..9) and
sign (+ or -). An integer constant must not contain commas
and spaces.
Eg: 3 -3 15 -15 2500 -9700 etc.
Text Literals:
A sequence of one or more characters enclosed within single
quotes is called text literal. These are also known as string
literals or character strings;
Eg:
„Nellore‟
„SQL-99‟
„Vikrama Simhapuri University‟
Date Literals:
Any date value enclosed within single quotes is called date
literal. The date literals must be in the format „DD- MON-
YYYY .
‟
Eg: 12-JUL-2022
‟ ‟
SQL OPERATORS
An operator is a symbol or keyword used to perform arithmetic and logical operations. In SQL, operators are
classified into the following types. They are
1 Arithmetic operators
2 Relational (comparison)
operators3 Logical operators
4 Set operators
5 Special relational operators
1 Arithmetic Operators: Arithmetic operators are used to perform mathematical operations
likeaddition,subtraction etc.
Operator Meaning Example Result
+ Addition 10+3 13
- Subtraction 10-3 7
* Multiplication 10*3 30
/ Division 10/3 3.333
| | Concatenation
10 | | 30
10 ||„AB‟
1030
10AB
1 Relational (comparison)Operators:Therelationaloperatorscomparetwovalues andgivethe result either
trueorfalse.These are usedto formsimpleconditions.
Operator Meaning Example Result
> Greaterthan 50>40 T
< Lessthan 50<40 F
= Equal to 50=40 F
>= Greaterthanorequal to 50>=40 T
<= Lessthan or equalto 50<=40 F
!= Not equal to 50!=40 T
Logical Operators: The logical operators combine two conditionsor to negate the result of a condition and
givethe result eithertrue orfalse.Theseareused to formcompound conditions.
Operator Meaning Example Result
AND Givestrueifbothconditionsaretrue 40>50AND50>30 F
OR Givestrueifanyor bothconditions aretrue 40>50 OR50>30 T
NOT
Givestrueifconditionisfalse
Givesfalseifconditionistrue
NOT (40>50) T
4 SetOperators:
Set operators are usedtocombine the output oftwo queries.Theseareusedtoformunion queries.
Operator Meaning
UNION Returns alldistinct rowsfromboth queries
UNIONALL Returns allrowsfrombothqueries
INTERSECT Returns onlycommonrows of bothqueries
MINUS Returns allrowsofthefirst querybutnotinthe secondquery
5.Special Comparison(Relational) Operators:
The special operators compare values and give the result either true
or false. These operators will simplify the complex conditions. They
can be used in conditions.
Operator Meaning
IN Comparesequaltoanyvalueinthelistofvalues
BETWEEN Comparesrangeofvalues
IS Comparesnulls
LIKE Comparesstringpatterns
ALL Comparesallvalueswithinthelist
ANYorSOME Comparesanyorsomeofvaluesinthelist
SQL DATA TYPES
The data type is the characteristic of a column in a table. It
specifies the type of data to be entered into the column of a table.
The data types are used in creating a table structure. SQL data
types are as follows
NUMBER data type: This data type allows numeric values only.
Syntax: NUMBER (L,D)
L indicates length i.e. number of digits. D indicates the number
of decimal places within the length
The length should be in the range from 1 to 38 digits. The length
is optional. If it is omitted, it takes 38 digits as default length.
Eg: i) number ii) number (9)iii) number (9,2)
CHAR data type: This data type allows any type of character i.e.
alphabet, digit, or symbol. It stores fixed length strings
Syntax : CHAR(size)
The „size indicates maximum number of characters allowed in
‟
each cell of column
The „size must be in the range from 1 to 2000 bytes
‟
The „size is optional. If it is omitted, the default length is 1
‟
character Eg: i) char ii) char(20)
VARCHAR2 data type: This data type allows any type of character i.e.
alphabet, digit, or symbol. It stores variable length strings.
syntax: VARCHAR(size)
The „size indicates maximum number of characters allowed in each
‟
cell of column
The „size must be in the range from 1 to 4000 bytes Eg: varchar2(20)
‟
LONG data type: This data type allows any type of character i.e.
„alphabet, digit, or symbol. It stores variable length strings. It can store
upto 2 Giga Bytes in each cell.
Syntax: LONG Eg: long
DATE data type: This data type allows date values. Date values must be
entered in „DD-MON-YYYY format. Syntax: DATE
‟
Eg: date
RAW data type: It is used to store small size multimedia information like
images, audio and video. It stores data in binary or hexadecimal format
Syntax: RAW(size)
• The „size must be in the range from 1 to 255 bytes Eg: raw(100)
‟
7 LONG RAW data type: It is used to store large size multimedia
information like images, audio and video. It stores data in binary or
hexadecimal format.
Syntax: LONG RAW Eg: long raw

literals operators datatypes and its adv

  • 1.
    DAT LITERALS SQLLITERALS A literal isa fixed value. It doesn‟t change its value. It is also called constant. In SQL, literals are classified asfollows: FLOATING INTEGER TEXT NUMBER
  • 2.
    Integer Literals: Any numberwithout fractional part is called an integer constant. The integer numbers can contain digits (0..9) and sign (+ or -). An integer constant must not contain commas and spaces. Eg: 3 -3 15 -15 2500 -9700 etc. Text Literals: A sequence of one or more characters enclosed within single quotes is called text literal. These are also known as string literals or character strings; Eg: „Nellore‟ „SQL-99‟ „Vikrama Simhapuri University‟ Date Literals: Any date value enclosed within single quotes is called date literal. The date literals must be in the format „DD- MON- YYYY . ‟ Eg: 12-JUL-2022 ‟ ‟
  • 3.
    SQL OPERATORS An operatoris a symbol or keyword used to perform arithmetic and logical operations. In SQL, operators are classified into the following types. They are 1 Arithmetic operators 2 Relational (comparison) operators3 Logical operators 4 Set operators 5 Special relational operators 1 Arithmetic Operators: Arithmetic operators are used to perform mathematical operations likeaddition,subtraction etc. Operator Meaning Example Result + Addition 10+3 13 - Subtraction 10-3 7 * Multiplication 10*3 30 / Division 10/3 3.333 | | Concatenation 10 | | 30 10 ||„AB‟ 1030 10AB
  • 4.
    1 Relational (comparison)Operators:Therelationaloperatorscomparetwovaluesandgivethe result either trueorfalse.These are usedto formsimpleconditions. Operator Meaning Example Result > Greaterthan 50>40 T < Lessthan 50<40 F = Equal to 50=40 F >= Greaterthanorequal to 50>=40 T <= Lessthan or equalto 50<=40 F != Not equal to 50!=40 T Logical Operators: The logical operators combine two conditionsor to negate the result of a condition and givethe result eithertrue orfalse.Theseareused to formcompound conditions.
  • 5.
    Operator Meaning ExampleResult AND Givestrueifbothconditionsaretrue 40>50AND50>30 F OR Givestrueifanyor bothconditions aretrue 40>50 OR50>30 T NOT Givestrueifconditionisfalse Givesfalseifconditionistrue NOT (40>50) T 4 SetOperators: Set operators are usedtocombine the output oftwo queries.Theseareusedtoformunion queries. Operator Meaning UNION Returns alldistinct rowsfromboth queries UNIONALL Returns allrowsfrombothqueries INTERSECT Returns onlycommonrows of bothqueries MINUS Returns allrowsofthefirst querybutnotinthe secondquery
  • 6.
    5.Special Comparison(Relational) Operators: Thespecial operators compare values and give the result either true or false. These operators will simplify the complex conditions. They can be used in conditions. Operator Meaning IN Comparesequaltoanyvalueinthelistofvalues BETWEEN Comparesrangeofvalues IS Comparesnulls LIKE Comparesstringpatterns ALL Comparesallvalueswithinthelist ANYorSOME Comparesanyorsomeofvaluesinthelist
  • 7.
    SQL DATA TYPES Thedata type is the characteristic of a column in a table. It specifies the type of data to be entered into the column of a table. The data types are used in creating a table structure. SQL data types are as follows NUMBER data type: This data type allows numeric values only. Syntax: NUMBER (L,D) L indicates length i.e. number of digits. D indicates the number of decimal places within the length The length should be in the range from 1 to 38 digits. The length is optional. If it is omitted, it takes 38 digits as default length. Eg: i) number ii) number (9)iii) number (9,2) CHAR data type: This data type allows any type of character i.e. alphabet, digit, or symbol. It stores fixed length strings Syntax : CHAR(size) The „size indicates maximum number of characters allowed in ‟ each cell of column The „size must be in the range from 1 to 2000 bytes ‟ The „size is optional. If it is omitted, the default length is 1 ‟ character Eg: i) char ii) char(20)
  • 8.
    VARCHAR2 data type:This data type allows any type of character i.e. alphabet, digit, or symbol. It stores variable length strings. syntax: VARCHAR(size) The „size indicates maximum number of characters allowed in each ‟ cell of column The „size must be in the range from 1 to 4000 bytes Eg: varchar2(20) ‟ LONG data type: This data type allows any type of character i.e. „alphabet, digit, or symbol. It stores variable length strings. It can store upto 2 Giga Bytes in each cell. Syntax: LONG Eg: long DATE data type: This data type allows date values. Date values must be entered in „DD-MON-YYYY format. Syntax: DATE ‟ Eg: date RAW data type: It is used to store small size multimedia information like images, audio and video. It stores data in binary or hexadecimal format Syntax: RAW(size) • The „size must be in the range from 1 to 255 bytes Eg: raw(100) ‟ 7 LONG RAW data type: It is used to store large size multimedia information like images, audio and video. It stores data in binary or hexadecimal format. Syntax: LONG RAW Eg: long raw