第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

MySQL CAST() 函數(shù)

標(biāo)簽:
MySQL

Summary: in this tutorial, we will show you how to use MySQL CAST function to convert a value of any type into a value with a specified type.

Introduction to MySQL CAST function

The syntax of the MySQL CAST() function is as follows:

CAST(expression AS TYPE)

The CAST() function converts a value of any type into a value that has a specified type. The target type can be any one of the following types: BINARYCHARDATEDATETIMETIME,DECIMALSIGNEDUNSIGNED.

The CAST() function is often used to return a value with a specified type for comparison in the WHEREJOIN, and HAVING clauses.

Let’s take a look at some examples of using the CAST() function.

MySQL CAST function examples

In the following example, MySQL converts a string into an integer implicitly before doing calculation:

SELECT (1 + '1')/2;

To explicitly convert a string into an integer, you use the CAST() function as the following statement:

SELECT (1 + CAST('1' AS UNSIGNED))/2;

MySQL CAST  convert string into integer

The following statement explicitly convert an integer into a string and concatenate the string with another string:

SELECT CONCAT('MySQL CAST example #',CAST(2 AS CHAR));

MySQL CAST convert integer into string

Let’s take a look at the orders table in the sample database.

Orders Table

See the following query:

SELECT orderNumber,        requiredDate FROM orders WHERE requiredDate BETWEEN '2003-01-01' AND '2003-01-31';

The query selects orders whose required dates are in January 2003. The data type of the requireDate column is DATE therefore MySQL has to convert the literal strings: '2003-01-01' and '2003-01-31' into TIMESTAMP values before evaluating WHERE condition.

However, to be safe, you can use CAST() function to explicitly convert a string into a TIMESTAMP value as follows:

SELECT orderNumber,        requiredDate FROM orders WHERE requiredDate BETWEEN  CAST('2003-01-01' AS DATETIME)                         AND CAST('2003-01-31' AS DATETIME);

MySQL CAST convert string into date

The following statement converts DOUBLE values into CHAR values and uses the results as the arguments of the 

MySQL CAST convert double into string

In this tutorial, you have learned how to use the MySQL CAST() function to convert a value with any type into a value with a specified type.

原文链接:http://outofmemory.cn/mysql/function/mysql-cast

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消