Pages

Showing posts with label Oracle 11g. Show all posts
Showing posts with label Oracle 11g. Show all posts

SQL Time calculation queries

To display Current date:

SELECT SYSDATE FROM DUAL;

To display Yesterday's date and Tomorrow's date (Adding or subtracting days):

SELECT SYSDATE-1 YESTERDAY,SYSDATE+1 TOMORROW FROM DUAL;

To display first day of month :

SELECT TRUNC(SYSDATE,'MONTH')FirstDayMonth FROM DUAL;

To display first day of year:

SELECT TRUNC(SYSDATE,'YEAR')FirstDayYear FROM DUAL;

To display first day of week:

SELECT TRUNC(SYSDATE,'iw')FirstDayWeek FROM DUAL;

To display today's day name:

SELECT TO_CHAR(SYSDATE,'DAY')TODAY FROM DUAL;

To display current month name:

SELECT TO_CHAR(SYSDATE,'MONTH')MONTH FROM DUAL;

SELECT TO_CHAR(SYSDATE,'MON')MON FROM DUAL;





SQL Time calculation queries

To display Current date:

SELECT SYSDATE FROM DUAL;

To display Yesterday's date and Tomorrow's date (Adding or subtracting days):

SELECT SYSDATE-1 YESTERDAY,SYSDATE+1 TOMORROW FROM DUAL;

To display first day of month :

SELECT TRUNC(SYSDATE,'MONTH')FirstDayMonth FROM DUAL;

To display first day of year:

SELECT TRUNC(SYSDATE,'YEAR')FirstDayYear FROM DUAL;

To display first day of week:

SELECT TRUNC(SYSDATE,'iw')FirstDayWeek FROM DUAL;

To display today's day name:

SELECT TO_CHAR(SYSDATE,'DAY')TODAY FROM DUAL;

To display current month name:

SELECT TO_CHAR(SYSDATE,'MONTH')MONTH FROM DUAL;

SELECT TO_CHAR(SYSDATE,'MON')MON FROM DUAL;





SQL Naming rules

we have to follow below rules.

i) Each name must begins with an Alphabetic character.

ii) Valid character set  is     a-z,A-Z,0-9 , @, #, $ and _

iii) Names are not case sensitive.

iv) Already existed names are not allowed.

v) Predefined keywords are not allowed as names.

vi) Blank spaces with in a name are not allowed.

SQL Naming rules

we have to follow below rules.

i) Each name must begins with an Alphabetic character.

ii) Valid character set  is     a-z,A-Z,0-9 , @, #, $ and _

iii) Names are not case sensitive.

iv) Already existed names are not allowed.

v) Predefined keywords are not allowed as names.

vi) Blank spaces with in a name are not allowed.

Types of SQL Commands

1) DDL (data definition language)  commands:

Used to create or change or delete the data base objects
a) CREATE b) ALTER C) DROP

2) DML  (data manipulation language ) commands:

Used to enter new data/update old data/delete unwanted data.
a) INSERT b)UPDATE c) DELETE

3) DCL ( data control  language) commands:

Used to provide or cancel permissions on the data base objects
a) GRANT b) REVOKE

NOTE:-  These  commands are used by DBA only.

4) TCL  ( Transaction control language ) commands:

Used to save or cancel user transactions.
a) COMMIT b) ROLLBACK c)SAVEPOINT


SELECT:-  Used to display the required data from the specified tables.

Types of SQL Commands

1) DDL (data definition language)  commands:

Used to create or change or delete the data base objects
a) CREATE b) ALTER C) DROP

2) DML  (data manipulation language ) commands:

Used to enter new data/update old data/delete unwanted data.
a) INSERT b)UPDATE c) DELETE

3) DCL ( data control  language) commands:

Used to provide or cancel permissions on the data base objects
a) GRANT b) REVOKE

NOTE:-  These  commands are used by DBA only.

4) TCL  ( Transaction control language ) commands:

Used to save or cancel user transactions.
a) COMMIT b) ROLLBACK c)SAVEPOINT


SELECT:-  Used to display the required data from the specified tables.

Difference between SQL and PLSQL

S NoSQLPLSQL
1
STRUCTURED QUERY LANGUAGE
PROCEDURAL LANGUAGE/SQL
2
It is a collection of predefined commands
programs.
It is a collection of user defined
commands programs
3
One query is executed at a time
as a block.
collection of queries can be executed
4
each query terminated with semi colon(;)each block terminated with END;
5
queries are not case sensitivenot case sensitive



Difference between SQL and PLSQL

S No SQL PLSQL
1
STRUCTURED QUERY LANGUAGE
PROCEDURAL LANGUAGE/SQL
2
It is a collection of predefined commands
programs.
It is a collection of user defined
commands programs
3
One query is executed at a time
as a block.
collection of queries can be executed
4
each query terminated with semi colon(;)each block terminated with END;
5
queries are not case sensitivenot case sensitive



Featured post

Snowflake - Creating warehouse in Snowflake

Creating warehouse Login to Snowflake and click on warehouse and click on Create fill the necessary details and click Finish We can also c...