+, -, *, / 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.

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL3.
Advertisements

Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
 The DATE data type consists of a date and time.  The default date format is determined by the database NLS_DATE_FORMAT parameter.  To change how a.
Subquery. Subquery or Inner query or Nested query A subquery is a query within another query. The outer query is called as main query and The inner query.
MUCH ADO ABOUT NOTHING Walter Schenk SoluTech Consulting Services Inc.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Using Single-Row Functions to Customize Output
Guide to Oracle10G1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
Using Web Discoverer with AQS ADVANCED Way Poteat & Fletcher Clover USEPA – National Air Data Group 2012 AQS Conference – August 24, 2012 Providence, Rhode.
SQL functions - numeric and date Speaker notes contain additional information!
3-1 Copyright  Oracle Corporation, All rights reserved. SQL Functions FunctionInput arg 1 arg 2 arg n Function performs action OutputResultvalue.
Oracle FUNCTIONS. Comment ScreenShot (in 10g) General Example of null Foreign Key: create table deptcs( deptno NUMBER(4) primary key, hiredate DATE,
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
2-1 Copyright © Oracle Corporation, All rights reserved. Character Strings and Dates Character strings and date values are enclosed in single quotation.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Conversion Functions Implicit datatype conversion Explicit datatype conversion Datatypeconversion In some cases, Oracle Server allows data of one datatype.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
Single Row Functions Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number, date, general and conversion.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
SQL Oracle PL/SQL. Select SELECT column1, column2,...columnN FROM table_name WHERE condition; SELECT column1, column2,...columnN FROM table_name WHERE.
Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
6 Copyright © 2006, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
2-1 Copyright © Oracle Corporation, All rights reserved. Using the NULL Conditions Test for nulls with the IS NULL operator. SELECT last_name, manager_id.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Conversion Functions.
Single Row Functions. Objectives –Use character, number, and date functions –Use conversion functions –Describe types of single row functions in SQL.
Retrieving Data Using the SQL SELECT Statement. Objectives After completing this lesson, you should be able to do the following: – List the capabilities.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 Creating and Maintaining Database Objects Part 1 Database Systems.
INTRODUCTION TO SQL Chapter SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
3 第三讲 Single-Row Functions. Objectives After completing this lesson, you should be able to do the following: Describe various types of functions available.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
SQL Functions. SQL functions are built into Oracle Database and are available for use in various appropriate SQL statements. These functions are use full.
Using Single-Row Functions to Customize Output
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Database Programming Sections 7– Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
Declaring PL/SQL Variables
5 Copyright © 2009, Oracle. All rights reserved. Managing Data in Different Time Zones.
PL/SQL Writing Executable Statements. PL/SQL Block Syntax and Guidelines Statement can be split across lines, but keywords must not be split Lexical units.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Single Row Functions Part I Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number and date SQL functions.
4 Copyright © 2009, Oracle. All rights reserved. Using Conversion Functions and Conditional Expressions.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
CS 3630 Database Design and Implementation
2.5 Another Java Application: Adding Integers
Factoring if/else code
SQL 101 3rd Session.
Using Single-Row Functions to Customize Output
Restricting and Sorting Data
Conditional Logic Presentation Name Course Name
SELECTIONS STATEMENTS
Introduction to Computer Science
Introduction to SQL Server and the Structure Query Language
Temporal Data Part V.
Presentation transcript:

+, -, *, / 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

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

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

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.

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

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

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

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

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?

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?

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?

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?

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

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?