Retrieving Data Using Select

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

RETRIEVING DATA USING SELECT


CAPABILITIES OF SQL STMT:

 Selection – Selecting the rows of a table


 Projection- Selecting certain columns of a table
 Join - Bringing/Displaying data together from multiple tables

BASIC SELECT STATEMENT:

* Denotes selecting all the columns

ARITHMETIC EXPRESSION:

Add, subtract, multiply, divide

OPERATOR PRECEDENCE- () * / + -

DEFINING NULL VALUES:

 Null is unavailable, unassigned, unknown, inapplicable


 Is not zero or blank space
 Any operation containing null evaluates to null

COLUMN ALIAS:

 Renames a column header


 Useful while calculations
 Immediately follows column
 Embedded with “” to retain case

CONCATENATION OPERATOR:

 Links characters or columns to other columns


 Represented by ||
 Concatenate null value does not alter anything

LITERAL CHARACTER STRINGS:

 Literal is a character, date or a number used in select statement


 Must be enclosed with ‘ ’

Alternative q’’ operator (q’[]’)

 We can use any delimiter


 [] {} () <>

Distinct keyword: removes duplicate columns

Describe command:

 Displaying table structure


 Columns, datatype
 NUMBER(p,s ) p-precision s- scale
 Varchar2(s) s- size
 Date
 Char(s) fixed length character of size s
2. RESTRICTING & SORTING DATA
 Restricting the rows displayed
 Sorting the rows

LIMITING THE ROWS

 The where clause USING


 Comparison option (< ,>,between ,like, IN, LIKE), NULL
 Logical operations AND OR NOT

COMPARISON OPERATORS

=, >, >=, <, <=, <>, BETWEEN AND, IN, LIKE, IS NULL

PATTERN MATCHING USING LIKE OPERATOR

% - many character

_ - only one character

ESCAPE identifier:

For searching exact match SA_, we have search using escape identifier

Select * from employees where job_id like ‘%SA\_%’ ESCAPE ‘\’;(interprets _ literally)

IS NULL

LOGICAL OPERATORS:

AND = true, if both conditions are true

OR = true, if any of the components is true

NOT = true, if the condition is false

PRECEDENCE RULES:

 Arithmetic operators
 Concatenation
 Comparison
 IS NULL, LIKE, IN
 BETWEEN
 NOT equal to
 NOT logical
 AND logical
 OR logical
 Precedence overridden by ()

SORTING THE ROWS

 Rows are sorted by using ORDER BY {column, expression, numeric position} [ASC | DESC]
 To display null rows first or last can be used NULLS FIRST, NULLS LAST

Check for & and && variables

DEFINE AN VERIFY COMMAND

DEFINE employee_num = 200


Select employee_id,last_name

From employees

Where employee_id = &employee_num;

UNDEFINE employee_num

SET VERIFY ON – toggles the display of the substitution variable before and after the sql developer replaces the substation
variable.

3. SQL FUNCTIONS
 Perform calculations on data
 Modify individual data items
 Manipulate output for a group of rows
 Format dates and numbers for display
 Convert columns data types

Function types:
 Single row functions
 Multi row functions

SINGLE ROW FUNCTION


 Character : accepts character and return character and number
 Number : accepts numeric and return numeric
 Date: operates on DATE datatype
 Conversion : converts from one type to other
 General:
1. NVL
2. NVL2
3. NULLIF
4. COALESCE
5. CASE
6. DECODE

CHARACTER FUNCTION:

Case conversion function:

LOWER

UPPER

INITCAP

Character Manipulation Function


CONCAT SUBSTR LENGTH

INSTR LPAD RPAD TRIM REPLACE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy