2013-05-17 35 views
1

我一直在尋找我的查詢解決方案,我花了整整一天,我找不到答案,我測試了我的查詢正常,它的工作,但當我將代碼放入存儲過程的結構來創建解決方案時,我總是收到錯誤代碼1064.問題在mysql中創建一個過程引發錯誤1064

這是我一直試圖創建的存儲過程,有人可以幫助我。

DELIMITER $$ 

CREATE 
    PROCEDURE `ocomon_rc6`.`spGetChamadoMaisAntigo`(IN Sistema VARCHAR(MAX), IN CodigoUrl INT) 
    BEGIN 

    DROP TABLE IF EXISTS ocomon_rc6.TempChamados; 

    CREATE TABLE IF NOT EXISTS ocomon_rc6.TempChamados(numero INT, dias_apos_abertura INT); 

    INSERT INTO TempChamados(numero, dias_apos_abertura) 
    SELECT 
     o.numero, 
     (CASE 
      WHEN CONVERT(NOW(), TIME) > CONVERT(o.data_abertura, TIME) THEN DATEDIFF(NOW(), o.data_abertura) 
      ELSE DATEDIFF(DATE_SUB(NOW(),INTERVAL 1 DAY), o.data_abertura) 
     END CASE) 
    FROM 
     ocorrencias as o 
    LEFT JOIN 
     sistemas AS a ON 
      a.sis_id = o.sistema 
    LEFT JOIN 
     sistemas_x_url AS su ON 
      a.sis_id = su.sis_id 
    LEFT JOIN 
     urls ON 
      su.codigoUrl = urls.codigoUrl 
    LEFT JOIN 
     localizacao AS l ON 
      l.loc_id = o.local 
    LEFT JOIN 
     instituicao AS i ON 
      i.inst_cod = o.instituicao 
    LEFT JOIN 
     usuarios AS u ON 
      u.user_id = o.operador 
    LEFT JOIN 
     usuarios AS ua ON 
      ua.user_id = o.aberto_por 
    LEFT JOIN 
     `status` AS s ON 
      s.stat_id = o.status 
    LEFT JOIN 
     status_categ AS stc ON 
      stc.stc_cod = s.stat_cat 
    LEFT JOIN 
     problemas AS p ON 
      p.prob_id = o.problema 
    LEFT JOIN 
     sla_solucao AS sls ON 
      sls.slas_cod = p.prob_sla 
    LEFT JOIN 
     prioridades AS pr ON 
      pr.prior_cod = l.loc_prior 
    LEFT JOIN 
     sla_solucao AS slr ON 
      slr.slas_cod = pr.prior_sla 
    LEFT JOIN 
     script_solution AS sol ON 
      sol.script_cod = o.oco_script_sol 
    LEFT JOIN 
     prior_atend AS prioridade_atendimento ON 
      prioridade_atendimento.pr_cod = o.oco_prior 
    LEFT JOIN 
     sistemas_x_filtro AS filtr ON 
      filtr.codigoSistemaFiltro = o.filtro 
    WHERE 
     s.stat_painel IN (2) 
    AND o.sistema IN (@Sistema) 
    AND su.codigoUrl = @CodigoUrl 
    AND o.oco_scheduled = 0 
    ORDER BY 
     o.data_abertura; 

    SELECT * FROM TempChamados WHERE dias_apos_abertura = (SELECT MAX(dias_apos_abertura) FROM TempChamados); 

    DROP TABLE IF EXISTS ocomon_rc6.TempChamados; 

    END$$ 

DELIMITER ; 

這是錯誤的訊息,我收到

Error Code : 1064 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@Sistema VARCHAR(MAX), @CodigoUrl INT) 
    BEGIN 

    DROP TABLE IF EXISTS ocomon_' at line 2 

Execution Time : 00:00:00:000 
Transfer Time : 00:00:00:000 
Total Time  : 00:00:00:000 

回答

2

VARCHAR(MAX)是無效的。嘗試VARCHAR(255)。

+0

感謝所有幫助我在這裏,它的工作,非常感謝,問題是在parameterName中使用@和使用VARCHAR(MAX),而不是使用VARCHAR(255)。 –