1

クエリの解決策を探していましたが、一日中費やして答えを見つけることができませんでした。クエリを正常にテストしたところ、うまくいきましたが、コードをストアドプロシージャの構造に入れると、解決策を作成する エラー コード 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
4

1 に答える 1

2

VARCHAR(MAX) は無効です。VARCHAR(255) を試してください。

于 2013-05-17T15:26:55.273 に答える