Неизвестный столбец в 'предложении where' с хранимой процедурой через mysql - PullRequest
0 голосов
/ 02 января 2019

Я использую хранимую процедуру с подготовленным описанием для поиска строк из строки.

Это выглядит так

CREATE DEFINER=`y0y0`@`%` PROCEDURE `SP_GEN_CASH_SOD_TXT_FILE`(IN oRETURNNO varchar(20))
BEGIN
    SET @returnNo = oRETURNNO;
    SET @sitePath = (select site_path from sap_transfer_data WHERE payer_payment_type = 'C' and trans_status ='I' and return_no = @returnNo LIMIT 1);
    SET @outputPath = CONCAT("/cash/","SAP_",@sitePath,"_SP_",@returnNo,"_", date_format(CURDATE(), '%Y%m%d'),".txt");

    SET @row_number = 0;
    SET @sqlCommand = CONCAT('SELECT "IsCashYesOrNo^Transaction type^Line No.^SAP Sales Organization^Date of Receive^HIS Unique ID^Paycode code (Internal)^Lab Number^Test Item Code^Test Item Description^Sequence^Customer Material No.^Lab site code^Sent Test^Lab Department Code^Lab Department Name^Hospital Number^Address2^IN/OUT^Priority^Auto Add TC^Patient first name^Patient last name^Patient address^Hospital Department^Hospital Location code^Hospital Location description^Quantity^UOM^Ref. No.^Date of Enter^Pathologist Code 1^Pathologist Level 1^Pathologist Code 2^Pathologist Level 2^Pathologist Code 3^Pathologist Level 3^Pathologist Code 4^Pathologist Level 4^Pathologist Code 5^Pathologist Level 5^Pathologist Code 6^Pathologist Level 6^Pathologist Code 7^Pathologist Level 7^Pathologist Code 8^Pathologist Level 8" as texts from dual
    UNION ALL
    SELECT CONCAT("Yes", "^", trans_status, "^", CAST((@row_number:=@row_number + 1) as char), "^", "0105", "^", return_date, "^", return_no, "|",  item_code, "|", "1", "^", payer_ship_to, "^", return_no, "^", item_code, "^",
    "^", "1", "^", "^", lab_site_code, "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", cust_code, "^", cust_name, "^", return_qty, "^", "^", ref_req_no, "^",  
    "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^", "^") as texts 
    INTO OUTFILE ', char(39), @outputPath, char(39),
    ' LINES TERMINATED BY ', char(39),'\r\n', char(39),
    ' FROM sap_transfer_data
    WHERE payer_payment_type = "C" and trans_status = "I" and return_no = ', @returnNo);

    prepare s1 from @sqlCommand;
    execute s1; deallocate prepare s1;

    update sap_transfer_data set delivery_date = CURDATE(), trans_fag = true where return_no = @returnNo;
END

Затем я вызываю процедуру, используя:

call SP_GEN_CASH_SOD_TXT_FILE ('RT20190101039354');

Но я получаю эту ошибку:

Error Code: 1054. Unknown column 'RT20190101039354' in 'where clause'

Любые идеи у вас есть предложения мне?

Спасибо заранее.^ _ ^

1 Ответ

0 голосов
/ 02 января 2019

SET @sqlCommand = CONCAT ('... ... ГДЕ payer_payment_type = "C" и trans_status = "I" и return_no = ', @returnNo);

Для @returnNo = 'RT20190101039354', что делает конец @sqlCommand похожим на

WHERE payer_payment_type = "C" and trans_status = "I" and return_no = RT20190101039354

и, следовательно, движок предполагает, что это имя столбца.

Вы хотите а) использовать двойные кавычки вокруг строковых литералов и использовать только одинарные кавычки, а б), в частности, изменить свой код на:

SET @sqlCommand = CONCAT('...
...
WHERE payer_payment_type = ''C'' and trans_status = ''I'' and return_no = ?');

execute s1 USING @returnNo; deallocate prepare s1;

Знак вопроса является заполнителем и заполняется нужным значением с помощью предложения USING для EXECUTE.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...