Home > Database > Oracle > body text

How to use convert function in oracle

下次还敢
Release: 2024-05-02 23:18:18
Original
532 people have browsed it

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>
Copy after login

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>
Copy after login
Convert number to string:

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

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

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

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!