Presentation is loading. Please wait.

Presentation is loading. Please wait.

Texas State Technical College DISCOVER! Conversion Functions “Convert this!”

Similar presentations


Presentation on theme: "Texas State Technical College DISCOVER! Conversion Functions “Convert this!”"— Presentation transcript:

1 Texas State Technical College DISCOVER! Conversion Functions “Convert this!”

2 Texas State Technical College DISCOVER! Conversion functions are utilized to change the data type of a value from one to another. There are 3 primary data types in Oracle SQL (text, numeric, date) thus there are 3 primary functions in this set. The 3 primary functions are as follows: to_char()to_char() to_number()to_number() to_date()to_date() Overview Conversion Functions

3 Texas State Technical College DISCOVER! Converts the given value to a character string. Syntax String to_char(Type object, [String strFormat]) ExampleSELECT cust.nameAS “Customer”, to_char(cust.debt, “$99,999.99”) AS “Total Debt”, to_char(cust.due_date, “YYYY”) AS “Year Due” to_char(cust.due_date, “YYYY”) AS “Year Due”FROM customer cust ; To_Char Conversion Functions

4 Texas State Technical College DISCOVER! The character format strings differ based on the data type being converted. Number Any unrecognized symbol appears as is. Utilizes the standard numeric formatting 9 represents a single decimal digit. represents the decimal point Date Uses the standard date formatting which is covered in a few slides. To_Char Formats Conversion Functions

5 Texas State Technical College DISCOVER! Converts the given value to a numeric value, if possible. Syntax Number to_number(Type object) ExampleSELECT cust.name AS “Customer” FROM customer cust WHERE ( to_number(to_char(cust.due_date, “YYYY”)) - to_number(to_char(cust.due_date, “YYYY”)) - to_number(to_char(sysdate, “YYYY”)) to_number(to_char(sysdate, “YYYY”)) ) > 5 ) > 5; To_Number Conversion Functions

6 Texas State Technical College DISCOVER! Converts the given date string to the appropriate date object. Syntax Date to_date(String strDate, [String strFormat]) ExampleUPDATEcustomerSET c_dob = to_date(“10/01/1981”, “MM/DD/YYYY”) WHERE c_id = 34587 ; To_Date Conversion Functions

7 Texas State Technical College DISCOVER! The following characters have special meaning in a date format string. SymbolMeaning MONTHFull Month Name MON3 Letter Month Name MM2 Digit Month D1 Digit Day of Week DD2 Digit Day of Month DDD3 Digit Day of Year DAYFull Day of Week DY3 Digit Day of Week YYYY4 Digit Year YEARFull Year Name To_Date Formats Conversion Functions

8 Texas State Technical College DISCOVER! In Summary… The conversion functions transform values to different data types, if possible. The 3 primary conversion functions are as follows: to_char()to_char() to_number()to_number() to_date()to_date() Some conversion functions require a format string that uses special characters dependent upon the type of data being converted. Conversion Functions


Download ppt "Texas State Technical College DISCOVER! Conversion Functions “Convert this!”"

Similar presentations


Ads by Google