db2 sql query

188
DB2 SQL QUERY By Hari Christian

Upload: harichristian

Post on 21-Jul-2016

93 views

Category:

Documents


2 download

DESCRIPTION

DB2 SQL QUERY

TRANSCRIPT

Page 1: Db2 SQL Query

DB2 SQL QUERYBy Hari Christian

Page 2: Db2 SQL Query

Agenda

• Introduction to Database and SQL

• Basic SQL

• Advance SQL

Page 3: Db2 SQL Query

What Is Database

• A database is an organized way of holding together various pieces of information. The term database actually refers to the collection of data, not the means by which it is stored.

• For a computer database, the software used to manage the data is known as a database-management system (DBMS).

Page 4: Db2 SQL Query

What Is Database

• A filing cabinet and a telephone directory both contain databases: They hold information, organized in a structured manner so that you can easily access the individual item you want to find.

Page 5: Db2 SQL Query

What Is Database

• A database consists of a series of tables. Each table has a name, which is how it is referenced in the SQL language. Each database also has a name, and the same RDBMS can manage many different databases.

• DB2 is a multiuser database and can restrict access to each database to only specific users.

Page 6: Db2 SQL Query

What Is Database

• A database table looks somewhat like a spreadsheet: a set of rows and columns that can contain data at each intersection. In a relational database, you store different types of data in different tables.

• For instance, the sample database in this book has separate tables for customers, products, and orders.

Page 7: Db2 SQL Query

What Is Database

• Each table has a defined set of columns, which determine the values it can store. For example, the table that contains information about products needs to store a name, price, and weight for every product.

• Each row of data can contain values for only the columns defined in the table.

Page 8: Db2 SQL Query

What Is Database

• In addition, each column is defined as a particular data type, which determines the kind of values it can store.

• The data type might restrict values to numeric or date values, or it might impose a maximum size.

Page 9: Db2 SQL Query

What Is SQL

• The Structured Query Language (SQL) is the most common way to retrieve and manage database information.

• An SQL query consists of a series of keywords that define the data set you want to fetch from the database.

• SQL uses descriptive English keywords, so most queries are easy to understand.

Page 10: Db2 SQL Query

Retrieve Data

• The first SQL command you will learn, and the one you will use most frequently, is SELECT. In this lesson, you begin by learning how to fetch data records from a single table.

Page 11: Db2 SQL Query

Retrieve Data

• A SELECT statement begins with the SELECT keyword and is used to retrieve information from database tables.

• You must specify the table name to fetch data from, using the FROM keyword and one or more columns that you want to retrieve from that table.

Page 12: Db2 SQL Query

Retrieve Data

• Query FormatSELECT [COLUMN_NAME] FROM [TABLE_NAME];

Page 13: Db2 SQL Query

Retrieve Single Column

• Display column NMDOSEN name from table QRYLIB.AGSDOS

• SELECT NMDOSEN FROM QRYLIB.AGSDOS;

Page 14: Db2 SQL Query

Retrieve Multiple Column

• Display column KDDOSEN and NMDOSEN name from table QRYLIB.AGSDOS

• SELECT KDDOSEN, NMDOSEN FROM QRYLIB.AGSDOS;

Page 15: Db2 SQL Query

Retrieve All Column

• Display all column from table QRYLIB.AGSDOS

• SELECT * FROM QRYLIB.AGSDOS;

Page 16: Db2 SQL Query

Retrieve Common Mistake

• File or table not found

• SELECT * FROM QRYLIB.AGSDOSS;

Page 17: Db2 SQL Query

Retrieve Common Mistake

• Column not in specified table

• SELECT NAME FROM QRYLIB.AGSDOS;

Page 18: Db2 SQL Query

Retrieve Exercise

• Retrieve Student Name from QRYLIB.AGSMHS

• Retrieve Student ID and Student Name from QRYLIB.AGSMHS

• Retrieve All column from QRYLIB.AGSMHS

Page 19: Db2 SQL Query

Retrieve Exercise

• Retrieve from QRYLIB.AGSMTKUL

• Retrieve from QRYLIB.AGSNIL

Page 20: Db2 SQL Query

Filtering Data

• You can add a WHERE clause to a SELECT statement to tell DB2 to filter the query results based on a given rule.

• Rules in a WHERE clause refer to data values returned by the query, and only rows in which the values meet the criteria in the rule are returned.

Page 21: Db2 SQL Query

Filtering Data

• Query FormatSELECT [COLUMN_NAME] FROM [TABLE_NAME] WHERE [COLUMN_NAME] [OPERATOR]

[FILTER_CRITERIA];

Page 22: Db2 SQL Query

Filtering Exact Value

• Display all information from lecturer D01

• SELECT * FROM QRYLIB.AGSDOS WHERE KDDOSEN = ‘D01’;

Page 23: Db2 SQL Query

Filtering Except Value

• Display all lecturer information except lecturer D01

• SELECT * FROM QRYLIB.AGSDOS WHERE KDDOSEN != ‘D01’;

Page 24: Db2 SQL Query

Filtering Range Value

• Display student test with score equal 70

• SELECT * FROM QRYLIB.AGSNIL WHERE NILAI = 70;

Page 25: Db2 SQL Query

Filtering Range Value

• Display student test with score greater than 70

• SELECT * FROM QRYLIB.AGSNIL WHERE NILAI > 70;

Page 26: Db2 SQL Query

Filtering Range Value

• Display student test with score greater than or equal 70

• SELECT * FROM QRYLIB.AGSNIL WHERE NILAI >= 70;

Page 27: Db2 SQL Query

Filtering Range Value

• Display student test with score less than 70

• SELECT * FROM QRYLIB.AGSNIL WHERE NILAI < 70;

Page 28: Db2 SQL Query

Filtering Range Value

• Display student test with score less than or equal 70

• SELECT * FROM QRYLIB.AGSNIL WHERE NILAI <= 70;

Page 29: Db2 SQL Query

Filtering Common Mistake

• Missing quotes (filtering character requires quotes)

• SELECT * FROM QRYLIB.AGSDOS WHERE KDDOSEN = D01;

Page 30: Db2 SQL Query

Filtering Exercise

• Display all lecturer data with name start with B

• Display all lecturer data with name start with E

• Display lecturer D03 information• Display student data score more than 50• Display student data score more than or

equal 60

Page 31: Db2 SQL Query

Ordering Data

• So far, you have seen that data is fetched from the database in no particular order.

• To specify the sorting on the result of a query, you can add an ORDER BY clause.

Page 32: Db2 SQL Query

Ordering Data

• Query FormatSELECT [COLUMN_NAME] FROM [TABLE_NAME] ORDER BY [COLUMN_NAME];

Page 33: Db2 SQL Query

Ordering Single Column

• Display all student information sort by code

• SELECT * FROM QRYLIB.AGSMHS ORDER BY KDMHS;

Page 34: Db2 SQL Query

Ordering Multiple Column

• Display all student information sort by code and name

• SELECT * FROM QRYLIB.AGSMHS ORDER BY KDMHS, NMMHS;

Page 35: Db2 SQL Query

Ordering Ascending

• Display all student information sort by code (A-Z)

• SELECT * FROM QRYLIB.AGSMHS ORDER BY KDMHS ASC;

Page 36: Db2 SQL Query

Ordering Descending

• Display all student information sort by code (Z-A)

• SELECT * FROM QRYLIB.AGSMHS ORDER BY KDMHS DESC;

Page 37: Db2 SQL Query

Ordering Exercise

• Display all student score with lowest score to highest score (0 - 100)

• Display all student score with highest score to lowest score (100 - 0)

• Display all student score with highest score to lowest score (100 - 0) and sort by student name (Z-A)

Page 38: Db2 SQL Query

Advance Filtering

• The examples you have seen so far perform filtering on a query based on only a single condition.

• To provide greater control over a result set, MySQL enables you to combine a number of conditions in a WHERE clause.

• They are joined using the logical operator keywords AND and OR.

Page 39: Db2 SQL Query

Advance Filtering - AND

• Display student data with score greater than or equal 70 and course id is M01

• SELECT *FROM QRYLIB.AGSNILWHERE NILAI >= 70 AND KDMTK = ‘M01’;

Page 40: Db2 SQL Query

Advance Filtering - OR

• Display student data with score greater than or equal 70 or course id is M01

• SELECT *FROM QRYLIB.AGSNILWHERE NILAI >= 70 OR KDMTK = ‘M01’;

Page 41: Db2 SQL Query

Advance Filtering - IN

• Display lecture data D03 and D01

• SELECT * FROM QRYLIB.AGSDOS WHERE KDDOSEN IN ('D03', 'D01');

WHERE KDDOSEN = 'D03‘ AND KDDOSEN = 'D01';

Page 42: Db2 SQL Query

Advance Filtering – NOT IN

• Display lecture data except D03 and D01

• SELECT * FROM QRYLIB.AGSDOS WHERE KDDOSEN NOT IN ('D03', 'D01');

Page 43: Db2 SQL Query

Advance Filtering – BETWEEN

• Display employees who were born between 1920 - 1940

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE BIRTHDATE BETWEEN '1920-01-01' AND '1940-01-01';

Page 44: Db2 SQL Query

Advance Filtering – Case

• Display employee bonus remark• SELECT EMPNO, FIRSTNME, BONUS,

CASEWHEN BONUS > 800 THEN 'BESAR'WHEN BONUS > 400 THEN 'SEDANG'ELSE 'KECIL'END AS RANKINGFROM OL37V3COL.EMPLOYEE;

Page 45: Db2 SQL Query

Precedence

• Display all manager with first name is Michael or John (see if the result are correct?)

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE JOB = 'MANAGER' AND FIRSTNME = 'Michael' OR FIRSTNME = 'John' ORDER BY FIRSTNME;

Page 46: Db2 SQL Query

Precedence

• Display all manager with first name is Michael or John (see if the result are correct?)

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE JOB = 'MANAGER' AND (FIRSTNME = 'Michael' OR FIRSTNME = 'John‘) ORDER BY FIRSTNME;

Page 47: Db2 SQL Query

Advance Filtering Exercise

• Display all manager with bonus more than $500

• Display all employee with bonus more than or equal $500

• Display all employee with salary more than $20.000 and bonus more than $400 and commision more than $100

• Display student grade

Page 48: Db2 SQL Query

Limiting Data

• If you are expecting a query to still return more rows that you want, even with the filtering from a WHERE clause applied, you can add a LIMIT clause to specify the maximum number of records to be returned.

Page 49: Db2 SQL Query

Limiting Data

• Query FormatSELECT [COLUMN_NAME] FROM [TABLE_NAME] FETCH FIRST [NUMBER] ROWS ONLY;

Page 50: Db2 SQL Query

Limiting Data

• Retrieve the first 5 data

• SELECT * FROM OL37V3COL.EMPLOYEE FETCH FIRST 5 ROWS ONLY;

Page 51: Db2 SQL Query

Limiting Data Exercise

• Retrieve the first 25 employee data

• Retrieve the first 10 student data

• Retrieve the first 20 lecturer data

Page 52: Db2 SQL Query

Numeric Function

• An expression that uses a numeric operator can be used in a SQL statement anywhere that you could otherwise put a numeric value.

• You can also use a numeric operator to modify retrieved data from a table, as long as it is numeric data.

Page 53: Db2 SQL Query

Numeric Function

• You can actually perform a query in SQL without supplying a table name.

• This is useful only when you have an expression as a selected value, but it can be used to show the result of an expression on fixed values.

Page 54: Db2 SQL Query

Numeric Function

• Addition in SQL is performed using the + operator, and subtraction using the - operator. The following query shows an expression using each of these operators:

• SELECT 15 + 28, 94 – 55FROM SYSIBM.SYSDUMMY1;

Page 55: Db2 SQL Query

Numeric Function – Column

• Display employee information and additional calculated column salary + 100.000

• SELECT EMPNO, FIRSTNME, LASTNAME, SALARY, SALARY + 100000 AS FUTURE_SALARY FROM OL37V3COL.EMPLOYEE;

Page 56: Db2 SQL Query

Numeric Function – Column

• Display employee information and additional calculated column salary – 10.000

• SELECT EMPNO, FIRSTNME, LASTNAME, SALARY, SALARY - 10000 FROM OL37V3COL.EMPLOYEE;

Page 57: Db2 SQL Query

Numeric Function – Column

• Display employee information and additional calculated column named tax

• SELECT EMPNO, FIRSTNME, LASTNAME, SALARY, 0.1 * SALARY AS TAXFROM OL37V3COL.EMPLOYEE;

Page 58: Db2 SQL Query

Numeric Function – Round

• Display employee information and additional calculated rounding column (1 digit only)

• SELECT EMPNO, FIRSTNME, LASTNAME, BONUS, ROUND(BONUS, 0)FROM OL37V3COL.EMPLOYEEORDER BY EMPNO;

Page 59: Db2 SQL Query

Numeric Function – Round

• Display employee information and additional calculated rounding column (2 digit only)

• SELECT EMPNO, FIRSTNME, LASTNAME, BONUS, ROUND(BONUS, 1)FROM OL37V3COL.EMPLOYEE;

Page 60: Db2 SQL Query

Numeric Function – Ceiling

• Display employee information and additional calculated ceiling column (forced to always round up)

• SELECT EMPNO, FIRSTNME, LASTNAME, BONUS, CEILING(BONUS)FROM OL37V3COL.EMPLOYEE;

Page 61: Db2 SQL Query

Numeric Function – Floor

• Display employee information and additional calculated ceiling column (forced to always round down)

• SELECT EMPNO, FIRSTNME, LASTNAME, BONUS, FLOOR(BONUS)FROM OL37V3COL.EMPLOYEE;

Page 62: Db2 SQL Query

Numeric Function – Pow

• Display pow function

• SELECT POW(2, 2)FROM SYSIBM.SYSDUMMY1;

Page 63: Db2 SQL Query

Numeric Function – Sqrt

• Display square root function

• SELECT SQRT(4)FROM SYSIBM.SYSDUMMY1;

Page 64: Db2 SQL Query

String Function - Like

• Display employee with last name contain er

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE LASTNAME LIKE '%er%';

Page 65: Db2 SQL Query

String Function - Like

• Display employee with last name start with Jo

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE LASTNAME LIKE ‘Jo%';

Page 66: Db2 SQL Query

String Function - Like

• Display employee with last name end with Jo

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE LASTNAME LIKE ‘%Jo';

Page 67: Db2 SQL Query

String Function - Concat

• Display employee first name and last name in one column

• SELECT CONCAT(FIRSTNME, LASTNAME) AS COMPLETENAME FROM OL37V3COL.EMPLOYEE;

Page 68: Db2 SQL Query

String Function - Substring

• Display the first 5 letter from employee first name

• SELECT SUBSTR(FIRSTNME, 1, 5) AS SUBSTRING FROM OL37V3COL.EMPLOYEE;

Page 69: Db2 SQL Query

String Function – Upper case

• Display first name from employee in upper case

• SELECT UCASE(FIRSTNME) AS FIRSTNAME_UPPERFROM OL37V3COL.EMPLOYEE;

Page 70: Db2 SQL Query

String Function – Lower case

• Display first name from employee in lower case

• SELECT LCASE(FIRSTNME) AS FIRSTNAME_LOWERFROM OL37V3COL.EMPLOYEE;

Page 71: Db2 SQL Query

String Function – Replace

• Display last name from employee but if the last name contain Jo then replace with XX

• SELECT REPLACE(LASTNAME, ‘Jo’, ‘XX’) AS LASTNAME_REPLACEDFROM OL37V3COL.EMPLOYEE;

Page 72: Db2 SQL Query

Date Function – Current Date

• Display the current date

• SELECT CURDATE() AS TANGGAL_SEKARANGFROM SYSIBM.SYSDUMMY1;

Page 73: Db2 SQL Query

Date Function – Current Time

• Display the current time

• SELECT CURTIME() AS JAM_SEKARANGFROM SYSIBM.SYSDUMMY1;

Page 74: Db2 SQL Query

Date Function – Now

• Display the current time

• SELECT NOW() AS CURRENT_DATE_TIMEFROM SYSIBM.SYSDUMMY1;

Page 75: Db2 SQL Query

Date Function – Year

• Display the employee who were born in 1941

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE YEAR(BIRTHDATE) = 1941;

Page 76: Db2 SQL Query

Date Function – Month

• Display the employee who were born in May

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE MONTH(BIRTHDATE) = 05;

Page 77: Db2 SQL Query

Date Function – Day

• Display the employee who were born 5th of the month

• SELECT * FROM OL37V3COL.EMPLOYEE WHERE DAY(BIRTHDATE) = 05;

Page 78: Db2 SQL Query

Summarizing Data

• SQL provides five aggregate functions that enable you to summarize table data without retrieving every row.

• By using these functions, you can find the total number of rows in a dataset, the sum of the values, or the highest, lowest, and average values.

Page 79: Db2 SQL Query

Summarizing Data - Count

• Count how many employee

• SELECT COUNT(*) AS TOTAL_EMPLOYEEFROM OL37V3COL.EMPLOYEE;

Page 80: Db2 SQL Query

Summarizing Data - Sum

• Sum all employee salary

• SELECT SUM(SALARY) AS TOTAL_SALARYFROM OL37V3COL.EMPLOYEE;

Page 81: Db2 SQL Query

Summarizing Data - Average

• Display average employee salary

• SELECT AVG(SALARY) AS AVERAGE_SALARYFROM OL37V3COL.EMPLOYEE;

Page 82: Db2 SQL Query

Summarizing Data - Minimum

• Display minimum employee salary

• SELECT MIN(SALARY) AS MINIMUM_SALARYFROM OL37V3COL.EMPLOYEE;

Page 83: Db2 SQL Query

Summarizing Data - Grouping

• Display employee per department

• SELECT JOB, COUNT(*) AS TOTAL_EMPLOYEEFROM OL37V3COL.EMPLOYEEGROUP BY JOB;

Page 84: Db2 SQL Query

Summarizing Data - Having

• Display employee per department with more than 5 employee

• SELECT JOB, COUNT(*) AS TOTAL_EMPLOYEEFROM OL37V3COL.EMPLOYEEGROUP BY JOBHAVING COUNT(*) > 5;

Page 85: Db2 SQL Query

Joining Data

• Define relationship between table and Foreign Key

• For example relationship between NILAI and MAHASISWA

Page 86: Db2 SQL Query

Joining Data – Type of Join

• Inner Join• Cross Join• Self Join• Left Join• Right Join

Page 87: Db2 SQL Query

Joining Data – Type of Join

Page 88: Db2 SQL Query

Joining Data – Inner Join

• Join between NILAI and MAHASISWA

• SELECT * FROM QRYLIB.AGSNIL n

INNER JOIN QRYLIB.AGSMHS m ON n.KDMHS = m.KDMHS;

Page 89: Db2 SQL Query

Joining Data – Left Join

• Join between NILAI and MAHASISWA

• SELECT * FROM QRYLIB.AGSNIL n

LEFT JOIN QRYLIB.AGSMHS m ON n.KDMHS = m.KDMHS;

Page 90: Db2 SQL Query

Combining Data - Union

• Combine 2 query into 1 result• SELECT *

FROM OL37V3COL.EMPLOYEE WHERE LASTNAME LIKE '%er%‘UNIONSELECT * FROM OL37V3COL.EMPLOYEE WHERE LASTNAME LIKE ‘%Jo%‘

Page 91: Db2 SQL Query

List of Aggregate Functions

• AVGThe AVG function returns the average of a set of numbers.

• CORRELATIONThe CORRELATION function returns the coefficient of the correlation of a set of number pairs.

Page 92: Db2 SQL Query

List of Aggregate Functions

• COUNTThe COUNT function returns the number of rows or values in a set of rows or values.

• COUNT_BIGThe COUNT_BIG function returns the number of rows or values in a set of rows or values. It is similar to COUNT except that the result can be greater than the maximum value of an integer.

Page 93: Db2 SQL Query

List of Aggregate Functions

• COVARIANCE or COVARIANCE_SAMPThe COVARIANCE and COVARIANCE_SAMP functions return the covariance (population) of a set of number pairs.

• MAXThe MAX function returns the maximum value in a set of values.

Page 94: Db2 SQL Query

List of Aggregate Functions

• MINThe MIN function returns the minimum value in a set of values.

• STDDEV or STDDEV_SAMPThe STDDEV or STDDEV_SAMP function returns the standard deviation (/n), or the sample standard deviation (/n-1), of a set of numbers.

Page 95: Db2 SQL Query

List of Aggregate Functions

• SUMThe SUM function returns the sum of a set of numbers.

• VARIANCE or VARIANCE_SAMPThe VARIANCE function returns the biased variance (/n) of a set of numbers. The VARIANCE_SAMP function returns the sample variance (/n-1) of a set of numbers.

Page 96: Db2 SQL Query

List of Aggregate Functions

• XMLAGGThe XMLAGG function returns an XML sequence that contains an item for each non-null value in a set of XML values.

Page 97: Db2 SQL Query

List of Scalar Functions

• ABSThe ABS function returns the absolute value of a number.

• ACOSThe ACOS function returns the arc cosine of the argument as an angle, expressed in radians. The ACOS and COS functions are inverse operations.

Page 98: Db2 SQL Query

List of Scalar Functions

• ADD_MONTHSThe ADD_MONTHS function returns a date that represents expression plus a specified number of months.

• ASCIIThe ASCII function returns the leftmost character of the argument as an integer.

Page 99: Db2 SQL Query

List of Scalar Functions

• ASCII_CHRThe ASCII_CHR function returns the character that has the ASCII code value that is specified by the argument.

• ASCII_STRThe ASCII_STR function returns an ASCII version of the string in the system ASCII CCSID.

Page 100: Db2 SQL Query

List of Scalar Functions

• ASINThe ASIN function returns the arc sine of the argument as an angle, expressed in radians. The ASIN and SIN functions are inverse operations.

• ATANThe ATAN function returns the arc tangent of the argument as an angle, expressed in radians. The ATAN and TAN functions are inverse operations.

• ATANHThe ATANH function returns the hyperbolic arc tangent of a number, expressed in radians. The ATANH and TANH functions are inverse operations.

• ATAN2The ATAN2 function returns the arc tangent of x and y coordinates as an angle, expressed in radians.

• BIGINTThe BIGINT function returns a big integer representation of either a number or a character or graphic string representation of a number.

• BINARYThe BINARY function returns a BINARY (fixed-length binary string) representation of a string of any type or of a row ID type.

• BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT The bit manipulation functions operate on the twos complement representation of the integer value of the input arguments. The functions return the result as a corresponding base 10 integer value in a data type that is based on the data type of the input arguments.

• BLOBThe BLOB function returns a BLOB representation of a string of any type or of a row ID type.

• CCSID_ENCODINGThe CCSID_ENCODING function returns a string value that indicates the encoding scheme of a CCSID that is specified by the argument.

• CEILINGThe CEILING function returns the smallest integer value that is greater than or equal to the argument.

• CHARThe CHAR function returns a fixed-length character string representation of the argument.

• CHARACTER_LENGTHThe CHARACTER_LENGTH function returns the length of the first argument in the specified string unit.

• CLOBThe CLOB function returns a CLOB representation of a string.

• COALESCEThe COALESCE function returns the value of the first nonnull expression.

• COLLATION_KEYThe COLLATION_KEY function returns a varying-length binary string that represents the collation key of the argument in the specified collation.

• COMPARE_DECFLOATThe COMPARE_DECFLOAT function returns a SMALLINT value that indicates whether the two arguments are equal or unordered, or whether one argument is greater than the other.

• CONCATThe CONCAT function combines two compatible string arguments.

• CONTAINSThe CONTAINS function searches a text search index using criteria that are specified in a search argument and returns a result about whether or not a match was found.

• COSThe COS function returns the cosine of the argument, where the argument is an angle, expressed in radians. The COS and ACOS functions are inverse operations.

• COSHThe COSH function returns the hyperbolic cosine of the argument, where the argument is an angle, expressed in radians.

• DATEThe DATE function returns a date that is derived from a value.

• DAYThe DAY function returns the day part of a value.

• DAYOFMONTHThe DAYOFMONTH function returns the day part of a value. The function is similar to the DAY function, except DAYOFMONTH does not support a date or timestamp duration as an argument.

• DAYOFWEEKThe DAYOFWEEK function returns an integer, in the range of 1 to 7, that represents the day of the week, where 1 is Sunday and 7 is Saturday. The DAYOFWEEK function is similar to the DAYOFWEEK_ISO function.

• DAYOFWEEK_ISOThe DAYOFWEEK_ISO function returns an integer, in the range of 1 to 7, that represents the day of the week, where 1 is Monday and 7 is Sunday. The DAYOFWEEK_ISO function is similar to the DAYOFWEEK function.

• DAYOFYEARThe DAYOFYEAR function returns an integer, in the range of 1 to 366, that represents the day of the year, where 1 is January 1.

• DAYSThe DAYS function returns an integer representation of a date.

• DBCLOBThe DBCLOB function returns a DBCLOB representation of a character string value (with the single-byte characters converted to double-byte characters) or a graphic string value.

• DECFLOATThe DECFLOAT function returns a decimal floating-point representation of either a number or a character string representation of a number, a decimal number, an integer, a floating-point number, or a decimal floating-point number.

• DECFLOAT_FORMAT The DECFLOAT_FORMAT function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

• DECFLOAT_SORTKEYThe DECFLOAT_SORTKEY function returns a binary value that can be used when sorting DECFLOAT values. The sorting occurs in a manner that is consistent with the IEEE 754R specification on total ordering.

• DECIMAL or DECThe DECIMAL function returns a decimal representation of either a number or a character-string or graphic-string representation of a number, an integer, or a decimal number.

• DECODE The DECODE function compares each expression2 to expression1. If expression1 is equal to expression2, or both expression1 and expression2 are null, the value of the result-expression is returned. If no expression2 matches expression1, the value of else-expression is returned. Otherwise a null value is returned.

• DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, and DECRYPT_DB

The decryption functions return a value that is the result of decrypting encrypted data. The decryption functions can decrypt only values that are encrypted by using the ENCRYPT_TDES function.

• DEGREESThe DEGREES function returns the number of degrees of the argument, which is an angle, expressed in radians.

• DIFFERENCEThe DIFFERENCE function returns a value, from 0 to 4, that represents the difference between the sounds of two strings, based on applying the SOUNDEX function to the strings. A value of 4 is the best possible sound match.

• DIGITSThe DIGITS function returns a character string representation of the absolute value of a number.

• DOUBLE_PRECISION or DOUBLEThe DOUBLE_PRECISION and DOUBLE functions returns a floating-point representation of either a number or a character-string or graphic-string representation of a number, an integer, a decimal number, or a floating-point number.

• DSN_XMLVALIDATEThe DSN_XMLVALIDATE function returns an XML value that is the result of applying XML schema validation to the first argument of the function. DSN_XMLVALIDATE can validate XML data that has a maximum length of 2 GB - 1 byte.

• EBCDIC_CHRThe EBCDIC_CHR function returns the character that has the EBCDIC code value that is specified by the argument.

• EBCDIC_STRThe EBCDIC_STR function returns a string, in the system EBCDIC CCSID, that is an EBCDIC version of the string.

• ENCRYPT_TDESThe ENCRYPT_TDES function returns a value that is the result of encrypting the first argument by using the Triple DES encryption algorithm. The function can also set the password that is used for encryption.

• EXPThe EXP function returns a value that is the base of the natural logarithm (e), raised to a power that is specified by the argument. The EXP and LN functions are inverse operations.

• EXTRACTThe EXTRACT function returns a portion of a date or timestamp, based on its arguments.

• FLOATThe FLOAT function returns a floating-point representation of either a number or a string representation of a number. FLOAT is a synonym for the DOUBLE function.

• FLOORThe FLOOR function returns the largest integer value that is less than or equal to the argument.

• GENERATE_UNIQUEThe GENERATE_UNIQUE function returns a bit data character string that is unique, compared to any other execution of the same function.

• GETHINTThe GETHINT function returns a hint for the password if a hint was embedded in the encrypted data. A password hint is a phrase that helps you remember the password with which the data was encrypted. For example, 'Ocean' might be used as a hint to help remember the password 'Pacific'.

• GETVARIABLEThe GETVARIABLE function returns a varying-length character-string representation of the current value of the session variable that is identified by the argument.

• GRAPHICThe GRAPHIC function returns a fixed-length graphic-string representation of a character string or a graphic string value, depending on the type of the first argument.

• HEXThe HEX function returns a hexadecimal representation of a value.

• HOURThe HOUR function returns the hour part of a value.

• IDENTITY_VAL_LOCALThe IDENTITY_VAL_LOCAL function returns the most recently assigned value for an identity column.

• IFNULLThe IFNULL function returns the first nonnull expression.

• INSERTThe INSERT function returns a string where, beginning at start in source-string, length characters have been deleted and insert-string has been inserted.

• INTEGER or INTThe INTEGER function returns an integer representation of either a number or a character string or graphic string representation of an integer.

• JULIAN_DAYThe JULIAN_DAY function returns an integer value that represents a number of days from January 1, 4713 B.C. (the start of the Julian date calendar) to the date that is specified in the argument.

• LAST_DAYThe LAST_DAY scalar function returns a date that represents the last day of the month of the date argument.

• LCASEThe LCASE function returns a string in which all the characters are converted to lowercase characters.

• LEFTThe LEFT function returns a string that consists of the specified number of leftmost bytes of the specified string units.

• LENGTHThe LENGTH function returns the length of a value.

• LNThe LN function returns the natural logarithm of the argument. The LN and EXP functions are inverse operations.

• LOCATEThe LOCATE function returns the position at which the first occurrence of an argument starts within another argument.

• LOCATE_IN_STRINGThe LOCATE_IN_STRING function returns the position at which an argument starts within a specified string.

• LOG10The LOG10 function returns the common logarithm (base 10) of a number.

• LOWERThe LOWER function returns a string in which all the characters are converted to lowercase characters.

• LPADThe LPAD function returns a string that is composed of string-expression that is padded on the left, with pad or blanks. The LPAD function treats leading or trailing blanks in string-expression as significant.

• LTRIMThe LTRIM function removes bytes from the beginning of a string expression based on the content of a trim expression.

• MAXThe MAX scalar function returns the maximum value in a set of values.

• MICROSECONDThe MICROSECOND function returns the microsecond part of a value.

• MIDNIGHT_SECONDSThe MIDNIGHT_SECONDS function returns an integer, in the range of 0 to 86400, that represents the number of seconds between midnight and the time that is specified in the argument.

• MINThe MIN scalar function returns the minimum value in a set of values.

• MINUTEThe MINUTE function returns the minute part of a value.

• MODThe MOD function divides the first argument by the second argument and returns the remainder.

• MONTHThe MONTH function returns the month part of a value.

• MONTHS_BETWEENThe MONTHS_BETWEEN function returns an estimate of the number of months between two arguments.

• MQREADThe MQREAD function returns a message from a specified MQSeries® location without removing the message from the queue.

• MQREADCLOBThe MQREADCLOB function returns a message from a specified MQSeries location without removing the message from the queue.

• MQRECEIVEThe MQRECEIVE function returns a message from a specified MQSeries location and removes the message from the queue.

• MQRECEIVECLOBThe MQRECEIVECLOB function returns a message from a specified MQSeries location and removes the message from the queue.

• MQSENDThe MQSEND function sends data to a specified MQSeries location, and returns a varying-length character string that indicates whether the function was successful or unsuccessful.

• MULTIPLY_ALTThe MULTIPLY_ALT scalar function returns the product of the two arguments. This function is an alternative to the multiplication operator and is especially useful when the sum of the precisions of the arguments exceeds 31.

• NEXT_DAYThe NEXT_DAY function returns a datetime value that represents the first weekday, named by string-expression, that is later than the date in expression.

• NORMALIZE_DECFLOATThe NORMALIZE_DECFLOAT function returns a DECFLOAT value that is the result of the argument, set to its simplest form. That is, a non-zero number that has any trailing zeros in the coefficient has those zeros removed by dividing the coefficient by the appropriate power of ten and adjusting the exponent accordingly. A zero has its exponent set to 0.

• NORMALIZE_STRINGThe NORMALIZE_STRING function takes a Unicode string argument and returns a normalized string that can be used for comparison.

• NULLIFThe NULLIF function returns the null value if the two arguments are equal; otherwise, it returns the value of the first argument.

• NVL The NVL function returns the first argument that is not null.

• OVERLAYThe OVERLAY function returns a string that is composed of one argument that is inserted into another argument at the same position where some number of bytes have been deleted.

• PACK The PACK function returns a binary string value that contains a data type array and a packed representation of each non-null expression argument.

• POSITIONThe POSITION function returns the position of the first occurrence of an argument within another argument, where the position is expressed in terms of the string units that are specified.

• POSSTRThe POSSTR function returns the position of the first occurrence of an argument within another argument.

• POWERThe POWER® function returns the value of the first argument to the power of the second argument.

• QUANTIZEThe QUANTIZE function returns a DECFLOAT value that is equal in value (except for any rounding) and sign to the first argument and that has an exponent that is set to equal the exponent of the second argument.

• QUARTERThe QUARTER function returns an integer between 1 and 4 that represents the quarter of the year in which the date resides. For example, any dates in January, February, or March return the integer 1.

• RADIANSThe RADIANS function returns the number of radians for an argument that is expressed in degrees.

• RAISE_ERRORThe RAISE_ERROR function causes the statement that invokes the function to return an error with the specified SQLSTATE (along with SQLCODE -438) and error condition. The RAISE_ERROR function always returns the null value with an undefined data type.

• RANDThe RAND function returns a random floating-point value between 0 and 1. An argument can be specified as an optional seed value.

• REALThe REAL function returns a single-precision floating-point representation of either a number or a string representation of a number.

• REPEATThe REPEAT function returns a character string that is composed of an argument that is repeated a specified number of times.

• REPLACEThe REPLACE function replaces all occurrences of search-string in source-string with replace-string. If search-string is not found in source-string, source-string is returned unchanged.

• RIDThe RID function returns the record ID (RID) of a row. The RID is used to uniquely identify a row.

• RIGHTThe RIGHT function returns a string that consists of the specified number of rightmost bytes or specified string unit from a string.

• ROUNDThe ROUND function returns a number that is rounded to the specified number of places to the right or left of the decimal place.

• ROUND_TIMESTAMPThe ROUND_TIMESTAMP scalar function returns a timestamp that is rounded to the unit that is specified by the timestamp format string.

• ROWIDThe ROWID function returns a row ID representation of its argument.

• RPADThe RPAD function returns a string that is padded on the right with blanks or a specified string.

• RTRIMThe RTRIM function removes bytes from the end of a string expression based on the content of a trim expression.

• SCOREThe SCORE function searches a text search index using criteria that are specified in a search argument and returns a relevance score that measures how well a document matches the query.

• SECONDThe SECOND function returns the seconds part of a value with optional fractional seconds.

• SIGNThe SIGN function returns an indicator of the sign of the argument.

• SINThe SIN function returns the sine of the argument, where the argument is an angle, expressed in radians.

• SINHThe SINH function returns the hyperbolic sine of the argument, where the argument is an angle, expressed in radians.

• SMALLINTThe SMALLINT function returns a small integer representation either of a number or of a string representation of a number.

• SOUNDEXThe SOUNDEX function returns a 4-character code that represents the sound of the words in the argument. The result can be compared to the results of the SOUNDEX function of other strings.

• SOAPHTTPC and SOAPHTTPVThe SOAPHTTPC function returns a CLOB representation of XML data that results from a SOAP request to the web service that is specified by the first argument. The SOAPHTTPV function returns a VARCHAR representation of XML data that results from a SOAP request to the web service that is specified by the first argument.

• SOAPHTTPNC and SOAPHTTPNVThe SOAPHTTPNC and SOAPHTTPNV functions allow you to specify a complete SOAP message as input and to return complete SOAP messages from the specified web service. The returned SOAP messages are CLOB or VARCHAR representations of the returned XML data.

• SPACEThe SPACE function returns a character string that consists of the number of SBCS blanks that the argument specifies.

• SQRTThe SQRT function returns the square root of the argument.

• STRIPThe STRIP function removes blanks or another specified character from the end, the beginning, or both ends of a string expression.

• SUBSTRThe SUBSTR function returns a substring of a string.

• SUBSTRINGThe SUBSTRING function returns a substring of a string.

• TANThe TAN function returns the tangent of the argument, where the argument is an angle, expressed in radians.

• TANHThe TANH function returns the hyperbolic tangent of the argument, where the argument is an angle, expressed in radians.

• TIMEThe TIME function returns a time that is derived from a value.

• TIMESTAMPThe TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value from its argument or arguments.

• TIMESTAMPADDThe TIMESTAMPADD function returns the result of adding the specified number of the designated interval to the timestamp value.

• TIMESTAMP_FORMATThe TIMESTAMP_FORMAT function returns a TIMESTAMP WITHOUT TIME ZONE value that is based on the interpretation of the input string using the specified format.

• TIMESTAMP_ISOThe TIMESTAMP_ISO function returns a timestamp value that is based on a date, a time, or a timestamp argument.

• TIMESTAMPDIFFThe TIMESTAMPDIFF function returns an estimated number of intervals of the type that is defined by the first argument, based on the difference between two timestamps.

• TIMESTAMP_TZ The TIMESTAMP_TZ function returns a TIMESTAMP WITH TIME ZONE value from the input arguments.

• TO_CHARThe TO_CHAR function returns a character string representation of a timestamp value that has been formatted using a specified character template.

• TO_DATEThe TO_DATE function returns a timestamp value that is based on the interpretation of the input string using the specified format.

• TO_NUMBER The TO_NUMBER function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

• TOTALORDERThe TOTALORDER function returns an ordering for DECFLOAT values. The TOTALORDER function returns a small integer value that indicates how expression1 compares with expression2.

• TRANSLATEThe TRANSLATE function returns a value in which one or more characters of the first argument might have been converted to other characters.

• TRIM The TRIM function removes bytes from the beginning, from the end, or from both the beginning and end of a string expression.

• TRUNCATE or TRUNCThe TRUNCATE function returns the first argument, truncated as specified. Truncation is to the number of places to the right or left of the decimal point this is specified by the second argument.

• TRUNC_TIMESTAMPThe TRUNC_TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value that is the expression, truncated to the unit that is specified by the format-string.

• UCASEThe UCASE function returns a string in which all the characters have been converted to uppercase characters, based on the CCSID of the argument. The UCASE function is identical to the UPPER function.

• UNICODEThe UNICODE function returns the Unicode UTF-16 code value of the leftmost character of the argument as an integer.

• UNICODE_STRThe UNICODE_STR function returns a string in Unicode UTF-8 or UTF-16, depending on the specified option. The string represents a Unicode encoding of the input string.

• UPPERThe UPPER function returns a string in which all the characters have been converted to uppercase characters.

• VALUEThe VALUE function returns the value of the first non-null expression.

• VARBINARYThe VARBINARY function returns a VARBINARY (varying-length binary string) representation of a string of any type.

• VARCHARThe VARCHAR function returns a varying-length character string representation of the value specified by the first argument. The first argument can be a character string, a graphic string, a datetime value, an integer number, a decimal number, a floating-point number, or a row ID value.

• VARCHAR_FORMATThe VARCHAR_FORMAT function returns a character string representation of the first argument in the format indicated by format-string.

• VARGRAPHICThe VARGRAPHIC function returns a varying-length graphic string representation of a the first argument. The first argument can be a character string value or a graphic string value.

• VERIFY_GROUP_FOR_USERThe VERIFY_GROUP_FOR_USER function returns a value that indicates whether the primary authorization ID and the secondary authorization IDs that are associated with the first argument are in the authorization names that are specified in the list of the second argument.

• VERIFY_ROLE_FOR_USERThe VERIFY_ROLE_FOR_USER function returns a value that indicates whether the roles that are associated with the authorization ID that is specified in the first argument are included in the role names that are specified in the list of the second argument.

• VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER

The VERIFY_TRUSTED_CONTEXT_FOR_USER function returns a value that indicates whether the authorization ID that is associated with first argument has acquired a role in a trusted connection and whether that acquired role is included in the role names that are specified in the list of the second argument.

• WEEKThe WEEK function returns an integer in the range of 1 to 54 that represents the week of the year. The week starts with Sunday, and January 1 is always in the first week.

• WEEK_ISOThe WEEK_ISO function returns an integer in the range of 1 to 53 that represents the week of the year. The week starts with Monday and includes seven days. Week 1 is the first week of the year that contains a Thursday, which is equivalent to the first week that contains January 4.

• XMLATTRIBUTESThe XMLATTRIBUTES function constructs XML attributes from the arguments. This function can be used as an argument only for the XMLELEMENT function.

• XMLCOMMENTThe XMLCOMMENT function returns an XML value with a single comment node from a string expression. The content of the comment node is the value of the input string expression, mapped to Unicode (UTF-8).

• XMLCONCATThe XMLCONCAT function returns an XML sequence that contains the concatenation of a variable number of XML input arguments.

• XMLDOCUMENTThe XMLDOCUMENT function returns an XML value with a single document node and zero or more nodes as its children. The content of the generated XML document node is specified by a list of expressions.

• XMLELEMENTThe XMLELEMENT function returns an XML value that is an XML element node.

• XMLFORESTThe XMLFOREST function returns an XML value that is a sequence of XML element nodes.

• XMLMODIFY The XMLMODIFY function returns an XML value that might have been modified by the evaluation of an XQuery updating expression and XQuery variables that are specified as input arguments.

• XMLNAMESPACESThe XMLNAMESPACES function constructs namespace declarations from the arguments. This function can be used as an argument only for specific functions, such as the XMLELEMENT function and the XMLFOREST function.

• XMLPARSEThe XMLPARSE function parses the argument as an XML document and returns an XML value.

• XMLPIThe XMLPI function returns an XML value with a single processing instruction node.

• XMLQUERYThe XMLQUERY function returns an XML value from the evaluation of an XQuery expression, by using specified input arguments, a context item, and XQuery variables.

• XMLSERIALIZEThe XMLSERIALIZE function returns a serialized XML value of the specified data type that is generated from the first argument.

• XMLTEXTThe XMLTEXT function returns an XML value with a single text node that contains the value of the argument.

• XMLXSROBJECTID The XMLXSROBJECTID function returns the XSR object identifier of the XML schema that is used to validate the XML document specified in the argument.

• XSLTRANSFORM The XSLTRANSFORM function transforms an XML document into a different data format. The output can be any form possible for the XSLT processor, including but not limited to XML, HTML, and plain text.

• YEARThe YEAR function returns the year part of a value that is a character or graphic string. The value must be a valid string representation of a date or timestamp.

Page 101: Db2 SQL Query

List of Scalar Functions

• ATANHThe ATANH function returns the hyperbolic arc tangent of a number, expressed in radians. The ATANH and TANH functions are inverse operations.

• ATAN2The ATAN2 function returns the arc tangent of x and y coordinates as an angle, expressed in radians.

Page 102: Db2 SQL Query

List of Scalar Functions

• BIGINTThe BIGINT function returns a big integer representation of either a number or a character or graphic string representation of a number.

• BINARYThe BINARY function returns a BINARY (fixed-length binary string) representation of a string of any type or of a row ID type.

Page 103: Db2 SQL Query

List of Scalar Functions

• BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT The bit manipulation functions operate on the twos complement representation of the integer value of the input arguments. The functions return the result as a corresponding base 10 integer value in a data type that is based on the data type of the input arguments.

Page 104: Db2 SQL Query

List of Scalar Functions

• BLOBThe BLOB function returns a BLOB representation of a string of any type or of a row ID type.

• CCSID_ENCODINGThe CCSID_ENCODING function returns a string value that indicates the encoding scheme of a CCSID that is specified by the argument.

Page 105: Db2 SQL Query

List of Scalar Functions

• CEILINGThe CEILING function returns the smallest integer value that is greater than or equal to the argument.

• CHARThe CHAR function returns a fixed-length character string representation of the argument.

Page 106: Db2 SQL Query

List of Scalar Functions

• CHARACTER_LENGTHThe CHARACTER_LENGTH function returns the length of the first argument in the specified string unit.

• CLOBThe CLOB function returns a CLOB representation of a string.

Page 107: Db2 SQL Query

List of Scalar Functions

• COALESCEThe COALESCE function returns the value of the first nonnull expression.

• COLLATION_KEYThe COLLATION_KEY function returns a varying-length binary string that represents the collation key of the argument in the specified collation.

Page 108: Db2 SQL Query

List of Scalar Functions

• COMPARE_DECFLOATThe COMPARE_DECFLOAT function returns a SMALLINT value that indicates whether the two arguments are equal or unordered, or whether one argument is greater than the other.

• CONCATThe CONCAT function combines two compatible string arguments.

Page 109: Db2 SQL Query

List of Scalar Functions

• CONTAINSThe CONTAINS function searches a text search index using criteria that are specified in a search argument and returns a result about whether or not a match was found.

• COSThe COS function returns the cosine of the argument, where the argument is an angle, expressed in radians.

Page 110: Db2 SQL Query

List of Scalar Functions

• COSHThe COSH function returns the hyperbolic cosine of the argument, where the argument is an angle, expressed in radians.

• DATEThe DATE function returns a date that is derived from a value.

Page 111: Db2 SQL Query

List of Scalar Functions

• DAYThe DAY function returns the day part of a value.

• DAYOFMONTHThe DAYOFMONTH function returns the day part of a value.

Page 112: Db2 SQL Query

List of Scalar Functions

• DAYOFWEEKThe DAYOFWEEK function returns an integer, in the range of 1 to 7, that represents the day of the week, where 1 is Sunday and 7 is Saturday. DAYOFWEEK_ISOThe DAYOFWEEK_ISO function returns an integer, in the range of 1 to 7, that represents the day of the week, where 1 is Monday and 7 is Sunday.

Page 113: Db2 SQL Query

List of Scalar Functions

• DAYOFYEARThe DAYOFYEAR function returns an integer, in the range of 1 to 366, that represents the day of the year, where 1 is January 1.

• DAYSThe DAYS function returns an integer representation of a date.

Page 114: Db2 SQL Query

List of Scalar Functions

• DBCLOBThe DBCLOB function returns a DBCLOB representation of a character string value

• DECFLOATThe DECFLOAT function returns a decimal floating-point representation of either a number or a character string representation of a number.

Page 115: Db2 SQL Query

List of Scalar Functions

• DECFLOAT_FORMAT The DECFLOAT_FORMAT function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

• DECFLOAT_SORTKEYThe DECFLOAT_SORTKEY function returns a binary value that can be used when sorting DECFLOAT values. The sorting occurs in a manner that is consistent with the IEEE 754R specification on total ordering.

Page 116: Db2 SQL Query

List of Scalar Functions

• DECIMAL or DECThe DECIMAL function returns a decimal representation of either a number or a character-string or graphic-string representation of a number, an integer, or a decimal number.

• DECODE The DECODE function compares each expression2 to expression1. If expression1 is equal to expression2, or both expression1 and expression2 are null, the value of the result-expression is returned. If no expression2 matches expression1, the value of else-expression is returned. Otherwise a null value is returned.

Page 117: Db2 SQL Query

List of Scalar Functions

• DECRYPT_BINARY, DECRYPT_BIT, DECRYPT_CHAR, and DECRYPT_DB

The decryption functions return a value that is the result of decrypting encrypted data. The decryption functions can decrypt only values that are encrypted by using the ENCRYPT_TDES function.

• DEGREESThe DEGREES function returns the number of degrees of the argument, which is an angle, expressed in radians.

• DIFFERENCEThe DIFFERENCE function returns a value, from 0 to 4, that represents the difference between the sounds of two strings, based on applying the SOUNDEX function to the strings. A value of 4 is the best possible sound match.

• DIGITSThe DIGITS function returns a character string representation of the absolute value of a number.

• DOUBLE_PRECISION or DOUBLEThe DOUBLE_PRECISION and DOUBLE functions returns a floating-point representation of either a number or a character-string or graphic-string representation of a number, an integer, a decimal number, or a floating-point number.

• DSN_XMLVALIDATEThe DSN_XMLVALIDATE function returns an XML value that is the result of applying XML schema validation to the first argument of the function. DSN_XMLVALIDATE can validate XML data that has a maximum length of 2 GB - 1 byte.

• EBCDIC_CHRThe EBCDIC_CHR function returns the character that has the EBCDIC code value that is specified by the argument.

• EBCDIC_STRThe EBCDIC_STR function returns a string, in the system EBCDIC CCSID, that is an EBCDIC version of the string.

• ENCRYPT_TDESThe ENCRYPT_TDES function returns a value that is the result of encrypting the first argument by using the Triple DES encryption algorithm. The function can also set the password that is used for encryption.

• EXPThe EXP function returns a value that is the base of the natural logarithm (e), raised to a power that is specified by the argument. The EXP and LN functions are inverse operations.

• EXTRACTThe EXTRACT function returns a portion of a date or timestamp, based on its arguments.

• FLOATThe FLOAT function returns a floating-point representation of either a number or a string representation of a number. FLOAT is a synonym for the DOUBLE function.

• FLOORThe FLOOR function returns the largest integer value that is less than or equal to the argument.

• GENERATE_UNIQUEThe GENERATE_UNIQUE function returns a bit data character string that is unique, compared to any other execution of the same function.

• GETHINTThe GETHINT function returns a hint for the password if a hint was embedded in the encrypted data. A password hint is a phrase that helps you remember the password with which the data was encrypted. For example, 'Ocean' might be used as a hint to help remember the password 'Pacific'.

• GETVARIABLEThe GETVARIABLE function returns a varying-length character-string representation of the current value of the session variable that is identified by the argument.

• GRAPHICThe GRAPHIC function returns a fixed-length graphic-string representation of a character string or a graphic string value, depending on the type of the first argument.

• HEXThe HEX function returns a hexadecimal representation of a value.

• HOURThe HOUR function returns the hour part of a value.

• IDENTITY_VAL_LOCALThe IDENTITY_VAL_LOCAL function returns the most recently assigned value for an identity column.

• IFNULLThe IFNULL function returns the first nonnull expression.

• INSERTThe INSERT function returns a string where, beginning at start in source-string, length characters have been deleted and insert-string has been inserted.

• INTEGER or INTThe INTEGER function returns an integer representation of either a number or a character string or graphic string representation of an integer.

• JULIAN_DAYThe JULIAN_DAY function returns an integer value that represents a number of days from January 1, 4713 B.C. (the start of the Julian date calendar) to the date that is specified in the argument.

• LAST_DAYThe LAST_DAY scalar function returns a date that represents the last day of the month of the date argument.

• LCASEThe LCASE function returns a string in which all the characters are converted to lowercase characters.

• LEFTThe LEFT function returns a string that consists of the specified number of leftmost bytes of the specified string units.

• LENGTHThe LENGTH function returns the length of a value.

• LNThe LN function returns the natural logarithm of the argument. The LN and EXP functions are inverse operations.

• LOCATEThe LOCATE function returns the position at which the first occurrence of an argument starts within another argument.

• LOCATE_IN_STRINGThe LOCATE_IN_STRING function returns the position at which an argument starts within a specified string.

• LOG10The LOG10 function returns the common logarithm (base 10) of a number.

• LOWERThe LOWER function returns a string in which all the characters are converted to lowercase characters.

• LPADThe LPAD function returns a string that is composed of string-expression that is padded on the left, with pad or blanks. The LPAD function treats leading or trailing blanks in string-expression as significant.

• LTRIMThe LTRIM function removes bytes from the beginning of a string expression based on the content of a trim expression.

• MAXThe MAX scalar function returns the maximum value in a set of values.

• MICROSECONDThe MICROSECOND function returns the microsecond part of a value.

• MIDNIGHT_SECONDSThe MIDNIGHT_SECONDS function returns an integer, in the range of 0 to 86400, that represents the number of seconds between midnight and the time that is specified in the argument.

• MINThe MIN scalar function returns the minimum value in a set of values.

• MINUTEThe MINUTE function returns the minute part of a value.

• MODThe MOD function divides the first argument by the second argument and returns the remainder.

• MONTHThe MONTH function returns the month part of a value.

• MONTHS_BETWEENThe MONTHS_BETWEEN function returns an estimate of the number of months between two arguments.

• MQREADThe MQREAD function returns a message from a specified MQSeries® location without removing the message from the queue.

• MQREADCLOBThe MQREADCLOB function returns a message from a specified MQSeries location without removing the message from the queue.

• MQRECEIVEThe MQRECEIVE function returns a message from a specified MQSeries location and removes the message from the queue.

• MQRECEIVECLOBThe MQRECEIVECLOB function returns a message from a specified MQSeries location and removes the message from the queue.

• MQSENDThe MQSEND function sends data to a specified MQSeries location, and returns a varying-length character string that indicates whether the function was successful or unsuccessful.

• MULTIPLY_ALTThe MULTIPLY_ALT scalar function returns the product of the two arguments. This function is an alternative to the multiplication operator and is especially useful when the sum of the precisions of the arguments exceeds 31.

• NEXT_DAYThe NEXT_DAY function returns a datetime value that represents the first weekday, named by string-expression, that is later than the date in expression.

• NORMALIZE_DECFLOATThe NORMALIZE_DECFLOAT function returns a DECFLOAT value that is the result of the argument, set to its simplest form. That is, a non-zero number that has any trailing zeros in the coefficient has those zeros removed by dividing the coefficient by the appropriate power of ten and adjusting the exponent accordingly. A zero has its exponent set to 0.

• NORMALIZE_STRINGThe NORMALIZE_STRING function takes a Unicode string argument and returns a normalized string that can be used for comparison.

• NULLIFThe NULLIF function returns the null value if the two arguments are equal; otherwise, it returns the value of the first argument.

• NVL The NVL function returns the first argument that is not null.

• OVERLAYThe OVERLAY function returns a string that is composed of one argument that is inserted into another argument at the same position where some number of bytes have been deleted.

• PACK The PACK function returns a binary string value that contains a data type array and a packed representation of each non-null expression argument.

• POSITIONThe POSITION function returns the position of the first occurrence of an argument within another argument, where the position is expressed in terms of the string units that are specified.

• POSSTRThe POSSTR function returns the position of the first occurrence of an argument within another argument.

• POWERThe POWER® function returns the value of the first argument to the power of the second argument.

• QUANTIZEThe QUANTIZE function returns a DECFLOAT value that is equal in value (except for any rounding) and sign to the first argument and that has an exponent that is set to equal the exponent of the second argument.

• QUARTERThe QUARTER function returns an integer between 1 and 4 that represents the quarter of the year in which the date resides. For example, any dates in January, February, or March return the integer 1.

• RADIANSThe RADIANS function returns the number of radians for an argument that is expressed in degrees.

• RAISE_ERRORThe RAISE_ERROR function causes the statement that invokes the function to return an error with the specified SQLSTATE (along with SQLCODE -438) and error condition. The RAISE_ERROR function always returns the null value with an undefined data type.

• RANDThe RAND function returns a random floating-point value between 0 and 1. An argument can be specified as an optional seed value.

• REALThe REAL function returns a single-precision floating-point representation of either a number or a string representation of a number.

• REPEATThe REPEAT function returns a character string that is composed of an argument that is repeated a specified number of times.

• REPLACEThe REPLACE function replaces all occurrences of search-string in source-string with replace-string. If search-string is not found in source-string, source-string is returned unchanged.

• RIDThe RID function returns the record ID (RID) of a row. The RID is used to uniquely identify a row.

• RIGHTThe RIGHT function returns a string that consists of the specified number of rightmost bytes or specified string unit from a string.

• ROUNDThe ROUND function returns a number that is rounded to the specified number of places to the right or left of the decimal place.

• ROUND_TIMESTAMPThe ROUND_TIMESTAMP scalar function returns a timestamp that is rounded to the unit that is specified by the timestamp format string.

• ROWIDThe ROWID function returns a row ID representation of its argument.

• RPADThe RPAD function returns a string that is padded on the right with blanks or a specified string.

• RTRIMThe RTRIM function removes bytes from the end of a string expression based on the content of a trim expression.

• SCOREThe SCORE function searches a text search index using criteria that are specified in a search argument and returns a relevance score that measures how well a document matches the query.

• SECONDThe SECOND function returns the seconds part of a value with optional fractional seconds.

• SIGNThe SIGN function returns an indicator of the sign of the argument.

• SINThe SIN function returns the sine of the argument, where the argument is an angle, expressed in radians.

• SINHThe SINH function returns the hyperbolic sine of the argument, where the argument is an angle, expressed in radians.

• SMALLINTThe SMALLINT function returns a small integer representation either of a number or of a string representation of a number.

• SOUNDEXThe SOUNDEX function returns a 4-character code that represents the sound of the words in the argument. The result can be compared to the results of the SOUNDEX function of other strings.

• SOAPHTTPC and SOAPHTTPVThe SOAPHTTPC function returns a CLOB representation of XML data that results from a SOAP request to the web service that is specified by the first argument. The SOAPHTTPV function returns a VARCHAR representation of XML data that results from a SOAP request to the web service that is specified by the first argument.

• SOAPHTTPNC and SOAPHTTPNVThe SOAPHTTPNC and SOAPHTTPNV functions allow you to specify a complete SOAP message as input and to return complete SOAP messages from the specified web service. The returned SOAP messages are CLOB or VARCHAR representations of the returned XML data.

• SPACEThe SPACE function returns a character string that consists of the number of SBCS blanks that the argument specifies.

• SQRTThe SQRT function returns the square root of the argument.

• STRIPThe STRIP function removes blanks or another specified character from the end, the beginning, or both ends of a string expression.

• SUBSTRThe SUBSTR function returns a substring of a string.

• SUBSTRINGThe SUBSTRING function returns a substring of a string.

• TANThe TAN function returns the tangent of the argument, where the argument is an angle, expressed in radians.

• TANHThe TANH function returns the hyperbolic tangent of the argument, where the argument is an angle, expressed in radians.

• TIMEThe TIME function returns a time that is derived from a value.

• TIMESTAMPThe TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value from its argument or arguments.

• TIMESTAMPADDThe TIMESTAMPADD function returns the result of adding the specified number of the designated interval to the timestamp value.

• TIMESTAMP_FORMATThe TIMESTAMP_FORMAT function returns a TIMESTAMP WITHOUT TIME ZONE value that is based on the interpretation of the input string using the specified format.

• TIMESTAMP_ISOThe TIMESTAMP_ISO function returns a timestamp value that is based on a date, a time, or a timestamp argument.

• TIMESTAMPDIFFThe TIMESTAMPDIFF function returns an estimated number of intervals of the type that is defined by the first argument, based on the difference between two timestamps.

• TIMESTAMP_TZ The TIMESTAMP_TZ function returns a TIMESTAMP WITH TIME ZONE value from the input arguments.

• TO_CHARThe TO_CHAR function returns a character string representation of a timestamp value that has been formatted using a specified character template.

• TO_DATEThe TO_DATE function returns a timestamp value that is based on the interpretation of the input string using the specified format.

• TO_NUMBER The TO_NUMBER function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

• TOTALORDERThe TOTALORDER function returns an ordering for DECFLOAT values. The TOTALORDER function returns a small integer value that indicates how expression1 compares with expression2.

• TRANSLATEThe TRANSLATE function returns a value in which one or more characters of the first argument might have been converted to other characters.

• TRIM The TRIM function removes bytes from the beginning, from the end, or from both the beginning and end of a string expression.

• TRUNCATE or TRUNCThe TRUNCATE function returns the first argument, truncated as specified. Truncation is to the number of places to the right or left of the decimal point this is specified by the second argument.

• TRUNC_TIMESTAMPThe TRUNC_TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value that is the expression, truncated to the unit that is specified by the format-string.

• UCASEThe UCASE function returns a string in which all the characters have been converted to uppercase characters, based on the CCSID of the argument. The UCASE function is identical to the UPPER function.

• UNICODEThe UNICODE function returns the Unicode UTF-16 code value of the leftmost character of the argument as an integer.

• UNICODE_STRThe UNICODE_STR function returns a string in Unicode UTF-8 or UTF-16, depending on the specified option. The string represents a Unicode encoding of the input string.

• UPPERThe UPPER function returns a string in which all the characters have been converted to uppercase characters.

• VALUEThe VALUE function returns the value of the first non-null expression.

• VARBINARYThe VARBINARY function returns a VARBINARY (varying-length binary string) representation of a string of any type.

• VARCHARThe VARCHAR function returns a varying-length character string representation of the value specified by the first argument. The first argument can be a character string, a graphic string, a datetime value, an integer number, a decimal number, a floating-point number, or a row ID value.

• VARCHAR_FORMATThe VARCHAR_FORMAT function returns a character string representation of the first argument in the format indicated by format-string.

• VARGRAPHICThe VARGRAPHIC function returns a varying-length graphic string representation of a the first argument. The first argument can be a character string value or a graphic string value.

• VERIFY_GROUP_FOR_USERThe VERIFY_GROUP_FOR_USER function returns a value that indicates whether the primary authorization ID and the secondary authorization IDs that are associated with the first argument are in the authorization names that are specified in the list of the second argument.

• VERIFY_ROLE_FOR_USERThe VERIFY_ROLE_FOR_USER function returns a value that indicates whether the roles that are associated with the authorization ID that is specified in the first argument are included in the role names that are specified in the list of the second argument.

• VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER

The VERIFY_TRUSTED_CONTEXT_FOR_USER function returns a value that indicates whether the authorization ID that is associated with first argument has acquired a role in a trusted connection and whether that acquired role is included in the role names that are specified in the list of the second argument.

• WEEKThe WEEK function returns an integer in the range of 1 to 54 that represents the week of the year. The week starts with Sunday, and January 1 is always in the first week.

• WEEK_ISOThe WEEK_ISO function returns an integer in the range of 1 to 53 that represents the week of the year. The week starts with Monday and includes seven days. Week 1 is the first week of the year that contains a Thursday, which is equivalent to the first week that contains January 4.

• XMLATTRIBUTESThe XMLATTRIBUTES function constructs XML attributes from the arguments. This function can be used as an argument only for the XMLELEMENT function.

• XMLCOMMENTThe XMLCOMMENT function returns an XML value with a single comment node from a string expression. The content of the comment node is the value of the input string expression, mapped to Unicode (UTF-8).

• XMLCONCATThe XMLCONCAT function returns an XML sequence that contains the concatenation of a variable number of XML input arguments.

• XMLDOCUMENTThe XMLDOCUMENT function returns an XML value with a single document node and zero or more nodes as its children. The content of the generated XML document node is specified by a list of expressions.

• XMLELEMENTThe XMLELEMENT function returns an XML value that is an XML element node.

• XMLFORESTThe XMLFOREST function returns an XML value that is a sequence of XML element nodes.

• XMLMODIFY The XMLMODIFY function returns an XML value that might have been modified by the evaluation of an XQuery updating expression and XQuery variables that are specified as input arguments.

• XMLNAMESPACESThe XMLNAMESPACES function constructs namespace declarations from the arguments. This function can be used as an argument only for specific functions, such as the XMLELEMENT function and the XMLFOREST function.

• XMLPARSEThe XMLPARSE function parses the argument as an XML document and returns an XML value.

• XMLPIThe XMLPI function returns an XML value with a single processing instruction node.

• XMLQUERYThe XMLQUERY function returns an XML value from the evaluation of an XQuery expression, by using specified input arguments, a context item, and XQuery variables.

• XMLSERIALIZEThe XMLSERIALIZE function returns a serialized XML value of the specified data type that is generated from the first argument.

• XMLTEXTThe XMLTEXT function returns an XML value with a single text node that contains the value of the argument.

• XMLXSROBJECTID The XMLXSROBJECTID function returns the XSR object identifier of the XML schema that is used to validate the XML document specified in the argument.

• XSLTRANSFORM The XSLTRANSFORM function transforms an XML document into a different data format. The output can be any form possible for the XSLT processor, including but not limited to XML, HTML, and plain text.

• YEARThe YEAR function returns the year part of a value that is a character or graphic string. The value must be a valid string representation of a date or timestamp.

Page 118: Db2 SQL Query

List of Scalar Functions

• DIFFERENCEThe DIFFERENCE function returns a value, from 0 to 4, that represents the difference between the sounds of two strings, based on applying the SOUNDEX function to the strings. A value of 4 is the best possible sound match.

• DIGITSThe DIGITS function returns a character string representation of the absolute value of a number.

Page 119: Db2 SQL Query

List of Scalar Functions

• DOUBLE_PRECISION or DOUBLEThe DOUBLE_PRECISION and DOUBLE functions returns a floating-point representation of either a number or a character-string or graphic-string representation of a number, an integer, a decimal number, or a floating-point number.

• DSN_XMLVALIDATEThe DSN_XMLVALIDATE function returns an XML value that is the result of applying XML schema validation to the first argument of the function. DSN_XMLVALIDATE can validate XML data that has a maximum length of 2 GB - 1 byte.

Page 120: Db2 SQL Query

List of Scalar Functions

• EBCDIC_CHRThe EBCDIC_CHR function returns the character that has the EBCDIC code value that is specified by the argument.

• EBCDIC_STRThe EBCDIC_STR function returns a string, in the system EBCDIC CCSID, that is an EBCDIC version of the string.

Page 121: Db2 SQL Query

List of Scalar Functions

• ENCRYPT_TDESThe ENCRYPT_TDES function returns a value that is the result of encrypting the first argument by using the Triple DES encryption algorithm. The function can also set the password that is used for encryption.

• EXPThe EXP function returns a value that is the base of the natural logarithm (e), raised to a power that is specified by the argument. The EXP and LN functions are inverse operations.

Page 122: Db2 SQL Query

List of Scalar Functions

• EXTRACTThe EXTRACT function returns a portion of a date or timestamp, based on its arguments.

• FLOATThe FLOAT function returns a floating-point representation of either a number or a string representation of a number. FLOAT is a synonym for the DOUBLE function.

Page 123: Db2 SQL Query

List of Scalar Functions

• FLOORThe FLOOR function returns the largest integer value that is less than or equal to the argument.

• GENERATE_UNIQUEThe GENERATE_UNIQUE function returns a bit data character string that is unique, compared to any other execution of the same function.

Page 124: Db2 SQL Query

List of Scalar Functions

• GETHINTThe GETHINT function returns a hint for the password if a hint was embedded in the encrypted data. A password hint is a phrase that helps you remember the password with which the data was encrypted. For example, 'Ocean' might be used as a hint to help remember the password 'Pacific'.

• GETVARIABLEThe GETVARIABLE function returns a varying-length character-string representation of the current value of the session variable that is identified by the argument.

Page 125: Db2 SQL Query

List of Scalar Functions

• GRAPHICThe GRAPHIC function returns a fixed-length graphic-string representation of a character string or a graphic string value, depending on the type of the first argument.

• HEXThe HEX function returns a hexadecimal representation of a value.

Page 126: Db2 SQL Query

List of Scalar Functions

• HOURThe HOUR function returns the hour part of a value.

• IDENTITY_VAL_LOCALThe IDENTITY_VAL_LOCAL function returns the most recently assigned value for an identity column.

Page 127: Db2 SQL Query

List of Scalar Functions

• IFNULLThe IFNULL function returns the first nonnull expression.

• INSERTThe INSERT function returns a string where, beginning at start in source-string, length characters have been deleted and insert-string has been inserted.

Page 128: Db2 SQL Query

List of Scalar Functions

• INTEGER or INTThe INTEGER function returns an integer representation of either a number or a character string or graphic string representation of an integer.

• JULIAN_DAYThe JULIAN_DAY function returns an integer value that represents a number of days from January 1, 4713 B.C. (the start of the Julian date calendar) to the date that is specified in the argument.

Page 129: Db2 SQL Query

List of Scalar Functions

• LAST_DAYThe LAST_DAY scalar function returns a date that represents the last day of the month of the date argument.

• LCASEThe LCASE function returns a string in which all the characters are converted to lowercase characters.

Page 130: Db2 SQL Query

List of Scalar Functions

• LEFTThe LEFT function returns a string that consists of the specified number of leftmost bytes of the specified string units.

• LENGTHThe LENGTH function returns the length of a value.

Page 131: Db2 SQL Query

List of Scalar Functions

• LNThe LN function returns the natural logarithm of the argument. The LN and EXP functions are inverse operations.

• LOCATEThe LOCATE function returns the position at which the first occurrence of an argument starts within another argument.

Page 132: Db2 SQL Query

List of Scalar Functions

• LOCATE_IN_STRINGThe LOCATE_IN_STRING function returns the position at which an argument starts within a specified string.

• LOG10The LOG10 function returns the common logarithm (base 10) of a number.

Page 133: Db2 SQL Query

List of Scalar Functions

• LOWERThe LOWER function returns a string in which all the characters are converted to lowercase characters.

• LPADThe LPAD function returns a string that is composed of string-expression that is padded on the left, with pad or blanks. The LPAD function treats leading or trailing blanks in string-expression as significant.

Page 134: Db2 SQL Query

List of Scalar Functions

• LTRIMThe LTRIM function removes bytes from the beginning of a string expression based on the content of a trim expression.

• MAXThe MAX scalar function returns the maximum value in a set of values.

Page 135: Db2 SQL Query

List of Scalar Functions

• MICROSECONDThe MICROSECOND function returns the microsecond part of a value.

• MIDNIGHT_SECONDSThe MIDNIGHT_SECONDS function returns an integer, in the range of 0 to 86400, that represents the number of seconds between midnight and the time that is specified in the argument.

Page 136: Db2 SQL Query

List of Scalar Functions

• MINThe MIN scalar function returns the minimum value in a set of values.

• MINUTEThe MINUTE function returns the minute part of a value.

Page 137: Db2 SQL Query

List of Scalar Functions

• MODThe MOD function divides the first argument by the second argument and returns the remainder.

• MONTHThe MONTH function returns the month part of a value.

Page 138: Db2 SQL Query

List of Scalar Functions

• MONTHS_BETWEENThe MONTHS_BETWEEN function returns an estimate of the number of months between two arguments.

• MQREADThe MQREAD function returns a message from a specified MQSeries® location without removing the message from the queue.

Page 139: Db2 SQL Query

List of Scalar Functions

• MQREADCLOBThe MQREADCLOB function returns a message from a specified MQSeries location without removing the message from the queue.

• MQRECEIVEThe MQRECEIVE function returns a message from a specified MQSeries location and removes the message from the queue.

Page 140: Db2 SQL Query

List of Scalar Functions

• MQRECEIVECLOBThe MQRECEIVECLOB function returns a message from a specified MQSeries location and removes the message from the queue.

• MQSENDThe MQSEND function sends data to a specified MQSeries location, and returns a varying-length character string that indicates whether the function was successful or unsuccessful.

Page 141: Db2 SQL Query

List of Scalar Functions

• MULTIPLY_ALTThe MULTIPLY_ALT scalar function returns the product of the two arguments. This function is an alternative to the multiplication operator and is especially useful when the sum of the precisions of the arguments exceeds 31.

• NEXT_DAYThe NEXT_DAY function returns a datetime value that represents the first weekday, named by string-expression, that is later than the date in expression.

Page 142: Db2 SQL Query

List of Scalar Functions

• NORMALIZE_DECFLOATThe NORMALIZE_DECFLOAT function returns a DECFLOAT value that is the result of the argument, set to its simplest form. That is, a non-zero number that has any trailing zeros in the coefficient has those zeros removed by dividing the coefficient by the appropriate power of ten and adjusting the exponent accordingly. A zero has its exponent set to 0.

Page 143: Db2 SQL Query

List of Scalar Functions

• NORMALIZE_STRINGThe NORMALIZE_STRING function takes a Unicode string argument and returns a normalized string that can be used for comparison.

• NULLIFThe NULLIF function returns the null value if the two arguments are equal; otherwise, it returns the value of the first argument.

Page 144: Db2 SQL Query

List of Scalar Functions

• NVL The NVL function returns the first argument that is not null.

• OVERLAYThe OVERLAY function returns a string that is composed of one argument that is inserted into another argument at the same position where some number of bytes have been deleted.

Page 145: Db2 SQL Query

List of Scalar Functions

• PACK The PACK function returns a binary string value that contains a data type array and a packed representation of each non-null expression argument.

• POSITIONThe POSITION function returns the position of the first occurrence of an argument within another argument, where the position is expressed in terms of the string units that are specified.

Page 146: Db2 SQL Query

List of Scalar Functions

• POSSTRThe POSSTR function returns the position of the first occurrence of an argument within another argument.

• POWERThe POWER® function returns the value of the first argument to the power of the second argument.

Page 147: Db2 SQL Query

List of Scalar Functions

• QUANTIZEThe QUANTIZE function returns a DECFLOAT value that is equal in value (except for any rounding) and sign to the first argument and that has an exponent that is set to equal the exponent of the second argument.

• QUARTERThe QUARTER function returns an integer between 1 and 4 that represents the quarter of the year in which the date resides. For example, any dates in January, February, or March return the integer 1.

Page 148: Db2 SQL Query

List of Scalar Functions

• RADIANSThe RADIANS function returns the number of radians for an argument that is expressed in degrees.

• RAISE_ERRORThe RAISE_ERROR function causes the statement that invokes the function to return an error with the specified SQLSTATE (along with SQLCODE -438) and error condition. The RAISE_ERROR function always returns the null value with an undefined data type.

Page 149: Db2 SQL Query

List of Scalar Functions

• RANDThe RAND function returns a random floating-point value between 0 and 1. An argument can be specified as an optional seed value.

• REALThe REAL function returns a single-precision floating-point representation of either a number or a string representation of a number.

Page 150: Db2 SQL Query

List of Scalar Functions

• REPEATThe REPEAT function returns a character string that is composed of an argument that is repeated a specified number of times.

• REPLACEThe REPLACE function replaces all occurrences of search-string in source-string with replace-string. If search-string is not found in source-string, source-string is returned unchanged.

Page 151: Db2 SQL Query

List of Scalar Functions

• RIDThe RID function returns the record ID (RID) of a row. The RID is used to uniquely identify a row.

• RIGHTThe RIGHT function returns a string that consists of the specified number of rightmost bytes or specified string unit from a string.

Page 152: Db2 SQL Query

List of Scalar Functions

• ROUNDThe ROUND function returns a number that is rounded to the specified number of places to the right or left of the decimal place.

• ROUND_TIMESTAMPThe ROUND_TIMESTAMP scalar function returns a timestamp that is rounded to the unit that is specified by the timestamp format string.

Page 153: Db2 SQL Query

List of Scalar Functions

• ROWIDThe ROWID function returns a row ID representation of its argument.

• RPADThe RPAD function returns a string that is padded on the right with blanks or a specified string.

Page 154: Db2 SQL Query

List of Scalar Functions

• RTRIMThe RTRIM function removes bytes from the end of a string expression based on the content of a trim expression.

• SCOREThe SCORE function searches a text search index using criteria that are specified in a search argument and returns a relevance score that measures how well a document matches the query.

Page 155: Db2 SQL Query

List of Scalar Functions

• SECONDThe SECOND function returns the seconds part of a value with optional fractional seconds.

• SIGNThe SIGN function returns an indicator of the sign of the argument.

Page 156: Db2 SQL Query

List of Scalar Functions

• SINThe SIN function returns the sine of the argument, where the argument is an angle, expressed in radians.

• SINHThe SINH function returns the hyperbolic sine of the argument, where the argument is an angle, expressed in radians.

Page 157: Db2 SQL Query

List of Scalar Functions

• SMALLINTThe SMALLINT function returns a small integer representation either of a number or of a string representation of a number.

• SOUNDEXThe SOUNDEX function returns a 4-character code that represents the sound of the words in the argument. The result can be compared to the results of the SOUNDEX function of other strings.

Page 158: Db2 SQL Query

List of Scalar Functions

• SOAPHTTPC and SOAPHTTPVThe SOAPHTTPC function returns a CLOB representation of XML data that results from a SOAP request to the web service that is specified by the first argument. The SOAPHTTPV function returns a VARCHAR representation of XML data that results from a SOAP request to the web service that is specified by the first argument.

Page 159: Db2 SQL Query

List of Scalar Functions

• SOAPHTTPNC and SOAPHTTPNVThe SOAPHTTPNC and SOAPHTTPNV functions allow you to specify a complete SOAP message as input and to return complete SOAP messages from the specified web service. The returned SOAP messages are CLOB or VARCHAR representations of the returned XML data.

Page 160: Db2 SQL Query

List of Scalar Functions

• SPACEThe SPACE function returns a character string that consists of the number of SBCS blanks that the argument specifies.

• SQRTThe SQRT function returns the square root of the argument.

Page 161: Db2 SQL Query

List of Scalar Functions

• STRIPThe STRIP function removes blanks or another specified character from the end, the beginning, or both ends of a string expression.

• SUBSTRThe SUBSTR function returns a substring of a string.

Page 162: Db2 SQL Query

List of Scalar Functions

• SUBSTRINGThe SUBSTRING function returns a substring of a string.

• TANThe TAN function returns the tangent of the argument, where the argument is an angle, expressed in radians.

Page 163: Db2 SQL Query

List of Scalar Functions

• TANHThe TANH function returns the hyperbolic tangent of the argument, where the argument is an angle, expressed in radians.

• TIMEThe TIME function returns a time that is derived from a value.

Page 164: Db2 SQL Query

List of Scalar Functions

• TIMESTAMPThe TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value from its argument or arguments.

• TIMESTAMPADDThe TIMESTAMPADD function returns the result of adding the specified number of the designated interval to the timestamp value.

Page 165: Db2 SQL Query

List of Scalar Functions

• TIMESTAMP_FORMATThe TIMESTAMP_FORMAT function returns a TIMESTAMP WITHOUT TIME ZONE value that is based on the interpretation of the input string using the specified format.

• TIMESTAMP_ISOThe TIMESTAMP_ISO function returns a timestamp value that is based on a date, a time, or a timestamp argument.

Page 166: Db2 SQL Query

List of Scalar Functions

• TIMESTAMPDIFFThe TIMESTAMPDIFF function returns an estimated number of intervals of the type that is defined by the first argument, based on the difference between two timestamps.

• TIMESTAMP_TZ The TIMESTAMP_TZ function returns a TIMESTAMP WITH TIME ZONE value from the input arguments.

Page 167: Db2 SQL Query

List of Scalar Functions

• TO_CHARThe TO_CHAR function returns a character string representation of a timestamp value that has been formatted using a specified character template.

• TO_DATEThe TO_DATE function returns a timestamp value that is based on the interpretation of the input string using the specified format.

Page 168: Db2 SQL Query

List of Scalar Functions

• TO_NUMBER The TO_NUMBER function returns a DECFLOAT(34) value that is based on the interpretation of the input string using the specified format.

• TOTALORDERThe TOTALORDER function returns an ordering for DECFLOAT values. The TOTALORDER function returns a small integer value that indicates how expression1 compares with expression2.

Page 169: Db2 SQL Query

List of Scalar Functions

• TRANSLATEThe TRANSLATE function returns a value in which one or more characters of the first argument might have been converted to other characters.

• TRIM The TRIM function removes bytes from the beginning, from the end, or from both the beginning and end of a string expression.

Page 170: Db2 SQL Query

List of Scalar Functions

• TRUNCATE or TRUNCThe TRUNCATE function returns the first argument, truncated as specified. Truncation is to the number of places to the right or left of the decimal point this is specified by the second argument.

• TRUNC_TIMESTAMPThe TRUNC_TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value that is the expression, truncated to the unit that is specified by the format-string.

Page 171: Db2 SQL Query

List of Scalar Functions

• UCASEThe UCASE function returns a string in which all the characters have been converted to uppercase characters. The UCASE function is identical to the UPPER function.

• UNICODEThe UNICODE function returns the Unicode UTF-16 code value of the leftmost character of the argument as an integer.

Page 172: Db2 SQL Query

List of Scalar Functions

• UNICODE_STRThe UNICODE_STR function returns a string in Unicode UTF-8 or UTF-16, depending on the specified option. The string represents a Unicode encoding of the input string.

• UPPERThe UPPER function returns a string in which all the characters have been converted to uppercase characters.

Page 173: Db2 SQL Query

List of Scalar Functions

• VALUEThe VALUE function returns the value of the first non-null expression.

• VARBINARYThe VARBINARY function returns a VARBINARY (varying-length binary string) representation of a string of any type.

Page 174: Db2 SQL Query

List of Scalar Functions

• VARCHARThe VARCHAR function returns a varying-length character string representation of the value specified by the first argument. The first argument can be a character string, a graphic string, a datetime value, an integer number, a decimal number, a floating-point number, or a row ID value.

Page 175: Db2 SQL Query

List of Scalar Functions

• VARCHAR_FORMATThe VARCHAR_FORMAT function returns a character string representation of the first argument in the format indicated by format-string.

Page 176: Db2 SQL Query

List of Scalar Functions

• VARGRAPHICThe VARGRAPHIC function returns a varying-length graphic string representation of a the first argument. The first argument can be a character string value or a graphic string value.

• VERIFY_GROUP_FOR_USERThe VERIFY_GROUP_FOR_USER function returns a value that indicates whether the primary authorization ID and the secondary authorization IDs that are associated with the first argument are in the authorization names that are specified in the list of the second argument.

Page 177: Db2 SQL Query

List of Scalar Functions

• VERIFY_ROLE_FOR_USERThe VERIFY_ROLE_FOR_USER function returns a value that indicates whether the roles that are associated with the authorization ID that is specified in the first argument are included in the role names that are specified in the list of the second argument.

Page 178: Db2 SQL Query

List of Scalar Functions

• VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER

The VERIFY_TRUSTED_CONTEXT_FOR_USER function returns a value that indicates whether the authorization ID that is associated with first argument has acquired a role in a trusted connection and whether that acquired role is included in the role names that are specified in the list of the second argument.

Page 179: Db2 SQL Query

List of Scalar Functions

• WEEKThe WEEK function returns an integer in the range of 1 to 54 that represents the week of the year. The week starts with Sunday, and January 1 is always in the first week.

• WEEK_ISOThe WEEK_ISO function returns an integer in the range of 1 to 53 that represents the week of the year. The week starts with Monday and includes seven days. Week 1 is the first week of the year that contains a Thursday, which is equivalent to the first week that contains January 4.

Page 180: Db2 SQL Query

List of Scalar Functions

• XMLATTRIBUTESThe XMLATTRIBUTES function constructs XML attributes from the arguments. This function can be used as an argument only for the XMLELEMENT function.

• XMLCOMMENTThe XMLCOMMENT function returns an XML value with a single comment node from a string expression. The content of the comment node is the value of the input string expression, mapped to Unicode (UTF-8).

Page 181: Db2 SQL Query

List of Scalar Functions

• XMLCONCATThe XMLCONCAT function returns an XML sequence that contains the concatenation of a variable number of XML input arguments.

• XMLDOCUMENTThe XMLDOCUMENT function returns an XML value with a single document node and zero or more nodes as its children. The content of the generated XML document node is specified by a list of expressions.

Page 182: Db2 SQL Query

List of Scalar Functions

• XMLELEMENTThe XMLELEMENT function returns an XML value that is an XML element node.

• XMLFORESTThe XMLFOREST function returns an XML value that is a sequence of XML element nodes.

• XMLMODIFY The XMLMODIFY function returns an XML value that might have been modified by the evaluation of an XQuery updating expression and XQuery variables that are specified as input arguments.

Page 183: Db2 SQL Query

List of Scalar Functions

• XMLNAMESPACESThe XMLNAMESPACES function constructs namespace declarations from the arguments. This function can be used as an argument only for specific functions, such as the XMLELEMENT function and the XMLFOREST function.

• XMLPARSEThe XMLPARSE function parses the argument as an XML document and returns an XML value.

Page 184: Db2 SQL Query

List of Scalar Functions

• XMLPIThe XMLPI function returns an XML value with a single processing instruction node.

• XMLQUERYThe XMLQUERY function returns an XML value from the evaluation of an XQuery expression, by using specified input arguments, a context item, and XQuery variables.

Page 185: Db2 SQL Query

List of Scalar Functions

• XMLSERIALIZEThe XMLSERIALIZE function returns a serialized XML value of the specified data type that is generated from the first argument.

• XMLTEXTThe XMLTEXT function returns an XML value with a single text node that contains the value of the argument.

Page 186: Db2 SQL Query

List of Scalar Functions

• XMLXSROBJECTID The XMLXSROBJECTID function returns the XSR object identifier of the XML schema that is used to validate the XML document specified in the argument.

• XSLTRANSFORM The XSLTRANSFORM function transforms an XML document into a different data format. The output can be any form possible for the XSLT processor, including but not limited to XML, HTML, and plain text.

Page 187: Db2 SQL Query

List of Scalar Functions

• YEARThe YEAR function returns the year part of a value that is a character or graphic string. The value must be a valid string representation of a date or timestamp.

Page 188: Db2 SQL Query

Thank You