Presentation is loading. Please wait.

Presentation is loading. Please wait.

+, -, *, / Mathematical operators ABS(value) Returns the absolute value SIGN(value) Returns the sign of a value, such as 1, -1, 0 MOD(value,divisor) Returns.

Similar presentations


Presentation on theme: "+, -, *, / Mathematical operators ABS(value) Returns the absolute value SIGN(value) Returns the sign of a value, such as 1, -1, 0 MOD(value,divisor) Returns."— Presentation transcript:

1

2 +, -, *, / Mathematical operators ABS(value) Returns the absolute value SIGN(value) Returns the sign of a value, such as 1, -1, 0 MOD(value,divisor) Returns the remainder Number Functions

3 ROUND(value[,precision]) Rounds the value TRUNC(value[,precision]) Truncates the value FLOOR(value) Returns the largest integer CEIL(value) Returns the smallest integer Number Functions continued

4 NVL(input_expr,substitution_expr) Null value replacement COALESCE(input_expr,substitution_exp_1[,substitution_expr_n]) Null value replacement with multiple substitution expressions NVL2(input_expr,not_null_substitution_expr,null_substitution_expr) Null and not null substitution replacement LNNVL(condition) Returns true if the condition is false or unknown. Returns false if the condition is true. NULLIF(expr_1,equal_expr_2) Returns null if the value of the two expressions are identical; otherwise, returns first expression Miscellaneous Functions

5 Miscellaneous Functions continued NANVL(input_value,substitution_value) Returns a substitution value in the case of NAN (not a number) value DECODE(if_expr,equals_search,then_result[,else_default]) Substitution function based on if- then-else logic CASE {WHEN cond THEN return_expr [WHEN cond THEN return_expr]…} [ELSE else_expr] END Searched CASE expression. It allows for testing of null values and other comparisons. CASE {expr WHEN expr THEN return_expr [WHEN expr THEN return_expr]…} [ELSE else_expr] END The simple CASE expression tests for equality only. No greater than, less than, or IS NULL comparisons are allowed.

6

7 DATE TIMESTAMP TIMESTAMP WITH TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE Data Type

8 INTERVAL YEAR TO MONTHYears and months INTERVAL DAY TO SECONDDays, hours, minutes and seconds Data Type Supported Time Differences

9

10 Select col_date From date_exampleTry it! Select col_date, to_char(col_date, ‘MM/DD/YYYY’) As “Formatted” From date_exampleTry it! TO_DATE does just the opposite of TO_CHAR It converts a text literal into a DATE data type

11

12

13 SELECT last_name, registration_dateTry it! FROM student WHERE registration_date = to_date('22-Jan-2007', 'DD-MON-YYYY') SELECT last_name, registration_dateTry it! FROM student WHERE registration_date = '22-Jan-2007’ SELECT last_name, registration_dateTry it! FROM studentWhy does it work? WHERE registration_date = '22-Jan-07’ Based on how the default date is defined within Oracle

14 SELECT student_id, to_char(enroll_date, 'DD-MON-YYYY HH24:MI:SS') FROM enrollment WHERE trunc(enroll_date) = To_date('07-FEB-2007', 'DD-MON-YYYY') Try it! What happened? Remove trunc. Execute it. What happened? Why?

15

16 Select To_Date(‘01-JAN-2015’, ‘DD-MON-YYYY’) – TRUNC(Sysdate) int, To_Date(‘01-JAN-2015’, ‘DD-MON-YYYY’) – Sysdate dec From dual Before entering this SQL statement, determine what it will do In particular: What does the To_Date function do? What does the TRUNC function do? What is the int used for? What happens if you leave it off? What is the dec used for? What happens if you leave it off? What is the dual table? Why use it? Try it. What happened? Why?

17 Select To_Char(Sysdate, ‘MM/DD HH24:MI:SS’) now, To_Char(Sysdate + 3/24, ‘MM/DD HH24:MI:SS’) As now_plus_3hrs, To_Char(Sysdate + 1, ‘MM/DD HH24:MI:SS’) tomorrow, To_Char(Sysdate + 1.5, ‘MM/DD HH24:MI:SS’) As “36 hrs from now” From dual What happened? Why? Try 1/8 instead of 3/24. Did it work? Why or why not?

18 Select To_Char( start_date_time, ‘DD-MON-YYYY’) “Start Date”, EXTRACT( MONTH FROM start_date_time) “Month”, EXTRACT( YEAR FROM start_date_time ) “Year”, EXTRACT( DAY FROM start_date_time ) “Day” From section WHERE EXTRACT( MONTH FROM start_date_time ) = 4 ORDER BY start_date_time What happened? Why?

19

20

21

22

23  Execute the following SQL statement and notice the result SELECT 60 + 60 + NULL FROM dual Now try this one: SELECT 60 + 60 + NVL(NULL, 1000) FROM dual

24 Select SYSDATE, To_Char( Sysdate, ‘dd-mon-yyyy HH24:MI’ ) From dual; What happened? Why? Select SYSDATE, To_Char( Sysdate, ‘dd- MON -yyyy HH24:MI’ ) From dual Notice the month value. What happened? Why?

25


Download ppt "+, -, *, / Mathematical operators ABS(value) Returns the absolute value SIGN(value) Returns the sign of a value, such as 1, -1, 0 MOD(value,divisor) Returns."

Similar presentations


Ads by Google