錯誤碼: 1582 Incorrect parameter count in the call to native function 'str_to_date',parameter

來源:互聯網
上載者:User

錯誤碼: 1582 Incorrect parameter count in the call to native function 'str_to_date',parameter
1. 錯誤描述

1 queries executed, 0 success, 1 errors, 0 warnings查詢:SELECT t.`name`, DATE_FORMAT(str_to_date('2015'), '%Y') as statisDate, ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS ...錯誤碼: 1582Incorrect parameter count in the call to native function 'str_to_date'執行耗時   : 0 sec傳送時間   : 0 sec總耗時      : 0 sec
2. 錯誤原因
SELECT   t.`name`,  DATE_FORMAT(STR_TO_DATE('2015'), '%Y') AS statisDate,  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amountFROM  t_stu_info t WHERE 1 = 1   AND DATE_FORMAT(t.statisDate, '%Y') = '2015' UNIONALL SELECT   t.`name`,  DATE_FORMAT(STR_TO_DATE('2014'), '%Y') AS statisDate,  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amountFROM  t_stu_info t WHERE 1 = 1   AND DATE_FORMAT(t.statisDate, '%Y') = '2014'

MySQL內建函數str_to_date的格式是:str_to_date(字串,日期格式);
在這個查詢SQL中卻是str_to_date(字串),導致報錯

3. 解決辦法

修改查詢SQL語句

SELECT   t.`name`,  DATE_FORMAT(STR_TO_DATE('2015','%Y'), '%Y') AS statisDate,  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amountFROM  t_stu_info t WHERE 1 = 1   AND DATE_FORMAT(t.statisDate, '%Y') = '2015' UNIONALL SELECT   t.`name`,  DATE_FORMAT(STR_TO_DATE('2014','%Y'), '%Y') AS statisDate,  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amountFROM  t_stu_info t WHERE 1 = 1   AND DATE_FORMAT(t.statisDate, '%Y') = '2014'

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

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.