Professional Documents
Culture Documents
QUERY WRITING - Adobe - Express
QUERY WRITING - Adobe - Express
QUERY WRITING - Adobe - Express
INSERT ,UPDATE,DELETE,MERGE
Enters new rows, changes existing rows, and removes unwanted rows from tables in the
database, respectively. Collectively known as data manipulation language (DML).DK®
COMMIT
ROLLBACK
SAVEPOINT
Manages the changes made by DML statements. Changes to the data can be grouped together
into logical transactions.
GRANT
REVOKE
Gives or removes access rights to both the Oracle database and the structures within it.
Collectively known as data control language(DCL).
A column alias:
• Renames a column heading
• Is useful with calculations
• Immediately follows the column name - there can
also be the optional AS keyword between the
column name and alias
• Requires double quotation marks if it contains
spaces or special characters or is case sensitive
LAST_NAME and JOB_ID are concatenated, and they are given the alias
Employees.
The slide displays last names and job codes of all employees. The column has the
Heading Employee Details.
To eliminate duplicate rows in the result, include the DISTINCT keyword in the SELECT clause
immediately after the SELECT keyword. In the example on the slide, the EMPLOYEES table
actually Contains 20 rows but there are only seven unique department numbers in the table.
Null? -----> indicates whether a column must contain data; NOT NULL indicates that a
Column must contain data
Type ---→ displays the data type for a column
✓ Comparison Conditions
Operator Meaning
= Equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
<> Not equal to
➢ SELECT first_name
FROM employees
WHERE first_name LIKE ’S%’; → % denotes zero or many characters.
✓ ORDER BY Clause
Sort rows with the ORDER BY clause
– ASC: ascending order, default
– DESC: descending order
• The ORDER BY clause comes last in the SELECT statement .
✓ Nesting Functions
➢ SELECT last_name,
NVL(TO_CHAR(manager_id), ’No Manager’)
FROM employees
WHERE manager_id IS NULL;
NVL Function
Converts a null to an actual value.
• Data types that can be used are date, character, and number.
• Data types must match:
– NVL (commission_pct,0)
– NVL (hire_date,’01-JAN-97’)
– NVL (job_id,’No Job Yet’)
✓ JOIN
Write SELECT statements to access data from more than one table using equality and
nonequality joins.
• View data that generally does not meet a join condition by using outer joins.
• Join a table to itself by using a self join.
• A Cartesian product is formed when:
– A join condition is omitted
– A join condition is invalid
– All rows in the first table are joined to all rows in the second table
• To avoid a Cartesian product, always include a valid join condition in a WHERE clause.
Types of Joins
b.Non-Equijoins
C.Outer Joins
If a row does not satisfy a join condition, the row will not appear in the query result. For
example, in
the equijoin condition of EMPLOYEES and DEPARTMENTS tables, employee Grant does not
appear
because there is no department ID recorded for her in the EMPLOYEES table. Instead of seeing
20
employees in the result set, you see 19 records.
• You use an outer join to also see rows that do not meet the join condition.
• The Outer join operator is the plus sign (+).
D.Self Joins
Sometimes you need to join a table to itself. To find the name of each employee’s manager, you
need
to join the EMPLOYEES table to itself, or perform a self join. For example, to find the name of
Whalen’s manager, you need to:
• Find Whalen in the EMPLOYEES table by looking at the LAST_NAME column.
• Find the manager number for Whalen by looking at the MANAGER_ID column.
Whalen’s
manager number is 101.
Unlike single-row functions, group functions operate on sets of rows to give one result per
group.
These sets may be the whole table or the table split into groups.
✓ Manipulating Data
DK®
UPDATE
The UPDATE statement modifies specific rows if the WHERE clause is specified. The slide
example
transfers employee 113 (Popp) to department 70.
If you omit the WHERE clause, all the rows in the table are modified.
• Specific row or rows are modified if you specify the WHERE clause.
➢ UPDATE employees
SET department_id = 70
HERE employee_id = 113;
• All rows in the table are modified if you omit the WHERE clause.
➢ UPDATE copy_emp
SET department_id = 110;
DELETE
• All rows in the table are deleted if you omit the WHERE clause.