Literals in SQL
What is Literals in SQL ?
- A literal is a character, a number or a data that is included in the select statement.
- Data’s and Character literal values must be enclosed by single quotation marks.
- Each character string is output once for each row returned.
Row Restrictions :
- it will accept space.
- it will not accept single quotes.
Column Restrictions:
- it will accept single quotes.
- it will not accept space.
Example :
Query : SELECT HELLO from emp;
Output : Error at line 1; “HELLO” invalid identifier
Query : ed
Query : SELECT ‘ HELLO ‘ from emp;
Query : /
Output : HELLO
HELLO
HELLO
HELLO
HELLO
.
.
.
14 rows selected
Query : SELECT 123 from emp;
Output : 123
123
123
123
.
.
.
14 rows selected
Query : SELECT ‘ I LOVE CODEFAME ‘ from emp;
Output : I LOVE CODEFAME
I LOVE CODEFAME
I LOVE CODEFAME
I LOVE CODEFAME
.
.
.
14 rows selected
Query : SELECT 15-nov-19 from emp;
Output : Error at line 1, 15-nov-19 invalid identifier.
Query : SELECT ’15-nov-19′ from emp;
Output : 15 – nov – 19
15 – nov – 19
15 – nov – 19
15 – nov – 19
.
.
.
14 rows selected