SQL COMMANDS
Languages:
- DQL Data query language(Select)
- DML ( Insert, Update, Delete, Marge)
- DDL ( Create, Alter, Drop, Rename, Truncate)
- TCL ( Commit, Rollback, SavePoint)
- DCL (Grant, Revoke)
SELECT STATEMENT
Select *|Distinct Col
name from table;
Arithmetic Expression: (+, -,*, /)
Precedence (*, /, +, -)
Null value
- A null is a value that is unavailable, unassigned, unknown, inapplicable.
- A NULL is not the same as Zero or a Blank.
- Arithmetic expression containing a null value evaluate to null.
Defining Column
Alias:
- Rename as a column heading.
- It is useful with Calculation
- Immediately follows the column name there can also be the optional AS keyword between the column name and alias.
- Requires double quotations marks if it contains space or special characters or is case sensitive.
- Example: select last_name AS(optional) name,commission comm. From employee.
Or
Select last_name
“Name”,salary*12 “Annul salary” from employee.
Concatenation
Operator:
- Concate columns or characters string to other column.
- It is represented by two vertical bars (||).
- Create a resultant column that is a character expression.
- Example: select lastname || job_id AS “Employees” from employee;
Order By: Sort
rows with Order By Clause (ASC / DESC)
1. Order By
clause comes last in the SELECT Statement.
2. Example: select expr from table where
condition(s) order by [column exp][ASC /
DESC]
Sorting By column
Alias
- Example: Select emp_id,Last_name,salary*12 AS AnnualSal from emp order by
AnnualSal;
Sorting By multipul
columns
- Example: Select last_name,salary from emp order by dept_id,salary DESC;
Functions:
Functions are very
powerful feature of SQL
1. Perform
calculation on data.
2. Modify
individual data items.
3. Manipulate
output for group of rows.
4. Format
dates and numbers for display.
5. Convert
column data types.
Type of SQL Functions:
There are two type of SQL Functions
1. Single
Row Function.
2. Multiple
Row Function.
1.
Single Row
Functions:
These function operate on single
row only and return one result per row.
1. Manipulate
data items.
2. Accept
arguments and return one value.
3. Act
on each row returned.
4. Return
one result per row.
5. May
modify the data type.
6. can
be nested.
7. Accept
arguments which can be a column or an expression.
Note: An argument in single row
function can be one of the following:
1. User-supplied
constant
2. Variable
value
3. Expression.
Features of single row functions:
1. Acting
on each row returned in the query.
2. Returning
one result per row.
3. Possibly
returning a data value of a different type than that referenced.
4. Possibly
expecting one or more arguments.
5. Can
be used in SELECT, WHERE and ORDER BY clause can be nested.
Type of Single Row Function
1. Character
2. Number
3. Date
4. Conversion
5. General (NVL, NVL2, NULLIF, COALSECE, CASE,
DECODE)
No comments:
Post a Comment