国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
在MySQL中如何進(jìn)行數(shù)據(jù)類型的轉(zhuǎn)換? - 其他數(shù)據(jù)庫開發(fā) / MySQL/Postgre...
在MySQL中如何進(jìn)行數(shù)據(jù)類型的轉(zhuǎn)換?如:從float到int類型轉(zhuǎn)換?在日期類型變量后加上一個(gè)int類型能否還得到日期類型?
#1樓 得分:0回復(fù)于:2006-06-15 09:38:31
MySQL的類型轉(zhuǎn)換函數(shù)如下:
CAST(expr   AS   type),   CONVERT(expr,type),   CONVERT(expr   USING   transcoding_name)  

The   CAST()   and   CONVERT()   functions   take   a   value   of   one   type   and   produce   a   value   of   another   type.  

The   type   can   be   one   of   the   following   values:  

BINARY[(N)]  

CHAR[(N)]  

DATE  

DATETIME  

DECIMAL  

SIGNED   [INTEGER]  

TIME  

UNSIGNED   [INTEGER]  


mysql>   select   cast(now()   as   char);
+---------------------+
|   cast(now()   as   char)   |
+---------------------+
|   2006-06-15   09:31:20   |
+---------------------+


mysql>   select   convert( '中文 '   using   gb2312);
+------------------------------+
|   convert( '中文 '   using   gb2312)   |
+------------------------------+
|   中文                                                   |
+------------------------------+
1   row   in   set   (0.06   sec)

使用日期函數(shù)date_add,date_sub就可以了,見下例:
mysql>   select   date_add(now(),interval   1   day);
+--------------------------------+
|   date_add(now(),interval   1   day)   |
+--------------------------------+
|   2006-06-16   09:36:06                         |
+--------------------------------+
1   row   in   set   (0.02   sec)

mysql>   select   date_add(now(),   interval   1   month);
+-----------------------------------+
|   date_add(now(),   interval   1   month)   |
+-----------------------------------+
|   2006-07-15   09:36:38                               |
+-----------------------------------+
1   row   in   set   (0.00   sec)

mysql>   select   date_add(now(),   interval   1   minute);
+------------------------------------+
|   date_add(now(),   interval   1   minute)   |
+------------------------------------+
|   2006-06-15   09:38:03                                 |
+------------------------------------+
1   row   in   set   (0.00   sec)

1   row   in   set   (0.05   sec)
  • klan
  • (因帥被判7年)
  • 等 級(jí):
#2樓 得分:0回復(fù)于:2006-06-15 15:07:40
CONVERT()   provides   a   way   to   convert   data   between   different   character   sets.   The   syntax   is:  

CONVERT(expr   USING   transcoding_name)

In   MySQL,   transcoding   names   are   the   same   as   the   corresponding   character   set   names.  

Examples:  

SELECT   CONVERT(_latin1 'Müller '   USING   utf8);
INSERT   INTO   utf8table   (utf8column)
        SELECT   CONVERT(latin1field   USING   utf8)   FROM   latin1table;

CONVERT(...   USING   ...)   is   implemented   according   to   the   standard   SQL   specification.  

You   may   also   use   CAST()   to   convert   a   string   to   a   different   character   set.   The   syntax   is:  

CAST(character_string   AS   character_data_type   CHARACTER   SET   charset_name)

Example:  

SELECT   CAST(_latin1 'test '   AS   CHAR   CHARACTER   SET   utf8);

If   you   use   CAST()   without   specifying   CHARACTER   SET,   the   resulting   character   set   and   collation   are   defined   by   the   character_set_connection   and   collation_connection   system   variables.   If   you   use   CAST()   with   CHARACTER   SET   X,   the   resulting   character   set   and   collation   are   X   and   the   default   collation   of   X.  

You   may   not   use   a   COLLATE   clause   inside   a   CAST(),   but   you   may   use   it   outside.   That   is,   CAST(...   COLLATE   ...)   is   illegal,   but   CAST(...)   COLLATE   ...   is   legal.  

Example:  

SELECT   CAST(_latin1 'test '   AS   CHAR   CHARACTER   SET   utf8)   COLLATE   utf8_bin;

#3樓 得分:0回復(fù)于:2006-06-16 10:41:31
謝謝大家的回復(fù),另我又找到一個(gè)函數(shù)truncate(float,int)可以把float類型轉(zhuǎn)換到int類型,具體語法自己看。
  • eqxu
  • (天使聯(lián)盟)
  • 等 級(jí):
#4樓 得分:0回復(fù)于:2006-06-16 17:22:56



多謝


經(jīng)典貼
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
base64解碼
mysql的utf8設(shè)置
【140319-02】mysql配置修改集錦
如何修改某一個(gè)表的字符集(轉(zhuǎn))
MySQL字符集中文亂碼終極解決方案和mysql查詢中文問題解決方法[轉(zhuǎn)貼]
mysql導(dǎo)入導(dǎo)出數(shù)據(jù)中文亂碼解決方法小結(jié)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服