Key Functions in Oracle SQL



Similar documents
Programming with SQL

Date / Time Arithmetic with Oracle

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Oracle SQL. Course Summary. Duration. Objectives

CONVERSION FUNCTIONS QUESTIONS

Conversion Functions

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database 12c: Introduction to SQL Ed 1.1

Excel: Introduction to Formulas

Single-Row Functions Schedule: Timing Topic

3.GETTING STARTED WITH ORACLE8i

Query Expressions Function Definitions and Examples

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Ad Hoc Advanced Table of Contents

Oracle Database 11g SQL

Using Single-Row Functions to Customize Output. Copyright 2006, Oracle. All rights reserved.

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Handling Missing Values in the SQL Procedure

Oracle Database: SQL and PL/SQL Fundamentals NEW

STRING, CONVERSION, AND MISCELLANEOUS FUNCTIONS

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

DATABASE DESIGN & PROGRAMMING WITH SQL COURSE CODE: 5324

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL

Advanced Tutorials. The Dark Side of the Transparent Moon

Oracle/SQL Tutorial 1

2. Which three statements about functions are true? (Choose three.) Mark for Review (1) Points

1 Stored Procedures in PL/SQL 2 PL/SQL. 2.1 Variables. 2.2 PL/SQL Program Blocks

Instant SQL Programming

IT2305 Database Systems I (Compulsory)


Netezza SQL Class Outline

Relational Database: Additional Operations on Relations; SQL

Appendix A Practices and Solutions

Advanced Query for Query Developers

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

SQL SELECT Query: Intermediate

IT2304: Database Systems 1 (DBS 1)

T-SQL STANDARD ELEMENTS

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

USING CONVERSION FUNCTIONS

Analysis One Code Desc. Transaction Amount. Fiscal Period

Agenda. 1. Tom Rosenburg, General Motors Maximizing Ad Hoc Reporting with the Application Where Clause

A basic create statement for a simple student table would look like the following.

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Introduction to Microsoft Jet SQL

HATRIS JTDB Query Tool

Oracle Database 10g: Introduction to SQL

LESSON PLANS FOR PERCENTAGES, FRACTIONS, DECIMALS, AND ORDERING Lesson Purpose: The students will be able to:

REPORT GENERATION USING SQL*PLUS COMMANDS

5.1 Database Schema Schema Generation in SQL

Advance DBMS. Structured Query Language (SQL)

What's New in ADP Reporting?

TO_CHAR Function with Dates

Number boards for mini mental sessions

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

Database Programming with PL/SQL: Learning Objectives

PL / SQL Basics. Chapter 3

Using SQL Server Management Studio

Aggregating Data Using Group Functions

Kaseya 2. Quick Start Guide. for VSA 6.3

QlikView 11.2 SR5 DIRECT DISCOVERY

DBMS / Business Intelligence, SQL Server

Oracle For Beginners Page : 1

Porting from Oracle to PostgreSQL

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Addition Methods. Methods Jottings Expanded Compact Examples = 15

IBM Unica Macros for IBM Unica Marketing Version 8 Release 6 May 25, User's Guide

Database Applications Microsoft Access

Achieving Database Interoperability Across Data Access APIs through SQL Up-leveling

Chapter 1 Overview of the SQL Procedure

Tips to Use Character String Functions in Record Lookup

Oracle Rdb A Comparison of SQL Dialects for Oracle and Oracle Rdb

Financial Data Access with SQL, Excel & VBA

Computer Science 281 Binary and Hexadecimal Review

9.1 SAS. SQL Query Window. User s Guide

Access Part 2 - Design

Managing Users and Identity Stores

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

Lecture 2. Binary and Hexadecimal Numbers

SAP BusinessObjects Business Intelligence platform Document Version: 4.1 Support Package Information Design Tool User Guide

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves

Participant Guide RP301: Ad Hoc Business Intelligence Reporting

SQL Basics. Introduction to Standard Query Language

Microsoft Access 3: Understanding and Creating Queries

SAP BusinessObjects Business Intelligence platform Document Version: 4.1 Support Package Information Design Tool User Guide

Transcription:

Page 1 of 6 Key Functions in Oracle SQL Use this Quick Reference Guide to locate functions you can use in your queries. There are five tables in this guide: Grouping Functions, Numeric Functions, String Functions, Date Functions, and Conversion Functions. Grouping functions may include either of the keywords DISTINCT or ALL. ALL is the default if neither is specified and uses all selected rows in the calculation. DISTINCT uses only one row for each value in the calculation. AVG(ALL 2,2,3,3,4) and AVG(2,2,3,3,4) both return 2.8. AVG(DISTINCT 2,2,3,3,4) returns 3. Grouping AVG(expression) COUNT(expression) or COUNT(*) MAX(expression) MAX(tub_last_update_dt) DD004QR3 - Key Functions In Oracle SQL.Doc Returns the average of the values in a set of rows AVG(endowment_unit_value) Returns the number of rows in the set Note: If you include an expression, COUNT returns only the number of rows in which the expression is not null. COUNT(*) counts all rows. Since no HDW table contains nulls, COUNT(expression) and COUNT(*) are equivalent. COUNT(*) COUNT(DISTINCT univ_id_no) Returns the largest value from a set of rows Note: See the GREATEST function if you want the largest of a series of values in a single row. Example (returns the date on which the most recent change was made to dwfnd_rf_tub_cds): 4-1

Page 2 of 6 Grouping Functions (continued) Grouping MIN(expression) Returns the smallest value from a set of rows Note: See the LEAST function if you want the smallest of a series of values in a single row. Example (returns the lowest rate used for fringe-benefit assessments): MIN(fringe_assessment_rate) SUM(expression) Adds the value for all rows in the query or for all rows with the same values for columns listed in the GROUP BY clause SUM(pcard_transaction_distr_amt) Numeric ABS(number) Removes the sign, if any, returning a positive value Example (selects actual_amt values above 10,000 and below 10,000): ABS(actual_amt) > 10000 GREATEST(value1, value2, ) Returns the largest of the values in the list Note: This function is used for multiple values in the same row. See the MAX function if you want the largest value from a group of rows. GREATEST(pcard_dt_modified, pcard_dt_reviewed) LEAST(value1, value2, ) Returns the smallest of the values in the list Note: This function is used for multiple values in the same row. See the MIN function if you want the smallest value from a group of rows. LEAST(pcard_dt_modified, pcard_dt_reviewed, pcard_swept_dt) 4-2 DD004QR3 - Key Functions In Oracle SQL.Doc

Page 3 of 6 Numeric Functions (continued) Numeric ROUND(number, decimal places) Rounds a value to the specified number of decimal places ROUND(123.456,2) returns 123.46 ROUND(234567.00,-3) returns 235000 TRUNC(number, decimal places) Cuts off a value at the specified number of decimal places TRUNC(123.456,2) returns 123.45 TRUNC(234567.00,-3) returns 234000 String Functions and string string Concatenates string values Note: The equivalent CONCAT function accepts only two arguments and is more confusing in queries. vendor_city, vendor_state vendor_postal_cd INITCAP(string) Converts a string to initial capital letters Note: This function will convert a, an, and the to A, An, and The. INITCAP(vendor_name) LENGTH(string) Returns the number of characters in a string LENGTH(full_name) LOWER(string) Converts a string to all lowercase characters LOWER(view_name) DD004QR3 - Key Functions In Oracle SQL.Doc 4-3

Page 4 of 6 String Functions (continued) String Functions and SUBSTR(string, starting value, number of characters) Extracts a portion of a string Note: If the starting value is 0, it is treated as 1. If the starting-value is negative, Oracle counts backward from the end of the string. If the starting value is positive, Oracle counts forward from the beginning of the string. SUBSTR( ABCDEF,2,3) returns BCD SUBSTR( abcdef,-4,3) returns cde UPPER(string) Converts a string to all uppercase characters WHERE UPPER(lodging_location) LIKE %CHICAGO% Date Functions and ADD_MONTHS (date, number of months) Adds the specified number of months to the date value (subtracts months if the number of months is negative) Note: If the result would be a date beyond the end of the month, Oracle returns the last day of the resulting month. Example (selects expense reports not settled for more than two months after trip end): WHERE report_gl_export_dt > ADD_MONTHS(report_ trip_end_or_expense_dt, 2) LAST_DAY(date) Returns the last day of the month that contains the date Example (returns 29-FEB-2000 ): LAST_DAY( 15-FEB-2000 ) 4-4 DD004QR3 - Key Functions In Oracle SQL.Doc

Page 5 of 6 Date Functions (continued) Date Functions and MONTHS_ BETWEEN(date1, date2) NEXT_DAY(date, day name) ROUND (datetime, SYSDATE TRUNC(datetime) Returns the difference between two dates expressed as whole and fractional months Note: If date1 is earlier than date2, the result is negative. The result also takes into account time differences between the two values. Example (returns 1.03225806): MONTHS_BETWEEN( 02-FEB-2001, 01-JAN-2001 ) Returns the date of the first day of the specified name that is later than the date supplied Example (returns 20-MAR-2001 ): NEXT_DAY( 14-MAR-2001, TUESDAY ) Returns the date-time rounded to the unit specified by the format, or to the nearest day if no format is supplied Note: For details on available formats, see the full description of functions (below). (returns 01-JAN-2000 ) ROUND( 27-OCT-1999, YEAR ) Returns the current date-time from the server where the database is located Example (returns rows posted the previous day): WHERE je_posted_dt = TRUNC(SYSDATE) 1 Removes the time component from a date-time value Note: This function has other truncating options. See the full description of functions (below) for details. WHERE TRUNC(je_posted_dt) = 12-OCT-99 DD004QR3 - Key Functions In Oracle SQL.Doc 4-5

Page 6 of 6 Conversion TO_CHAR(date, TO_CHAR(number, TO_DATE(string, TO_NUMBER (string, Converts a date to a string in the specified format Note: For details on available formats, see the full description of functions (below). TO_CHAR(je_posted_dt, Month DD, YYYY ) Converts a number to a string in the specified format TO_CHAR(fund_spec_invest_amt, $9,999,999 ) Converts a string to a date using the specified format Note: Oracle automatically converts dates in the standard format of DD-MON-YYYY. TO_DATE( 01-02-1999, DD-MM-YYYY ) Converts a string to a number using the optional format if specified Note: For details on available formats, see the full description of functions (below). TO_NUMBER( 100.00, 9G999D99 ) TO_NUMBER(TO_CHAR(je_posted_dt, YYYY )) This list includes only the most commonly used Oracle functions. To download the full descriptions of all Oracle functions, navigate to the Forms section of ABLE and choose Ad-Hoc Reporting Forms, then Oracle Manuals. 4-6 DD004QR3 - Key Functions In Oracle SQL.Doc