Jumat, 21 Oktober 2011

Conversion Function


Resume kuliah Pemrograman Basis Data 2 - Pertemuan 2

Resume : 2
Mata Kuliah : Pemrograman Basis Data 2

*** Macam - macam conversion Function ***
1. To_char 

  • Fungsi To_char mengubah nomor atau tanggal ke string.
  • Sintaks : To_char (value, [format_mask],[nls_language])
  • nilai baik dapat berupa angka atau tanggal yang akan dikonversi ke string
  • Format_mask adalah opsional. Ini adalah format yang akan digunakan untuk konversi nilai string.
  • Nls_language adalah opsional. Ini adalah bahasa nls digunakan untuk mengkonversi nilai string
  • Berikut ini adalah sejumlah contoh untuk fungsi To_char:

to_char(1210.73, '9999.9')would return '1210.7'
to_char(1210.73, '9,999.99')would return '1,210.73'
to_char(1210.73, '$9,999.00')would return '$1,210.73'
to_char(21, '000099')would return '000021'



  •  Berikut ini daftar parameter yang valid ketika funsi To_char digunakan untuk mengkonversi tanggal untuk string. Parameter ini dapat digunakan dalam banyak kombinasi.

ParameterExplanation
YEARYear, spelled out
YYYY4-digit year
YYY
YY
Y
Last 3, 2, or 1 digit(s) of year.
IYY
IY
I
Last 3, 2, or 1 digit(s) of ISO year.
IYYY4-digit year based on the ISO standard
QQuarter of year (1, 2, 3, 4; JAN-MAR = 1).
MMMonth (01-12; JAN = 01).
MONAbbreviated name of month.
MONTHName of month, padded with blanks to length of 9 characters.
RMRoman numeral month (I-XII; JAN = I).
WWWeek of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
WWeek of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IWWeek of year (1-52 or 1-53) based on the ISO standard.
DDay of week (1-7).
DAYName of day.
DDDay of month (1-31).
DDDDay of year (1-366).
DYAbbreviated name of day.
JJulian day; the number of days since January 1, 4712 BC.
HHHour of day (1-12).
HH12Hour of day (1-12).
HH24Hour of day (0-23).
MIMinute (0-59).
SSSecond (0-59).
SSSSSSeconds past midnight (0-86399).
FFFractional seconds.


  •  Berikut ini adalah tanggal contoh untuk fungsi To_char:

to_char(sysdate, 'yyyy/mm/dd');would return '2003/07/09'
to_char(sysdate, 'Month DD, YYYY');would return 'July 09, 2003'
to_char(sysdate, 'FMMonth DD, YYYY');would return 'July 9, 2003'
to_char(sysdate, 'MON DDth, YYYY');would return 'JUL 09TH, 2003'
to_char(sysdate, 'FMMON DDth, YYYY');would return 'JUL 9TH, 2003'
to_char(sysdate, 'FMMon ddth, YYYY');would return 'Jul 9th, 2003'
Sumber : link

2. To_Date

  • FungsiTo_date adalah mengkonversi string ke tanggal
  • Sintaks : To_date (string1, [format_mask], [nls_language])
  • String 1 adalah string yang akan dikonversi ke tanggal
  • Format_mask adalah opsional. Ini adalah format yang akan digunakan untuk mengkonversi string 1 untuk acuan.
  • Nls_language adalah opsional. Ini adalah bahasa nls digunakan untuk mengkonversi sring 1 untuk acuan.
  • Berikut ini adalah daftar pilihan untuk parameter format_mask. Parameter ini dapat digunakan dalam banyak kombinasi.
ParameterExplanation
YEARYear, spelled out
YYYY4-digit year
YYY
YY
Y
Last 3, 2, or 1 digit(s) of year.
IYY
IY
I
Last 3, 2, or 1 digit(s) of ISO year.
IYYY4-digit year based on the ISO standard
RRRRAccepts a 2-digit year and returns a 4-digit year.
A value between 0-49 will return a 20xx year.
A value between 50-99 will return a 19xx year.
QQuarter of year (1, 2, 3, 4; JAN-MAR = 1).
MMMonth (01-12; JAN = 01).
MONAbbreviated name of month.
MONTHName of month, padded with blanks to length of 9 characters.
RMRoman numeral month (I-XII; JAN = I).
WWWeek of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
WWeek of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IWWeek of year (1-52 or 1-53) based on the ISO standard.
DDay of week (1-7).
DAYName of day.
DDDay of month (1-31).
DDDDay of year (1-366).
DYAbbreviated name of day.
JJulian day; the number of days since January 1, 4712 BC.
HHHour of day (1-12).
HH12Hour of day (1-12).
HH24Hour of day (0-23).
MIMinute (0-59).
SSSecond (0-59).
SSSSSSeconds past midnight (0-86399).
FFFractional seconds. Use a value from 1 to 9 after FF to indicate the number of digits in the fractional seconds. For example, 'FF4'.
AM, A.M., PM, or P.M.Meridian indicator
AD or A.DAD indicator
BC or B.C.BC indicator
TZDDaylight savings information. For example, 'PST'
TZHTime zone hour.
TZMTime zone minute.
TZRTime zone region.
  • Contoh :

to_date('2003/07/09', 'yyyy/mm/dd')would return a date value of July 9, 2003.
to_date('070903', 'MMDDYY')would return a date value of July 9, 2003.
to_date('20020315', 'yyyymmdd')would return a date value of Mar 15, 2002.


Sumber : Link


3. To_Number

  • Fungsi To_number adalah mengkonversi string ke nomor
  • Sintaks: adalah string yang akan dikonversi  to_number (string1, [format_mask], [nls_language])
  • String 1 adalah string yang akan dikonversi ke nomor.
  • Format_mask adalah opsional. Ini adalah format yang akan digunakan untuk mengkonversi string1 ke suatu nomor
  • Nls_language adalah opsional. Ini adalah bahasa nls digunakan untuk mengkonversi string1 ke suatu nomor.
  • contoh:

to_number('1210.73', '9999.99')would return the number 1210.73
to_number('546', '999')would return the number 546
to_number('23', '99')would return the number 23

Sumber: link 

Tidak ada komentar:

Posting Komentar