DB2 Function Conversion for Sybase ASE Users

Similar documents
MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

This course is aimed at those who need to extract information from a relational database system.

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya.

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)

Built-in SQL Functions. Chapter 5

Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Single row numeric functions

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 )

Course Outline and Objectives: Database Programming with SQL

Writing PL/SQL Executable Statements. Copyright 2007, Oracle. All rights reserved.

Introduction to Computer Science and Business

What are temporary tables? When are they useful?

CS Week 10 - Page 1

Senturus Analytics Connector. User Guide Cognos to Tableau Senturus, Inc. Page 1

Senturus Analytics Connector. User Guide Cognos to Power BI Senturus, Inc. Page 1

Topics - System Administration for Glovia

COPYRIGHTED MATERIAL. Contents. Chapter 2: Functions: Concept and Architecture 13. Acknowledgments Introduction

Introduction to Functions and Variables

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL

SQL Structured Query Language (1/2)

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing T-SQL and Data Management Systems 1. Chapter 2: SQL Server Fundamentals 23.

MYSQL NUMERIC FUNCTIONS

Oracle Database 12c SQL Fundamentals

How to Configure Pushdown Optimization for an Amazon Redshift Task Using an ODBC Connection

Phụ lục 2. Bởi: Khoa CNTT ĐHSP KT Hưng Yên. Returns the absolute value of a number.

Chapter-14 SQL COMMANDS

SQL Functions (Single-Row, Aggregate)

Arithmetic and Logic Blocks

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Built-in Types of Data

@vmahawar. Agenda Topics Quiz Useful Links

arc tangent, 26 ASIN, 22t, 25 ATAN, 22t, 26 ATAN2, 22t, 26 ATANH, 22t, 26 AVG, 18t

Insert Into Customer1 (ID, CustomerName, City, Country) Values(103, 'Marwa','Baghdad','Iraq')

After completing this unit, you should be able to: Define the terms

How to Design Programs Languages

1001ICT Introduction To Programming Lecture Notes

RDBMS Using Oracle. BIT-4 Lecture Week 3. Lecture Overview

Mentor Graphics Predefined Packages

None of the techniques used till now allows display of data from a after some arithmetic has been done it. Computations may include displaying

CS-201 Introduction to Programming with Java

Installation and Configuration Guide

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017

Index. Boolean expression, , Business rules enforcement. see Declarative constraints table with Oracle constraints and,

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Oracle Syllabus Course code-r10605 SQL


The Expressions plugin PRINTED MANUAL

Installation and Configuration Guide

Oracle Database SQL Basics

SQL Reference Guide. For use with c-treesql Server. This manual describes syntax and semantics of SQL language statements and elements for c-treesql.

Basic types and definitions. Chapter 3 of Thompson

Script started on Thu 25 Aug :00:40 PM CDT

Senturus Analytics Connector Version 3.0. User Guide. Senturus, Inc. 533 Airport Blvd. Suite 400 Burlingame CA P F

Visit for more.

Informix SQL Using New SQL Features

C Functions. 5.2 Program Modules in C

Customizing Built In Formulas

Test: Mid Term Exam Semester 2 Part 1 Review your answers, feedback, and question scores below. An asterisk (*) indica tes a correct answer.

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Oracle Database: SQL and PL/SQL Fundamentals NEW

Transact-SQL Techniques

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

Computational Physics

Long (or LONGMATH ) floating-point (or integer) variables (length up to 1 million, limited by machine memory, range: approx. ±10 1,000,000.

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database 11g: SQL and PL/SQL Fundamentals

Database Programming with SQL

Objectives. You will learn how to process data in ABAP

Downloaded from

Relational Database Language

Unit 4. Scalar Functions and Arithmetic

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Advanced SQL Tribal Data Workshop Joe Nowinski

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

SAS Web Report Studio Performance Improvement

Unit 6. Scalar Functions

Scheme Quick Reference

The Expressions plugin PRINTED MANUAL

LAB 1 General MATLAB Information 1

DB2 SQL Class Outline

Reporting Functions & Operators

Oracle Database: Introduction to SQL Ed 2

Topic 8 Structured Query Language (SQL) : DML Part 2

FORMULAS QUICK REFERENCE

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Dr Richard Greenaway

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries

Scheme Quick Reference

SWITCH(DatePart("w",DateOfYear) IN(1,7),"Weekend",DatePart("w",DateOfYear) IN(2,3,4,5,6),"Weekday") AS DayType,

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

JUN / 04 VERSION 7.0

Basics of ST. Each must end with a semi-colon (";") Basic statement. Q:=IN; Q:=sin(angle); Q := (IN1 + (IN2 / IN 3)) * IN4;

Math 2250 MATLAB TUTORIAL Fall 2005

Using the um-fpu with the Javelin Stamp

MATHEMATICAL / NUMERICAL FUNCTIONS

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

Introduction to GNU-Octave

Functions. Systems Programming Concepts

Transcription:

DB2 Function Conversion for Sybase ASE Users ChangSung KANG, Kitty Lau IMTE Version 1.2 Date: July-01-2011 Page:1 Version: 1.1

Document History Version Date Author Comment Authorization 1.0 07/01/2011 ChangSung KANG Initial Draft 1.1 07/06/2011 Kitty Lau Editing and fixing examples 1.2 07/10/2011 Changsung KANG Modify Function table SECTION I Introduction 1.1 Purpose 1.2 Scope 1.3 Oracle compatibility SECTION II Management Summary 2.1 Overview SECTION III Function Types 3.1 Aggregate Functions 3.2 Date Functions 3.3 Mathematical Functions 3.4 Row Aggregate Functions 3.5 String Functions 3.6 Conversion Functions 3.7 Special Functions APPENDIX Table of Content Page:2 Version: 1.1

SECTION I Introduction 1.1 Purpose This document is a blueprint for converting Sybase ASE SQL functions to DB2 functions. This document is intended to show which functions in Sybase ASE convert to which functions in DB2 v9.7 FP4. 1.2 Scope This document includes the functions in each database and how they equate to each other. 1.3 Oracle compatibility DB2 v9.7 supports Oracle Compatibility which enriches the DB2 user s implementation; therefore this document also involves Oracle style functions. Not only are they one of DB2 s strongest features but they are also part of the new DB2 function set. Page:3 Version: 1.1

SECTION II Management Summary 2.1 Overview This document is intended to help DB2 customers and consultants who are planning on porting or supporting an application onto a DB2 platform from a Sybase platform. In particular this document addresses the functions used by both databases and how they equate. The functions will be broken down into the following areas: Aggregate Generate summary values that appear as new columns in the query results. Count is an example of this type of function. Conversion Change expressions from one data type to another and specify new display formats for date/time information. Date Perform computations on 'datetime' and 'smalldatetime' values and their components, obtain date parts. Mathematical Return values commonly needed for operations on mathematical data. Row Aggregate Generate summary values that appear as additional rows in the query results. Compute is an example of this type of function. String Operate on binary data, character strings, and expressions. Special Functions Functions that do not fall into one of the previous categories. Page:4 Version: 1.1

SECTION III Function Types 3.1 Aggregate Functions The following is a summary of aggregate functions covered in this section: Sybase DB2 Description AVG Same Finds the average of the values in a column. AVG can only be used on numeric data types. COUNT Same Finds the number of non-null values in a column. When distinct is specified, count finds the number of unique non-null values. COUNT(*) Same Finds the number of rows. MAX Same Finds the maximum value in a column. MIN Same Finds the minimum value in a column SUM Same Finds the sum of all of the values in a column. SUM can only be used on numeric data types. N/A STDDEV Finds the standard deviation of an expression (DB2 specific function) N/A VARIANCE Returns the variance of an expression. VARIANCE can only be used on numeric data types. 3.1.1 AVG Finds the average of the values in a column or expression. AVG can only be used on numeric data types. AVG ( [ all distinct ] expression ) select WORKDEPT, avg(salary) from EMP group by workdept WORKDEPT 2 ----------- ------------------------------ A00 70850 B01 94250 C01 77222.5 D11 58783.636363636363636363636363 Page:5 Version: 1.1

... * if you format output, use type functions like int(), dec(). 3.1.2 COUNT cf> dec(avg(salary),9,2) Finds the number of non-null values in a column. When distinct is specified, COUNT finds the number of unique non-null values. COUNT ( [ all distinct ] expression ) 3.1.3 COUNT(*) Finds the number of rows that will be returned by the SELECT statement. COUNT ( * ) select WORKDEPT, count(*) from EMPLOYEE group by workdept... WORKDEPT 2 ----------- ---- A00 5 B01 1 C01 4 3.1.4 MAX Finds the maximum value in a column or expression. MAX ( expression ) select WORKDEPT, max(salary) from EMPLOYEE group by workdept... WORKDEPT 2 ----------- ------ A00 152750 B01 94250 C01 98250 Page:6 Version: 1.1

3.1.5 MIN Finds the minimum value in a column or expression. MIN ( expression ) 3.1.6 SUM Finds the sum of the values in a column or expression. SUM can only be used on numeric data types. SUM ( expression ) select WORKDEPT,sum(salary) from EMPLOYEE group by workdept WORKDEPT 2 ----------- ------ A00 354250 B01 94250 C01 308890... 3.1.7 STDDEV Finds the standard deviation of an expression. This function is not available within Sybase ASE. STDDEV ( expression ) select WORKDEPT,STDDEV(salary) from EMPLOYEE group by workdept WORKDEPT 2 ----------- ------------------ A00 41915.56989950155 B01 0 C01 12337.314081679206 * if you format output, use type functions like int(), dec(). cf> dec(avg(salary),9,2) Page:7 Version: 1.1

3.1.8 VARIANCE Finds the sum of the variance of an expression. VARIANCE can only be used on numeric data types. This function is not available within Sybase ASE. VARIANCE ( [ all distinct ] expression ) select WORKDEPT,variance(salary) from EMPLOYEE group by workdept WORKDEPT 2 ----------- ------------------ A00 1756915000 B01 0 C01 152209318.75... Page:8 Version: 1.1

3.2 Date Functions The following are date manipulation functions from both databases and how they equate: Sybase DB2 Description CONVERT TRUNC, ROUND Used to round or truncate a date value based on the specified format mask. DATEADD DATEDIFF ADD_MONTHS... MONTHS_BET WEEN... Used to return a new date by adding a value to either a day, month or year component. Also can be used to return the first day of the next week. Returns the difference between two dates. DATENAME DAYNAME... Returns the specified part of the date as an integer. Sybase 'datetime' has a higher precision than DB2 'date'. For this reason, it is not always possible to find an equivalent 'format' string in DB2 to match the 'datename' in Sybase. DATEPART DAY, MONTH Returns the specified part of the date as a character string (name). Sybase 'datetime' has a higher precision than DB2 'date'. For this reason, it is not always possible to find an equivalent 'format' string in DB2 to match the 'datepart' in Sybase. GETDATE CURRENT DATE... Returns the system date. LAST_DAY Same Returns the last day in the month of the date value passed. (DB2 specific function). 3.2.1 CONVERT Used to round or truncate a date value based on the specified format mask. Convert has other uses that will be covered later in this document. CONVERT ( desired datatype, date-expression, [ format mask ] ) To round a date value: TRUNC, ROUND ( date-expression ) select current timestamp, trunc(current timestamp ) from sysibm.dual 1 2 -------------------------- -------------------------- 2011-07-02-01.42.37.304000 2011-07-02-00.00.00.000000 Page:9 Version: 1.1

3.2.2 DATEADD Used to return a new date by adding a value to either a day, month or year component. Also can be used to return the first day of the next week. To add a day increment to a date value: DATEADD ( day, integer-expression, date-expression ) Where integer-expression is the number of days to get to Monday from the current day. To add a day increment to a date value: date-expression + integer-expression To add a month increment to a date value: ADD_MONTHS ( date-expression, integer-expression ) To add a day increment to a date value: date-expression + integer-expression day(s) select current date, ADD_MONTHS (current date, 2) from sysibm.dual 1 2 ---------- ---------- 2011. 7. 2 2011. 9. 2 select current date, current date + 2 days from sysibm.dual 1 2 ---------- ---------- 2011. 7. 2 2011. 7. 4 3.2.3 DATEDIFF Returns the difference between two dates. To determine the number of days between dates: DATEDIFF ( day, date-expression, date-expression ) To determine the number of months between dates: DATEDIFF ( month, date-expression, date-expression ) To determine the number of years between dates: Page:10 Version: 1.1

DATEDIFF ( year, date-expression, date-expression ) To determine the number of days between dates: date-expression1 - date-expression2 To determine the number of days between dates: MONTHS_BETWEEN ( date-expression1, date-expression2 ) To determine the number of days between dates: ( date-expression1 - date-expression2 ) / 365.254 select (current date + 2 days) -( current date) from sysibm.dual 1 ---- 2 select MONTHS_BETWEEN (to_date('2011-10-02','yyyy-mm- DD'),current date), current date from sysibm.dual 1 2 ---- ---------- 3 2011. 7. 2 select timestampdiff(256, char(to_date('2013-10-02','yyyy-mm-dd') - current date)), current date from sysibm.dual 1 2 ---- ---------- 2 2011. 7. 2 3.2.4 DATENAME Returns the name of the specified part (such as the month "June") of a DATETIME value, as a character string. Sybase 'datetime' has a higher precision than DB2 'date'. For this reason, it is not always possible to find an equivalent 'format' string in DB2 to match the 'datename' in Sybase. To return the string containing a day in a date expression: DATENAME ( day, date-expression ) To return the name of a month: Page:11 Version: 1.1

DATENAME( month, date-expression ) To return the string containing a day in a date expression: DAYNAME ( date-expression, (locale-name) ) To return the name of a month: MONTHNAME ( date-expression, (locale-name) ) select dayname(current date),dayname(current date, 'ko_kr'), current date from sysibm.dual 1 2 3 -------- ---- ---------- Saturday 토요일 2011. 7. 2 select monthname(current date),monthname(current date, 'ko_kr'), date from sysibm.dual current 1 2 3 ---- ---- ---------- July 7 월 2011. 7. 2 Example: 'TO_CHAR' function which express date format TO_CHAR (TMSTAMP,'Month','en_US') March TO_CHAR (TMSTAMP,'MONTH','en_US') MARCH TO_CHAR (TMSTAMP,'MON','en_US') MAR TO_CHAR (TMSTAMP,'Day','en_US') Friday TO_CHAR (TMSTAMP,'DAY','en_US') FRIDAY TO_CHAR (TMSTAMP,'Dy','en_US') Fri TO_CHAR (TMSTAMP,'Month','de_DE') März TO_CHAR (TMSTAMP,'MONTH','de_DE') MÄRZ TO_CHAR (TMSTAMP,'MON','de_DE') MRZ TO_CHAR (TMSTAMP,'Day','de_DE') Freitag TO_CHAR (TMSTAMP,'DAY','de_DE') FREITAG TO_CHAR (TMSTAMP,'Dy','de_DE') Fr Page:12 Version: 1.1

3.2.5 DATEPART Returns an integer value for the specified part of a DATETIME value. Again, since the Sybase 'datetime' has a higher precision than DB2 'date' there may not be an applicable format string between the two databases. To return the integer value of a day in a date expression: DATEPART ( day, date-expression ) To return the integer value of a month in a date expression: DATEPART ( month, date-expression ) To return the integer value of a day in a date expression: DAY ( date-expression ) To return the integer value of a month in a date expression: MONTH ( date-expression ) select day(current date), sysibm.dual month(current date), current date from 1 2 3 ---- ---- ---------- 2 7 2011. 7. 2 3.2.6 GETDATE Returns the system date. GETDATE () CURRENT DATE, SYSDATE select current date,current time, sysdate from sysibm.dual 1 2 3 ---------- -------- ------------------- 07/02/2011 02:21:42 2011-07-02-02.21.42 3.2.7 LAST_DAY Returns the last day of the month determined by the passed date expression. This is a DB2 specific function. Page:13 Version: 1.1

In Sybase, you must calculate this value by converting a character expression that contains the first day of the next month to a datetime datatype and then use DATEADD with 1 as the integer expression. LAST_DAY ( date-expression ) select last_day(current date), current date from sysibm.dual 1 2 ----------- ---------- 2011. 7. 31 2011. 7. 2 Page:14 Version: 1.1

3.3 Mathematical Functions The following are the mathematical functions from both databases and how they equate: Sybase DB2 Description ABS Same Returns the absolute value of a number. ACOS Same Returns the angle (in radians) whose arc-cosine equals the passed argument. ASIN Same Returns the angle (in radians) whose arc-sine equals the passed argument. ATAN Same Returns the angle (in radians) whose arc-tangent equals the passed argument. ATAN2 Same Returns the angle (in radians) whose tangent equals the division of two passed arguments. CEILING Same Returns the smallest integer that is greater than or equal to the passed numeric argument. CONVERT Same Used to truncate a number to n significant digits. COS Same Returns the cosine of the angle (in radians). COSH Same Returns the hyperbolic cosine of the passed parameter. COT Same Returns the cotangent of then angle (in radians). DEGREES Same Converts radians to degrees. EXP Same Returns the exponential value of the passed parameter. FLOOR Same Returns the largest integer that is less than or equal to the passed numeric argument. LOG LN Returns the natural logarithm of the passed parameter. LOG10 Same Returns the base 10 logarithm of the passed argument. % MOD Returns the remainder or modulus of the division of two numeric arguments. PI N/A Returns the value of pi (3.1415926 ). POWER Same Returns the value of one numeric argument raised to the power of a second numeric argument. RADIANS Same Converts degrees to radians. RAND Same Returns a random number between 0 and 1. ROUND Same Rounds a number to a specified precision. SIGN Same Returns 1 if a passed number is less than zero, 0 if equal to zero, or 1 if positive. Page:15 Version: 1.1

Sybase DB2 Description SIN Same Returns the sine of the passed angle (in radians). SINH Same Returns the hyperbolic sine of the passed angle (in radians). SQRT Same Returns the square root of a number. TAN Same Returns the tangent of the passed angle (in radians). TANH Same Returns the hyperbolic tangent of the passed angle (in radians). 3.3.1 ABS Returns the absolute value of a number-expression. ABS ( number-expression ) 3.3.2 ACOS Returns the arc-cosine of a number expression in radians. ACOS ( number-expression ) 3.3.3 ASIN Returns the arc-sine of a number expression in radians. ASIN ( number-expression ) 3.3.4 ATAN Returns the arc-tangent of a number expression in radians. ATAN ( number-expression ) 3.3.5 ATAN2 Returns the angle (in radians) whose tangent equals the division of two passed arguments. ATAN2 ( number-expression1, number-expression2 ) Page:16 Version: 1.1

3.3.6 CEILING Returns the ceiling (smallest integer not less than) of a numeric expression. CEILING ( number-expression ) CEILING / CEIL ( number-expression ) 3.3.7 COS Returns the cosine of a number expression in radians. COS ( number-expression ) 3.3.8 COSH Returns the hyperbolic cosine of a number expression in radians This function is not implemented in Sybase ASE. COSH ( number-expression ) 3.3.9 CONVERT Truncate a number expression to a specified number of decimal places. CONVERT ( datatype, number-expression * POWER( 10, n ), format-mask of desired number of digits ) / POWER( 10, n ) TRUNC ( number-expression, integer-expression (# of decimal places) ) 3.3.10 COT Returns the cotangent of a number expression in radians. COT ( number-expression ) Page:17 Version: 1.1

3.3.11 DEGREES Converts number expression from radians to degrees. DEGREES ( number-expression ) 3.3.12 EXP Returns the exponential value of a number expression. EXP ( number-expression ) 3.3.13 FLOOR Returns the floor (largest integer not greater than) of numeric expression. FLOOR ( number-expression ) 3.3.14 LOG Returns the natural logarithm of a number expression. LOG ( number-expression ) LN ( number-expression ) 3.3.15 LOG10 Returns the base 10 logarithm of the passed argument. LOG10 ( number-expression ) 3.3.16 % Returns the remainder when dividend is divided by divisor. Division involving a negative dividend will give a negative or zero result. Page:18 Version: 1.1

number-expression (dividend) % number-expression (divisor) MOD ( number-expression (dividend), number-expression (divisor) ) 3.3.17 PI Returns the arithmetic value of pi (3.1415926). PI () This function is not available in DB2 9.7 3.3.18 POWER Returns the value of one numeric argument raised to the power of a second numeric argument. POWER ( number-expression, number-expression (magnitude) ) 3.3.19 RADIANS Converts degrees to radians. RADIANS ( number-expression ) 3.3.20 RAND Returns a random number in the interval 0 to 1, using a number-expression as an optional seed. RAND ( number-expression ) 3.3.21 ROUND Rounds numeric-expression to integer-expression places after the decimal point. A positive integer determines the number of significant digits to the right of the decimal point; a negative integer, the number of significant digits to the left of the decimal point. ROUND ( number-expression, integer-expression ) Page:19 Version: 1.1

3.3.22 SIGN Returns the sign of a number expression. SIGN ( number-expression ) 3.3.23 SIN Returns the sine of a numeric expression, expressed in radians SIN ( number-expression ) 3.3.24 SINH Returns the hyperbolic sine of a numeric expression, expressed in radians This function is not available in Sybase ASE. SINH ( number-expression ) 3.3.25 SQRT Returns the square root of a numeric expression. SQRT ( number-expression ) 3.3.26 TAN Returns the tangent of a numeric expression, expressed in radians TAN ( number-expression ) 3.3.27 TANH Returns the hyperbolic tangent of a numeric expression, expressed in radians Not implemented in Sybase ASE. Page:20 Version: 1.1

TANH ( number-expression ) Page:21 Version: 1.1

3.4 Row Aggregate Functions Row aggregate functions are located at the end of a select statement and the results appear as additional rows in the query. The following are the row aggregate functions in both databases and how they equate: Sybase DB2 Description AVG Same Finds the average of the values in a column. AVG can only be used on numeric data types. COUNT Same Finds the number of non-null values in a column. When distinct is specified, count finds the number of unique non-null values. MAX Same Finds the maximum value in a column. MIN Same Finds the minimum value in a column SUM Same Finds the sum of all of the values in a column. SUM can only be used on numeric data types. 3.4.1 AVG This function is used to find the average of the values in a column or expression. AVG can only be used on numeric data types. AVG ( [ all distinct ] expression ) 3.4.2 COUNT Finds the number of non-null values in a column. When distinct is specified, count finds the number of unique non-null values. COUNT ( [ all distinct ] expression ) 3.4.3 MAX Finds the maximum value in a column or expression. MAX ( expression ) 3.4.4 MIN Finds the minimum value in a column or expression. Page:22 Version: 1.1

3.4.5 SUM MIN ( expression ) Finds the sum of the values in a column or expression. Sum can only be used on numeric data types. SUM ( expression ) Page:23 Version: 1.1

3.5 String Functions The following are the string functions in both databases and how they equate: Sybase DB2 Description ASCII Same Returns the integer ASCII value of the first byte in a string expression, or 0 for the empty string. CHAR Same Returns the character with the ASCII value for a given numeric expression. CHAR_LENGT H LENGTH Computes the length allocated to a string expression, giving the result in number of characters. CHARINDEX INSTR Returns the position where the string-to-search first occurs in the string-expression. CONCAT Same Returns char1 concatenated with char2. DATALENGTH LENGTH Computes the length allocated to an expression, giving the result in bytes. DIFFERENCE SOUNDEX Returns the numeric difference of the SOUNDEX values of two strings. INITCAP INITCAP Returns a string with the first letter of each word in uppercase. ISNULL NVL If the value of the variable is NULL, the new value is returned LEFT SUBSTR Returns the leftmost integer-expression characters from a string expression. LOWER LOWER Converts all characters in a string expression into all lowercase. N/A LPAD Returns source string expression left padded to specified length with the sequence of characters in a second string expression. LTRIM Same Truncates leading spaces from the left end of specified string expression. PATINDEX INSTR ( Returns the position of the pattern in the column value. The pattern can have wild characters. This function also works on TEXT and BINARY data types. REPLICATE REPEAT Produces a string with a character expression repeated a specified amount of times. REVERSE N/A Reverses the passed string expression. RIGHT Same Returns the right-most integer-expression characters from a string-expression. Page:24 Version: 1.1

Sybase DB2 Description N/A RPAD Returns source string expression right padded to specified length with the sequence of characters in char_exp2. RTRIM Same Truncates the trailing spaces from the right end of a string expression. SOUNDEX Same This function allows the user to compare words that are spelled differently. SPACE N/A This function returns a string with the indicated number of single-byte spaces. STR TO_CHAR Returns a character representation of an approximate number STUFF N/A Deletes length characters from a base string expression at a starting point for a specified length then inserts the desired string expression into the base string expression at the starting point. SUBSTRING SUBSTR Returns part of a character starting from a given starting point for a specified length. N/A TRANSLA TE Returns a string expression with all occurrences of each character in a from string expression replaced by its corresponding character in a to string expression. Characters in the base string expression not found in the from string expression are not replaced. UPPER Same Converts all characters in a string expression to uppercase. 3.5.1 ASCII Returns the integer ASCII value of the first byte in a string expression, or 0 for the empty string. ASCII ( string-expression ) 3.5.2 CHAR Converts the decimal code to its corresponding ASCII character. CHAR ( integer-expression ) Page:25 Version: 1.1

3.5.3 CHAR_LENGTH Computes the length allocated to a string expression, giving the result in number of characters. CHAR_LENGTH LENGTH ( string-expression) select length('changsung') from sysibm.dual 1 ---- 9 3.5.4 CHARINDEX Returns the position where the string-to-search first occurs in the string-expression. CHARINDEX ( string-expression, string-to-search ) INSTR ( string-expression, string-to-search ) select INSTR('changsung','s') from sysibm.dual 1 ---- 6 3.5.5 CONCAT Concatenates two string expressions. string-expression-1 + string-expression-2 CONCAT ( string-expression-1, string-expression-2 ) select concat('kang ', 'changsung'), 'KANG ' 'changsung' from sysibm.dual Page:26 Version: 1.1

1 2 -------------- -------------- KANG changsung KANG changsung 3.5.6 DATALENGTH Computes the length allocated to a string expression, giving the result in bytes. DATALENGTH ( string-expression ) LENGTH ( string-expression ) 3.5.7 DIFFERENCE Returns the numeric difference of the SOUNDEX values of the two strings. DIFFERENCE ( string-expression1, string-expression2 ) SOUNDEX( string-expression1 ) SOUNDEX( string-expression2 ) 3.5.8 INITCAP Returns a string with the first letter of each word in uppercase. This must be performed by programmatic means by using Transact- SQL functions to parse the given string and convert the beginning of each word to uppercase. INITCAP ( string-expression ) select initcap ( 'changsung' ) from sysibm.dual 1 --------- Changsung Page:27 Version: 1.1

3.5.9 ISNULL If the value of the variable is NULL, the new value is returned. ISNULL ( data-value, new-value ) NVL ( data-value, new-value ) select nvl ( null, 0 ), nvl ( 1, 0 ) from sysibm.dual 1 2 ---- ---- 0 1 3.5.10 LEFT Returns the leftmost integer-expression characters from a string expression. LEFT ( string-expression, integer-expression ) SUBSTR ( string-expression, 1, integer-length ) select left ('chang',2) from sysibm.dual 1 ---- ch 3.5.11 LOWER Converts all characters in a string expression to lowercase. LOWER ( string-expression ) 3.5.12 LPAD Returns string-expression-1 left padded to a specified length with repeating characters in string-expression-2. REPLICATE( string-expression-2, (integer-expression-datalength(stringexpression-1)) ) + string-expression-1 Page:28 Version: 1.1

LPAD ( string-expression-1, integer-expression, string-expression-2 ) SELECT LPAD(FIRSTNME,15,'.' ) from EMPLOYEE 1 ---------------...CHRISTINE...MICHAEL...SALLY...JOHN 3.5.13 LTRIM Truncates leading spaces from a string expression. LTRIM ( string-expression ) 3.5.14 PATINDEX Returns the position of the pattern in a string expression. The pattern can have wildcard characters. This function also works on TEXT and BINARY data types. PATINDEX ( pattern-string, string-to-search ) (Does NOT accept wildcard characters) INSTR ( string-to-find, string-to-search ) SELECT INSTR(FIRSTNME,'A'), FIRSTNME from EMPLOYEE... 1 FIRSTNME ---- ----------- 0 CHRISTINE 5 MICHAEL 2 SALLY 3.5.15 REPLACE Returns a string with every occurrence of a search-string-expression replaced with a replace-string-expression. Use a combination of PATINDEX() and SUBSTR() Page:29 Version: 1.1

REPLACE ( string-expression, search-string, replace-string ) SELECT replace (FIRSTNME,'C', '$'), FIRSTNME from EMPLOYEE 1 FIRSTNME --------- ----------- $HRISTINE CHRISTINE MI$HAEL MICHAEL 3.5.16 REPLICATE Produces a string with a specified character repeated a desired number of times. REPLICATE ( character, number-expression ) REPEAT ( string-expression, integer-expression) select repeat('chang ',3) from sysibm.dual 1 ------------------ chang chang chang 3.5.17 REVERSE Reverses the characters in a string expression. REVERSE ( string-expression ) Use User Defined Function http://www.ibm.com/developerworks/data/library/samples/db2/0205udfs/index.html 3.5.18 RIGHT Returns the right-most integer-expression characters from a string-expression. RIGHT ( string-expression, integer-expression ) select right ('chang', 2) from sysibm.dual Page:30 Version: 1.1

1 ---- ng 3.5.19 RPAD Returns string-expression-1 right padded to a specified length with repeating characters in string-expression-2. string-expression-1 + REPLICATE( string-expression-2, (integer-expression- DATALENGTH(string-expression-1)) ) RPAD ( string-expression-1, integer-expression, string-expression-2 ) SELECT RPAD (FIRSTNME,15, '$'), FIRSTNME from EMPLOYEE... 1 FIRSTNME --------------- ----------- CHRISTINE$$$$$$ CHRISTINE MICHAEL$$$$$$$$ MICHAEL SALLY$$$$$$$$$$ SALLY JOHN$$$$$$$$$$$ JOHN 3.5.20 RTRIM Truncates the trailing spaces from the right end of a string expression. RTRIM ( string-expression ) select rtrim ('chang ') sung from sysibm.dual 1 ----- changsung 3.5.21 SOUNDEX Returns a number representing the sound of a string expression. Page:31 Version: 1.1

SOUNDEX ( string-expression ) SELECT EMPNO, LASTNAME FROM EMPLOYEE WHERE SOUNDEX(LASTNAME) = SOUNDEX('Loucesy') EMPNO LASTNAME -------- ----------- 000110 LUCCHESSI 3.5.22 SPACE This function returns a string of a specified number of single-byte spaces. SPACE ( integer-expression ) The DB2 REPEAT() and LPAD/RPAD() functions can be used to duplicate the functionality of SPACE() in Sybase ASE. select chang repeat(' ', 10) sung from sysibm.dual 1 ---------- chang sung 3.5.23 STR Returns a string representing the passed numeric argument. STR ( number-expression, integer-expression (length), integer-expression (decimals) ) TO_CHAR ( number-expression, format-string ) SELECT lastname, TO_CHAR(salary, '9999,99') SALARY from EMPLOYEE LASTNAME SALARY ----------- ----------- HAAS 1527,50 THOMPSON 942,50 KWAN 982,50 Page:32 Version: 1.1

... GEYER 801,75 STERN 722,50 Example: 'TO_CHAR' function which express number type format Function invocation Result ------------------- ------ TO_CHAR(POSNUM) '1234.56' TO_CHAR (NEGNUM) '-1234.56' TO_CHAR (POSNUM,'9999.99') '1234.56' TO_CHAR (NEGNUM,'9999.99') '1234.56' TO_CHAR (POSNUM,'99999.99') ' 1234.56' TO_CHAR (NEGNUM,'99999.99') ' 1234.56' TO_CHAR (POSNUM,'00000.00') '01234.56' TO_CHAR (NEGNUM,'00000.00') '01234.56' TO_CHAR (POSNUM,'9999.99MI') '1234.56 ' TO_CHAR (NEGNUM,'9999.99MI') '1234.56-' TO_CHAR (POSNUM,'S9999.99') '+1234.56' TO_CHAR (NEGNUM,'S9999.99') '-1234.56' TO_CHAR (POSNUM,'9999.99PR') ' 1234.56 ' TO_CHAR (NEGNUM,'9999.99PR') '<1234.56>' TO_CHAR (POSNUM,'S$9,999.99') '+$1,234.56' 3.5.24 STUFF Deletes characters from string-expression-1 at a specified starting position for a desired length then inserts string-expression-2 into string-expression-1 at the starting position. STUFF ( string-expression-1, integer-expression (start), integer-expression (length), string-expression-2 ) This operation can be simulated by using a combination of the LENGTH(), SUBSTR(), and CONCAT() functions [Sybase] SELECT STUFF ('chang', 1, 3, 'KKK') column1 ---------- KKKng [DB2] select FIRSTNME, 'KKK' (substr(firstnme,4, length(firstnme) )) FROM EMPLOYEE FIRSTNME 2 ----------- ------------ Page:33 Version: 1.1

.. CHRISTINE MICHAEL SALLY JOHN IRVING KKKISTINE KKKHAEL KKKLY KKKN KKKING 3.5.25 SUBSTRING Returns part of a string expression starting at a specified starting position for a desired length of characters. SUBSTRING ( string-expression, integer-start, integer-length ) SUBSTR ( string-expression, integer-start, integer-length ) To specify the desired result length in bytes: SUBSTRB ( string-expression, integer-start, integer-length ) select substr(firstnme,1, 4) FROM EMPLOYEE 1 ---- CHRI MICH SALL JOHN 3.5.26 TRANSLATE Returns a string expression with all occurrences of each character in a from string expression replaced by its corresponding character in a to string expression. Characters in the base string expression not found in the from string expression are not replaced. Use a combination of PATINDEX() and SUBSTRING() TRANSLATE ( string-expression, to-string-expression, from-string-expression ) select translate ('Hanauma Bay', 'r', 'Bu') from sysibm.dual Page:34 Version: 1.1

1 ---------- Hanama ray 3.5.27 UPPER Converts all characters in a string expression to uppercase. UPPER ( string-expression ) Page:35 Version: 1.1

3.6 Conversion Functions The following are the conversion functions in both databases and how they equate: Sybase DB2 Description convert (datatype, expression, [format]) convert ( datatype, expression, [format]) convert ( datatype, expression, [format]) convert ( datatype, expression, [format]) str (approx_number, length, decimal) hextoint (hexstring) inttohex (integer) convert (char, dest_char_set, source_char_set) to_char (data, format) to_date (char, format) to_number (char, format) to_char (approx_num, format) Converts a character string from one character set to another. Converts data to character datatype based on format. Converts char to timestamp datatype based on format. Converts a char to a number based on format. Returns a character representation of the approx_num. Returns a platform independent integer equivalent of a hexadecimal sting. Returns a platform independent hexadecimal equivalent. Page:36 Version: 1.1

3.7 Special Functions 3.7.1 DECODE DB2 has not only ANSI SQL 'CASE' statement not also a non-ansi SQL extension called DECODE. DECODE function evaluates a field and returns it in as a set of possible values. The DECODE function syntax is a follows: DECODE (expr, search, result, search2, result2,..., default) The expression is evaluated and if its value equals one of the search values it is replaced with the result value. Otherwise it is replaced with the default value. In Sybase a SELECT statement may appear anywhere that a column specification appears. For the following SALES table: year qtr amount 1993 1 1.3 1993 2 1.4 1993 3 3.0 1993 4 2.3 In Sybase: If you want to select the year, q1 amount, q2 amount, q3 amount and q4 as a row. Sybase 4.X accepts the following query: SELECT distinct year, FROM sales s; q1 = (SELECT amt FROM sales WHERE qtr=1 AND year = s.year), q2 = (SELECT amt FROM sales WHERE qtr=2 AND year = s.year), q3 = (SELECT amt FROM sales WHERE qtr=3 AND year = s.year), q4 = (SELECT amt FROM sales WHERE qtr=4 AND year = s.year) Page:37 Version: 1.1

In DB2: In this example, replace the SELECT statement with DECODE. Then the query would function as normal. The DECODE function is much faster than Sybase subqueries. Translate the above query to the following for DB2: SELECT year, DECODE( qtr, 1, amt, 0 ) q1, DECODE( qtr, 2, amt, 0 ) q2, DECODES qtr, 3, amt, 0 ) q3, DECODE( qtr, 4, amt, 0 ) q4 FROM sales s; Page:38 Version: 1.1

APPENDIX [Table] DB2 Sample Database Schema Page:39 Version: 1.1

[Sample UDFs for Migration] http://www.ibm.com/developerworks/data/library/samples/db2/0205udfs/index.html [Porting to DB2 from Sybase Adaptive Server or Microsoft SQL Server 2000] http://www.ibm.com/developerworks/data/library/techarticle/0203rada/0203rada.html [Summary] Mapping functions Sybase vs DB2 Function Mapping Information: Aggregate NO SYBFUNC DB2FUNC REMARKS CATEGORY 1 AVG AVG NO CHANGE AGGREGATE 2 COUNT COUNT NO CHANGE AGGREGATE 3 MAX MAX NO CHANGE AGGREGATE 4 MIN MIN NO CHANGE AGGREGATE 5 SUM SUM NO CHANGE AGGREGATE Sybase vs DB2 Function Mapping Information: Conversion NO SYBFUNC DB2FUNC REMARKS CATEGORY 6 HEXTOINT - NO EQUIVALENT CONVERSION 7 INTTOHEX HEX PARTIALLY EQUIVALENT CONVERSION 8 ONVERT PC CHANGE CONVERSION Page:40 Version: 1.1

Sybase vs DB2 Function Mapping Information: Date NO SYBFUNC DB2FUNC REMARKS CATEGORY 9 DATEADD - DATE ARITHMETIC DATE 10 DATEDIFF - DATE ARITHMETIC DATE 11 DATENAME - DATE ARITHMETIC DATE 12 DATEPART - DATE ARITHMETIC DATE 13 GETDATE CURRENT TIMESTAMP CHANGE DATE Sybase vs DB2 Function Mapping Information: Mate NO SYBFUNC DB2FUNC REMARKS CATEGORY 14 ABS ABS NO CHANGE MATH 15 ACOS ACOS NO CHANGE MATH 16 CEILING CEILING NO CHANGE MATH 17 COS COS NO CHANGE MATH 18 COT COT NO CHANGE MATH 19 DEGREES DEGREES NO CHANGE MATH 20 EXP EXP NO CHANGE MATH 21 FLOOR FLOOR NO CHANGE MATH 22 LOG LOG NO CHANGE MATH 23 LOG10 LOG10 NO CHANGE MATH 24 PI - NO EQUIVALENT MATH 25 POWER POWER NO CHANGE MATH 26 RADIANS RADIANS NO CHANGE MATH Page:41 Version: 1.1

27 RAND RAND NO CHANGE MATH 28 ROUND ROUND NO CHANGE MATH 29 SIGN SIGN NO CHANGE MATH 30 SIN SIN NO CHANGE MATH 31 SQRT SQRT NO CHANGE MATH 32 SQUARE - NO EQUIVALENT MATH 33 TAN TAN NO CHANGE MATH Sybase vs DB2 Function Mapping Information: Security NO SYBFUNC DB2FUNC REMARKS CATEGORY 34 IS_SEC_SERVICE_ON - NO EQUIVALENT SECURITY 35 MUT_EXCL_ROLES - NO EQUIVALENT SECURITY 36 PROC_ROLE - NO EQUIVALENT SECURITY 37 ROLE_CONTAIN - NO EQUIVALENT SECURITY 38 ROLE_ID - NO EQUIVALENT SECURITY 39 ROLE_NAME - NO EQUIVALENT SECURITY 40 SHOW_ROLE - NO EQUIVALENT SECURITY 41 SHOW_SEC_SERVICES - NO EQUIVALENT SECURITY Sybase vs DB2 Function Mapping Information: String NO SYBFUNC DB2FUNC REMARKS CATEGORY 42 ASCII ASCII NO CHANGE STRING 43 CHAR CHR CHANGE STRING Page:42 Version: 1.1

44 CHARINDEX POSSTROR LOCATE CHANGE STRING 45 CHAR_LENGTH LENGTH NO CHANGE STRING 46 DIFFERENCE DIFFERENCE NO CHANGE STRING 47 LOWER LOWER NO CHANGE STRING 48 LTRIM LTRIM NO CHANGE STRING 49 PATINDEX POSSTR CHANGE STRING 50 REPLICATE REPEAT CHANGE STRING 51 REVERSE - NO EQUIVALENT STRING 52 RIGHT RIGHT NO CHANGE STRING 53 RTRIM RTRIM NO CHANGE STRING 54 SOUNDEX SOUNDEX NO CHANGE STRING 55 SPACE SPACE NO CHANGE STRING 56 STR CHAR PARTLY EQUIVALENT STRING 57 STUFF INSERT CHANGE STRING 58 SUBSTRING SUBSTR CHANGE STRING Sybase vs DB2 Function Mapping Information: System NO SYBFUNC DB2FUNC REMARKS CATEGORY 59 COL_LENGTH - NO EQUIVALENT SYSTEM 60 COL_SIZE - NO EQUIVALENT SYSTEM 61 CURUNRESERVEDPGS - NO EQUIVALENT SYSTEM 62 DATALENGTH LENGTH CHANGE SYSTEM 63 DATA_PGS - NO EQUIVALENT SYSTEM Page:43 Version: 1.1

64 DB_ID - NO EQUIVALENT SYSTEM 65 DB_NAME - NO EQUIVALENT SYSTEM 66 HOST_ID - NO EQUIVALENT SYSTEM 67 HOST_NAME - NO EQUIVALENT SYSTEM 68 ICT_ADMIN - NO EQUIVALENT SYSTEM 69 INDEX_COL - NO EQUIVQLENT SYSTEM 70 ISNULL COALESCE NO CHANGE SYSTEM 71 OBJECT_ID - NO EQUIVALENT SYSTEM 72 OBJECT_NAME - NO EQUIVALENT SYSTEM 73 PTN_DATA_PGS - NO EQUIVALENT SYSTEM 74 RESERVED_PGS - NO EQUIVALENT SYSTEM 75 ROWCNT - NO EQUIVALENT SYSTEM 76 SUSER_ID - NO EQUIVALENT SYSTEM 77 SUSER_NAME CURRENT USER CHANGE SYSTEM 78 TSEQUAL - NO EQUIVALENT SYSTEM 79 USED_PGS - NO EQUIVALENT SYSTEM 80 USER CURRENT USER CHANGE SYSTEM 81 USER_ID - NO EQUIVALENT SYSTEM 82 USER_NAME CURRENT USER CHANGE SYSTEM 83 VALID_NAME - NO EQUIVALENT SYSTEM 84 VALID_USER - NO EQUIVALENT SYSTEM Page:44 Version: 1.1

Sybase vs DB2 Function Mapping Information: Text SYBFUNC DB2FUNC REMARKS CATEGORY TEXTPTR - NO EQUIVALENT TEXT TEXTVALID - NO EQUIVALENT TEXT * DB2 LOB-locator replaces with this feature. Page:45 Version: 1.1