Home  >  Article  >  Database  >  How to use convert function in oracle

How to use convert function in oracle

下次还敢
下次还敢Original
2024-05-02 23:18:18536browse

The CONVERT function converts a value in Oracle from one data type to another, and its syntax is CONVERT(, ). It can be used to convert string to number, number to string, date to string, string to date, binary to string and string to binary.

How to use convert function in oracle

Usage of CONVERT function in Oracle

The CONVERT function is used in Oracle to convert data types. It converts a value from one data type to another.

Syntax

<code>CONVERT(<结果数据类型>, <输入值>)</code>

Parameters

  • ##: The data type to convert to.
  • : The value to be converted.

Usage

The CONVERT function can be used to convert various data types, including:

    String to number
  • Number to string
  • Date to string
  • String to date
  • Binary to string
  • String to binary

Example

Convert string to number:

<code>SELECT CONVERT(NUMBER, '123.45') FROM DUAL;</code>
Convert number to string:

<code>SELECT CONVERT(VARCHAR2(20), 12345) FROM DUAL;</code>
Convert date For string:

<code>SELECT CONVERT(CHAR(10), SYSDATE, 'YYYY-MM-DD') FROM DUAL;</code>
Convert string to date:

<code>SELECT CONVERT(DATE, '2023-03-08', 'YYYY-MM-DD') FROM DUAL;</code>
Convert binary to string:

<code>SELECT CONVERT(VARCHAR2(100), DUMP(NULL, 16)) FROM DUAL;</code>
Convert string to binary:

<code>SELECT CONVERT(BLOB, 'This is a string.') FROM DUAL;</code>

Notes

  • Data type restrictions: Both the value to be converted and the target data type must be supported by Oracle.
  • Format string: When converting dates or strings, a format string can be specified to control the output format.
  • Default format: If you do not specify a format string, Oracle's default format will be used.

The above is the detailed content of How to use convert function in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn