Professional Documents
Culture Documents
Oracle
Oracle
INSTRUCTOR NOTES
SECTION 1 LESSON 1 Case and Character Manipulation Slide 1: Case and Character Manipulation No instructor notes for this slide Slide 2: What Will I Learn? No instructor notes for this slide Slide 3: Why Learn It? Ask students for other ways in which we transform ourselves. Possible responses: Many professions wear uniforms; your rough draft of a paper doesnt usually look like what you eventually turn in. Slide 4: Why Learn It? (continued) No instructor notes for this slide Slide 5: Tell Me / Show Me DUAL TABLE Begin this lesson with a review question: What are the five types of single-row functions? Answer: Character, Number, Date, Conversion, and General Slide 6: Tell Me / Show Me DUAL TABLE (continued) Demonstrate and practice the following functions using the DUAL table. 1. Create a query that outputs the CD titles in the DJ on Demand database in all lowercase letters. SELECT LOWER(title) FROM d_cds; 2. Create a query that selects the first names of the DJ on Demand clients who have an a somewhere in their name. Output the results set in all uppercase letters. Ask students why UPPER was put in the SELECT statement and not in the WHERE clause. SELECT UPPER(first_name) FROM d_clients WHERE first_name LIKE '%a%'; Slide 7: Tell Me / Show Me SINGLE-ROW CHARACTER FUNCTIONS Single row functions are very powerful pre-defined code that accepts arguments and returns a value. An argument can be defined as a column name, an expression, or a constant. There are five single row function groups: Character Number Date Conversion Oracle Academy 1 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
4 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
5 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
6 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
7 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
8 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
11 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Format INITCAP
Character functions
TRIM
Expression
Single-row functions
REPLACE
Try It / Solve It 1. Using the three separate words Oracle, Internet, and Academy, use one command to produce the following output: The Best Class Oracle Internet Academy Solution: SELECT CONCAT('Oracle ', 'Internet')||' Academy' AS "The Best Class" FROM DUAL; 2. Use the string Oracle Internet Academy to produce the following output: The Net net Solution: SELECT SUBSTR('Oracle Internet Academy', 13,3)AS "The Net" FROM DUAL; 3. What is the length of the string Oracle Internet Academy? Solution: 23 SELECT LENGTH('Oracle Internet Academy')AS "Length" FROM DUAL;
Oracle Academy
13 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
7. Using the string Oracle Internet Academy, produce the output shown using the REPLACE function. The Best Class Oracle 2004-2005 Academy Solution: SELECT REPLACE('Oracle Internet Academy', 'Internet','2004-2005') AS "The Best Class" FROM DUAL; 8. List the order date and the order total from the Global Fast Foods F_ORDERS table. Name the order total as TOTAL, and fill in the empty spaces to the left of the order total with $. Solution: SELECT order_date, LPAD(ORDER_TOTAL,10,'$')AS "TOTAL" FROM f_orders; Oracle Academy 14 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
15 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
16 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
MOD ROUND
Try It / Solve It 1. Display Oracle database employee last_name and salary for employee_ids between 100 and 102. Include a third column that divides each salary by 1.55 and rounds the result to two decimal places. Solution: SELECT last_name, ROUND(salary/1.55,2) AS "Salary Calculation" FROM employees WHERE employee_id BETWEEN 100 AND 102; 2. Display employee last_name and salary for those employees who work in department 80. Give each of them a raise of 5.33% and truncate the result to two decimal places. Solution: SELECT last_name, TRUNC(salary * 1.0533,2) AS "Salary with Raise" FROM employees WHERE department_id = 80; -Alternate answer SELECT last_name, TRUNC(salary * .0533,2) AS "Raise Amount" FROM employees WHERE department_id = 80;
Oracle Academy
17 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
19 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Try It / Solve It 1. For DJ on Demand, display the number of months between the event_date of the Vigil wedding and todays date. Round to the nearest month. Solution: SELECT ROUND(MONTHS_BETWEEN (SYSDATE,event_date)) AS MONTHS FROM d_events where id=105; 2. Display the days between the start of last summers school vacation break and the day school started this year. Assume 30.5 days per month. Name the output Days. Solution: SELECT ROUND(MONTHS_BETWEEN ('05-SEP-04', '15-JUN-04')*30.5) AS DAYS FROM dual; (Answers will vary.) 3. Display the days between January 1 and December 31. Solution: SELECT ROUND(MONTHS_BETWEEN ('31-DEC-04','01-JAN-04')*30.5) AS DAYS FROM dual; Oracle Academy 20 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
21 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
22 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
23 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
24 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Oracle Academy
25 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.
Solution: Individual Responses Answer each of the following. Use complete sentences. 3. Which career(s) do you have the most interest in? Solution: Individual Responses 4. For each of the careers you are most interested in, describe in detail why you are interested in it. What makes this job sound like something youd like to do? Solution: Individual Responses 5. Based on the educational/training requirements for the career(s) you are most interested in, list the courses youve taken in high school or college that you feel will help you prepare for this career? Solution: Individual Responses 6. What future steps will you take to gain more knowledge and experience about your chosen career(s)? Solution: Individual Responses Oracle Academy 26 Database Programming with SQL Copyright 2009, Oracle. All rights reserved.