Lecture 5 26/1/15

advertisement
Lecture 5
26/1/15
1
Delete
DELETE FROM table
WHERE conditions;
DELETE FROM CUSTOMER
WHERE NAME = 'CARA';
2
Single Row Functions
•
•
•
•
•
•
•
Manipulate data items
Accept arguments and return one value
Acton each row that is returned
Return one result per row
May modify the data type
Can be nested
Accept arguments that can be a column or an
expression
Function name[(arg1, arg2……)]
3
Uses
• Functions are used to manipulate data values.
• We will now examine character, number, and
date functions.
• These are called single row functions.
• Later, we will examine group functions –
functions which apply to more than one row.
4
Character functions
• We defined functions as being used to manipulate
( or change ) data values.
• What can we change with functions?
• We can change
– User supplied constant (i.e. a number, date, or a
string)
– A variable name
– A column name
– An expression
5
Lower()
• To change characters to lower case we use
the lower() function.
• For example Lower(‘John’) Would return john
• Similarly,
Select lower(emp_name)
from employee;
6
7
Upper
• To change characters to lower case we use the
upper() function.
• For example upper (‘John’) Would return
JOHN
• Similarly,
Select upper(emp_name)
from employee;
8
Upper
• This converts lower, or mixed, case to upper case. For
example, lets take the script below.
• If the user inputs hearne then no values will be
returned.
• There is no ‘hearne’ in the employee table. There is a
‘HEARNE’.
• To fix this run
Select emp_name,sal,dept_no
From employee
Where emp_name=upper('&name');
9
10
Initcap
• Initcap, forces the first letter of a string to be
capitalized.
• For example initcap(‘john’) Will output John
11
12
Concat
• We have seen concatenation using the || symbols.
• We can also use the concat function.
• The syntax is show in the command below
Select concat(emp_name,job)
from employee
Where emp_name='HEARNE';
This will return HEARNEANALYST
• The difference between concat() and || is that concat
can only join two parameters.
13
14
Another Concat Example
This example uses nesting to concatenate three character strings:
Column
name
Column
name
SELECT CONCAT(CONCAT(emp_name, '''s job category is '), job) "Job"
FROM employee
WHERE emp_no = 3;
Column
Alias
Job
HEARNE's job category is ANALYST
15
16
Substr
• This stands for substring. It returns a part of a
string. We specify which part of the string we want
to return.
• For example
select substr('Diploma',2,3)
from sys.dual;
ipl
17
18
INSTR()
INSTR() is used to find where characters occur in a
string.
• For example,
• Instr(‘Diploma’,’o’)
• Would return the number 5.
select Instr('Diploma','oma')
from sys.dual;
Return?????
19
20
Dual
• DUAL is a table owned by the SYS user that contains a
single VARCHAR2 column called DUMMY and a single row
with the value 'X' in it.
• This table is handy when you want to select a
pseudocolumn such as SYSDATE or simply select an
expression and only want to get a single row back.
SQL> DESC sys.dual
Name
Null? Type
------------------------------- -------- ----------------------DUMMY
VARCHAR2(1)
21
Serving a PHP file
Internet – Connect to Web Browser
1. User enters
web address to
PHP file
WEB SERVER
2. Send
Request for
PHP file
3. Receive Request, find file and
read it
URL: www.mypage.com/
funstuff.php
Internet – Connect to Web Browser
7. Receive and
interpret HTML
file
Here are some fun
things to do:
1. Go shopping
2. Play soccer
4. Execute PHP
statements
6. Return
Results
5. Send back results
22
Links
• https://docs.oracle.com/database/121/SQLRF
/functions002.htm#SQLRF20032
23
Download