SQL Notes
SQL Notes
4
5
6
Single row functions are very powerful pre-defined code that accept arguments and return a value. An
argument can be defined as a column name, an expression, or a constant.
7
8
9
10
The reason Oracle differentiates between 'V' and 'v' is due to the way it stores characters. It does not store
the chars directly, but their corresponding binary values, depending on the character set of the database.
In most of the Western world, an ACSII character set will have been used as the database character set, and
the binary codes for 'V' and 'v' are different numbers; therefore, Oracle does not consider them to be
equal.
11
Using Case Manipulation Functions in the WHERE clause allows you to retrieve rows regardless of the case
they are stored in the table.
Using Case Manipulation Functions in the SELECT clause alters the way in which the results of the query are
displayed.
12
13
14
Example 1: extracts a substring of 5 characters from position 1 of 'HelloWorld'.
Example 2: extracts a substring starting at position 6 of 'HelloWorld' to the end of the string.
Example 3: extracts a substring of the first 3 characters from employee last names.
15
The second example returns the number of characters in each employees last name.
16
Example 1: a 'W' is the 6th character of the first string argument, so the function would return the number
6.
Example 2: returns the first occurrence of the character 'a' in employee last names. If the name does not
contain 'a', zero is returned. Even though Abel contains an "A", it is in the wrong case, hence the 0 is
returned.
17
Example 1: the string 'HelloWorld' is left padded to 15 characters using the '-' symbol. As the string has a
length of 10 characters, 5 '-' symbols are added to the left. .
Example 2: Employee last names are left padded to 10 characters using an '*'.
18
19
Example 1: removes the leading 'a' from the start of the string 'abcba'
Example 2: removes the trailing 'a' from the end of the string 'abcba'
Example 3: removes both the leading 'a' and the trailing 'a' from the string 'abcba'.
If LEADING, TRAILING or BOTH are omitted, the function returns BOTH.
IF the specified character is not the leading (or trailing) character of the string, it is not trimmed, for
example TRIM (LEADING 'a' FROM 'xyz') would return 'xyz'
20
21
Example 1: Every instance of 'J' in the string 'JACK and JUE' is replaced with 'BL'.
Example 2: If the replacement string argument is omitted, the string_to_replace is deleted,
So every instance of 'J' in the string 'JACK and JUE' is removed.
Example 3: Every instance of the character 'a' in employee last names is replaced with a '*' character.
22
23
24
The first example uses an Alias for the column heading, and is more readable and user-friendly than the
second example which has no column alias.
25
26
27
A Substitution Variable is User-Defined at the time of execution.
28
29
30
31
32
33
34