程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> 錯誤代碼:1582 Incorrect parameter count in the call to native function 'str_to_date'

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

編輯:DB2教程

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


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 ...

錯誤代碼: 1582
Incorrect 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 amount
FROM
  t_stu_info t 
WHERE 1 = 1 
  AND DATE_FORMAT(t.statisDate, '%Y') = '2015' 
UNION
ALL 
SELECT 
  t.`name`,
  DATE_FORMAT(STR_TO_DATE('2014'), '%Y') AS statisDate,
  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amount
FROM
  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 amount
FROM
  t_stu_info t 
WHERE 1 = 1 
  AND DATE_FORMAT(t.statisDate, '%Y') = '2015' 
UNION
ALL 
SELECT 
  t.`name`,
  DATE_FORMAT(STR_TO_DATE('2014','%Y'), '%Y') AS statisDate,
  ROUND(IFNULL(SUM(t.`amount`), 0), 3) AS amount
FROM
  t_stu_info t 
WHERE 1 = 1 
  AND DATE_FORMAT(t.statisDate, '%Y') = '2014'

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved