sqlÖÐ×Ö·û´®Êý×ÖÔõô¼Ó¼õ
sqlÖÐ×Ö·û´®Êý×Ö²»¿ÉÖ±½Ó¼Ó¼õ¡£¿ÉʹÓÃÒÔÏ°취ʵÏÖ£ºÊ¹ÓÃcast()½«×Ö·û´®Êý×Öת»»³ÉÊý×ÖÀàÐÍ£»¾ÙÐмӼõÔËË㣻¿É½«Ð§¹ûת»»»Ø×Ö·û´®ÀàÐÍ£¨¿ÉÑ¡£©¡£
SQL ÖÐ×Ö·û´®Êý×ֵļӼõ
ÔÚ SQL ÖУ¬×Ö·û´®ºÍÊý×Ö²»¿ÉÖ±½ÓÏà¼Ó»òÏà¼õ¡£ÒÔÏÂÊÇÔõÑùʹÓà SQL ½«×Ö·û´®Êý×Öת»»³ÉÊý×Ö²¢¾ÙÐмӼõ£º
µÚÒ»²½£ºÀàÐÍת»»
ʹÓà CAST() º¯Êý½«×Ö·û´®Êý×Öת»»³ÉÕûÊý»ò¸¡µãÊýÀàÐÍ¡£ÀýÈ磺
CAST('10' AS INTEGER) -- ½«×Ö·û´® "10" ת»»ÎªÕûÊý 10 CAST('12.5' AS REAL) -- ½«×Ö·û´® "12.5" ת»»Îª¸¡µãÊý 12.5
µÇ¼ºó¸´ÖÆ
µÚ¶þ²½£º¼Ó¼õÔËËã
½«×ª»»ºóµÄÊý×Ö¾ÙÐмӼõÔËËã¡£ÀýÈ磺
SELECT CAST('10' AS INTEGER) + CAST('5' AS INTEGER); -- Êä³ö£º15 SELECT CAST('12.5' AS REAL) - CAST('5.5' AS REAL); -- Êä³ö£º7.0
µÇ¼ºó¸´ÖÆ
µÚÈý²½£ºÐ§¹ûÀàÐÍת»»£¨¿ÉÑ¡£©
ÈôÊÇÐèÒª£¬¿ÉÒÔ½«ÔËËãЧ¹ûת»»»Ø×Ö·û´®ÀàÐÍ¡£ÀýÈ磺
CAST(CAST('10' AS INTEGER) + CAST('5' AS INTEGER) AS TEXT); -- Êä³ö£º'15' CAST(CAST('12.5' AS REAL) - CAST('5.5' AS REAL) AS VARCHAR(5)); -- Êä³ö£º'7.000'
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º
×Ö·û´®±ØÐè°üÀ¨ÓÐÓõÄÊý×Ö£¬²»È»×ª»»»áʧ°Ü¡£
ת»»µÄЧ¹ûÀàÐÍÈ¡¾öÓÚÔʼ×Ö·û´®µÄÃûÌá£
ÔÚ¾ÙÐмӼõÔËËã֮ǰ£¬È·±£×Ö·û´®Êý×ÖÒÑ׼ȷת»»³ÉÊý×ÖÀàÐÍ¡£
ÒÔÉϾÍÊÇsqlÖÐ×Ö·û´®Êý×ÖÔõô¼Ó¼õµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡