You are reading the article How Convert Function Works In Oracle? updated in September 2023 on the website Dacquyenphaidep.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Convert Function Works In Oracle?
Definition of Oracle CONVERT Function
Oracle Convert Function is responsible for transforming a string value from one character set to a different one. Here, a character set can be defined as a set of characters and the way they are symbolized.
Generally, this convert () function is frequently implemented to accurately the data values stored in the server database having an erroneous character set.
This Oracle Convert() function can be implemented in some of the versions of Oracle such as Oracle 11g, Oracle 12c, Oracle 9i, Oracle 8i, and Oracle10g.
You should note that the Oracle Convert Function does not perform a conversion between the data types which might be thought by some of us. For the conversion of data type, we can choose other Oracle functions like TO_DATE, CAST, TO_NUMBER, and TO_CHAR.
Syntax:
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
CONVERT (string_expr,to_data_set {, from_data_set});
Let us explain the arguments of the convert() function accepting three arguments in Oracle as follows:
String_expr: It denotes the string value whose character set needs to be converted. It includes the data types such as CHAR, NCHAR, VARCHAR2, NVHARCHAR2, CLOB, and NCLOB.
To_data_set: It denotes the character set name to which the string_expr is transformed to.
From_data_set: It defines the character set name that is applied to store the string_expr value in the server database. This argument can be said as an optional one that has the default value as the character set of the database.
Return value: This Oracle convert() function results from a string value in the converted character set.
Few extra notes to be noted about this function are listed below:
The return data type for the type parameters CHAR and VARCHAR2 are VARCHAR2.
The return data type for the type parameters NCHAR and NVARCHAR2 is NVARCHAR2.
For CLOB data type the return type is CLOB.
For NCLOB data type the return type is NCLOB.
The to_data_set and from_data_set may be either literal string or any table column in the database.
The communal character set consists of:
US7ASCII – Character set of US 7-bit ASCII
WE8EBCDIC1047 – IBM West European EBCDIC Code page 1047
WE8ISO8859P1 – Character set of ISO 8859-1 West European 8-bit
JA16SJISTILDE – Japanese Shift-JIS Character Set, compatible with MS Code Page 932
EE8MSWIN1250 – Microsoft Windows East European Code Page 1250
WE8MSWIN1252 – Microsoft Windows West European Code Page 1252
AL32UTF8 – Unicode 5.0 Universal character set UTF-8 encoding form.
UTF8 – Unicode 3.0 Universal Character set CESU-8 encoding form
ZHT16MSWIN950 – Microsoft Windows Traditional Chinese Code page 950
F7DEC – character set of DEC French 7-bit
How convert function works in Oracle?
Apart from the utility functions in SQL, conversion functions are also contained by the Oracle inbuilt function library. There may exist different scenarios where the SQL query supposes input in a definite data type and it accepts the output in an altered data type. In such situations, Oracle indirectly attempts to convert the unpredicted value to a well-matched data type that can be replaced in place, and application steadiness is not negotiated. Here, the data type conversion process is applied either explicitly performed by the programmer or by the Oracle performed implicitly.
The implicit data type of conversion functions on the basis of a matrix that showcases Oracle’s maintenance for the inner typecasting. Moreover, these procedures, Oracle provides type conversion functions that may be implemented in the queries for open conversion and structuring. As a matter of information, it is therefore suggested to execute conversion as an alternative of trusting software intelligence. Although, implicit conversion functions well, but to remove the skew probabilities where corrupt inputs could be problematic to typecast within.
Oracle has recommended that the convert () function must not be implemented in the prevailing release of their database. This is due to the reason that the data type on the return of output is present in a character data type such as CHAR, VARCHAR, VARCHAR2, NCHAR, NVARCHAR2, also CLOB, and NCLOB. When the from_data_set is not fixed to either the national character set or the database character set is not maintained.
Any from_data_set which is not included in one of these two character sets is not supported. Thus, values that are available neither in the database nor the national character set must be processed and can be kept BLOB or RAW.
ExamplesLet us follow some illustrations as follows for this Oracle Convert() function:
1. Converting a string value from ANSI to UTF8 character sets as:
SELECT CONVERT ('GHJ', 'utf8', 'us7ascii') FROM dual;
Output:
2. Converting the character set of a string value from Latin-1 to ASCII as:
SELECT CONVERT('Ó Ø Ä Ê Í A B E C D', 'US7ASCII','WE8ISO8859P1') FROM DUAL;
Output:
Here, the above instance clarifies conversion using Oracle Convert() function to a character set specified present in WE8ISO8859P1 to the US7ASCII character set. This result illustrates similar to importing an identical string from a WE8ISO8859P1 database to a US7ASCII database.
3. Oracle Convert function can transform a content file character sets directly in SQL, for instance as:
SELECT Convert('®Ã B','WE8EBCDIC500','US7ASCII')FROM DUAL;
Basically, the convert function is implemented to transform textual data from one particular character set to another destined character set. Following is an example showing the convert function to alter an unprintable English string alphabetical characters to equivalent US character set as follows:
SELECT CONVERT('à à Õ Ê Ø A B E C D0','US7ASCII','WE8ISO8859P1') FROM DUAL;
Output:
Here, the rude type English alphabets are converted to US7ASCII character set from the previous set defined as WE8ISO8859P1 set which is a character set denoting an ISO 8859-1 West European 8-bit set.
Conclusion
We have discussed an Oracle conversion function i.e. CONVERT(), which accepts string value in one character set and outputs the value in another specific character set.
Recommended ArticlesThis is a guide to Oracle CONVERT. Here we discuss the definition, syntax, parameters, and How the convert function works in Oracle? respectively. You may also have a look at the following articles to learn more –
You're reading How Convert Function Works In Oracle?
Update the detailed information about How Convert Function Works In Oracle? on the Dacquyenphaidep.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!