You are on page 1of 6

There is different conversion function which used to convert one

form of data into another format. The BODS support most of basic
conversion functions.
Here, I will explain the syntax and examples for those conversion
functions.

1. To_char
The to_char function used to convert number or date value into
string format.
This function will help you to convert a number or date to string.
The syntax for this function is given below with examples.
To_char(number or date, format)

Number to string.
e.g.

to_char(123,9999)= 123

to_char(123,09999)= 0123
to_char(31,xx) = 1f ----> string contains hexadecimal
integer.
to_char(31,xx)= 37 ----> string contains octal integer

Date to string.
e.g.

to_char(sysdate(),MM)= 06 --> month number of the date


to_char(sysdate(),MON)= JUN ---> Month name with 3
letter like JUN
to_char(sysdate(),MONTH)= = JUNE ----> Month name
like 'JUNE'.
to_char(sysdate(),DD)=03 ----> Day part of the date
to_char(sysdate(),YY)=13-----> 2 digit YEAR
to_char(sysdate(),YYYY)=2013----> 4 digit YEAR
to_char(sysdate(),HH)=12----> 2 digit Hour
to_char(sysdate(),MI)=13----> 2 digit Minute
to_char(sysdate(),SS)=13----> 2 digit Second
to_char(sysdate(),FF)=286959000----> Sub second

2. Intervel_to_char

This function is to convert an interval to string. This will help you


find out the date difference between two dates in different format.
Find below given examples and syntax for this function.
The syntax for this function is given below.
Interval_to_char(interval, interval type)
$start_date=2013.01.01 00:00:00
sysdate() = 2013.06.05 17:31:54
Interval_to_char($start_date- sysdate(),D)=155
This statement will give the number of days between given
interval. Similarly,
Interval type:
M for minutes
S for Seconds
H for hours

3. Julian_To_Date
This will convert Julian value to date value.
The syntax for this function is given below.
Julian_to_date(Julian) return date
Julian_to_date(2,451,545) = 2000.01.01 00:00:00
Please refer below link to get more information about Julian day.
https://en.wikipedia.org/wiki/Julian_day

4. Num_to_Intervel
This function will help you to convert an number into interval
value.
The syntax and examples are given below.
If sysdate()=2013.06.05 17:52:21
E.g. sysdate()+num_to_intervel(12,D)=2013.06.17
17:52:21(Adding 12 days to given date)

sysdate()+num_to_intervel(1,H)=2013.06.05
18:52:21(Adding 1 hour to given date)
Similarly, the number can convert into minutes (M) and
seconds(S).
Conversion functions in BODS_Part2
In this section I will explain mainly three conversion function in BO data service. They are mainly CAST, To_Date and
load_to_XML.
1. CAST
Cast function used to explicitly convert an expression in one data type to another data type. The syntax for this
function is given below.
CAST(Expression, data type) return data type.
The expression is the input which will be convert to target data type and the data type should be in build data type .
Syntax for different data type is given below .Please see below given table.

Data Type

Syntax

Varchar

Cast(expression, varchar(length))

decimal

Cast(expression,decimal(Precision,scale))

Integer

Cast(expression,int)

Real

Cast(expression,real)

Double

Cast(expression,double)

Timestamp

Cast(expression,timestamp)

Datetime

Cast(expression,datetime)

Date

Cast(expression,date)

Time

Cast(expression,time)

Intervel

Cast(expression,intervel)

Examples for those functions are given below.

Input Expression

Source and target Datatype

Ouput

CAST(12.20,INT)

Varchar to int

12

CAST(12.20,DECIMAL(3,1))

Varchar to decimal

12.12

CAST(12.20,REAL)

Decimal to real

12.200000

CAST(12.20,DOUBLE)

Decimel to double

12.200000

CAST(12.20,VARCHAR(4))

Decimel to varchar

12.20

Cast(2012.01.01,date)

Varchar to date

2012.01.01

Cast(2012.01.01,datetime)

Varchar to datetime

2012.01.01 00:00:00

Cast(2012.01.01
12:01:12,timestamp)

Datetime to timestamp

2012.01.01 12.01.12.000000000

Cast(sysdate(),time)

Datetime to time

12:21:00

Cast(12.121239,intervel)

Integer to interval

12.121239

This table shows all the data type conversion valid for the cast functions.

From-To

Varchar

Date

DateTim
e

Intege
r

Rea
l

Double

Interva
l

Timestam
p

Time

Decimal

Varchar

Date

DateTime

Integer

Real

Double

Decimal

Interval

Timestam
p

Time

x
x

From above table you will get which one data type can be convert to another one and which all are cant convert to
other data type.

2. TO_DATE

The to_date function used to convert a string to date value. This function converts a string into date format.
The string can also convert into datetime and time value format.
If the input string has more characters than the format string, the extra characters in the input string will be ignored
and will be initialized to the default value.

For example, to_date('10.02.2007 10:12:12, 'DD.MM.YYYY') will convert the date to 10.02.2007 00.00.00. The time
part in the input string will be ignored and initialized to 0.
The syntax of the function is given below.
To_date(string,format) returns date ,datetime or time

FORMATS
DD

Day of the Month(2 Digit)

MM

Month Number(2 Digit)

MONTH

Full Month Name

MON

Month name(3 char)

YY

Year(2 Digit)

YYYY

Year(4 Digit)

HH24

Hour(2 Digit)

MI

Minutes(2 Digit)

SS

Seconds(2 Digit)

FF

Sub Seconds(Upto 9 Digit)

The examples for this function are given below. A string can be converted into date value based on the above given
format.
Please refer below examples.
Function
To_date(jun 18,2012,MON DD,YYYY)
To_date(1March1900,DDMONTHYYYY)
To_date(12-12-01 13:12,MM-YY-DD HH24:MM)
To_date(2012Jan01,YYYYMONDD)

Result

2012.06.18 00:00:00
1900.03.01 00:00:00
2012.12.01 12:00
2012.01.01 00:00:00

These are examples for the string to date conversion .you can do any conversion from string to date based on the
format given.
3. LOAD_TO_XML
This function convert an NRDT(Nested Relational Data Model) into XML and place it as a single column during the
data load.
If the function fails during XML conversion then data services will return NULL value.
The Syntax for this is:

Load_to_XML(nested_table
name,Schema_dtd_name,enable_validation,xml_header,replace_string_nulls,is_top_level_ele
ment,max size)

nested_table_name

Name of NRDM table.

Schema_dtd_name

Name of DTD or XML Schema

enable_validation

Enter 1 to validate and 0 disable validation

xml_header

default is UTF-8

replace_string_nulls

Replace null with this value

is_top_level_element

1 or 0

max size

Expected size of the XML.

Regards
Asgar

You might also like