Oracle Cast usage

Source: Internet
Author: User

The Cast usage of Oracle is often seen in the SQL of the predecessors, for example: www.2cto.com with t as (select level | ''l from dual connect by level <= 5), A (A, V) AS (select cast (l as varchar (30), 1 from tunion allselect a | L, V + 1 from a, t where instr (A, L) = 0 and v <5) SELECT * from a; for example, the with recursive statement above, but the CAST is used less often. Today, we will give ourselves A blind sweep, the description of CAST in the Oracle official document is as follows: CASTCAST converts values from one data type to another. return ValueThe data type specified Type_name.SyntaxCAST (expr AS type_name) Argumentsexpr can be an expression in one of the data types. type_name is one of the data types listed in Table1-2, "dimen1_data Types ". table 3-1 shows which data types can be cast into which other built-in data types. NUMBER between des NUMBER, DECIMAL, and INTEGER. DATETIME between des DATE, TIMESTAMP, timestamp with timezone, and TIMESTAMP WITH LOCAL TIMEZONE. INTERVAL between des interval day to second and interval year to month. table 3-1 Compatible Data TypesFrom To BINARY_FLOAT, BINARY_DOUBLE To CHAR, VARCHAR2 To NUMBER To DATETIME, INTERVAL To NCHAR, clerk, intervalnoyesnoyesnchar, comment ExampleCAST ('2017. 4567 'as NUMBER () retu Rns the value 123. 46. As described above, we can see that CAST can convert one type to another. For example, convert the string type to the NUMBER () type, not just the to_number, to_char (), and to_date () types, the preceding Table 3-1 indicates whether CAST can be used for mutual conversion of this type. Example call: ChenZw> select cast ('192. 100' as number (123) as num from dual;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.