본문 바로가기
MySql

MySQL mysql 저장 프로 시저 오류 (1172, '결과가 둘 이상의 행으로 구성됨')

by 베이스 공부 2020. 12. 19.
반응형

django에서 다음 저장 프로 시저를 실행하려고하면 OperationError (1172, '결과가 둘 이상의 행으로 구성됨')가 표시됩니다. 내가 뭘 잘못하고 있는지 알 수 있습니까?

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `UpdatePrices`(IN storeId int, IN bottleSize VARCHAR(50))
BEGIN
    DECLARE amount DECIMAL(10,2); DECLARE isCustom INT DEFAULT 0;
    DECLARE changeType VARCHAR(50) DEFAULT 'State'; DECLARE updateType INT DEFAULT 0;

        IF bottleSize = '1000 Ml' THEN
            SELECT S1000IncreaseChoices INTO changeType FROM store_store WHERE StoreID = storeId;

            IF changeType = 'State' THEN
                SELECT updateType = 0;
            END IF;

            IF changeType = 'Flat' THEN
                SELECT S1000IncreaseAmount INTO amount FROM store_store WHERE StoreID = storeId;
                SELECT updateType = 1;
            END IF;


            IF changeType = 'Percent' THEN
                SELECT 1 - S1000IncreaseAmount/100 INTO amount FROM store_store WHERE StoreID = storeId;
                SELECT updateType = 2;
            END IF;
        END IF;

        IF updateType = 0 THEN
            update store_storeliquor SL 
            inner join liquor_liquor LL
            on liquorID_id = id
            set StorePrice = ShelfPrice
            where BottleSize = bottleSize
            and storeID_id = storeId
            and custom = 0;
        END IF;

        IF updateType = 1 THEN
            update store_storeliquor SL 
            inner join liquor_liquor LL
            on liquorID_id = id
            set StorePrice = OffPremisePrice + amount
            where BottleSize = bottleSize
            and storeID_id = storeId
            and custom = 0;
        END IF;

        IF updateType = 1 THEN
            update store_storeliquor SL 
            inner join liquor_liquor LL
            on liquorID_id = id
            set StorePrice = OffPremisePrice / amount
            where BottleSize = bottleSize
            and storeID_id = storeId
            and custom = 0;
        END IF;



END

중요한지 잘 모르겠지만 다음과 같이 저장 프로 시저를 시작합니다.

def priceupdate(request, store_id):

    cursor = connection.cursor()
    cursor.callproc("UpdatePrices", (store_id, '1000 ML'))
    cursor.close()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

 

해결 방법

 

SELECT ... INTO 쿼리는 둘 이상의 레코드가있는 결과 집합을 제공합니다. WHERE 필터가 잘못되었습니다. 두 개의 동일한 값 StoreID = storeId 를 비교합니다. IN storeId int parementer의 이름을 다른 이름으로 바꿉니다. 예 : IN storeId_param int

쿼리는 다음과 같습니다.

SELECT S1000IncreaseChoices INTO changeType FROM store_store WHERE StoreID = storeId_param;

 

참조 페이지 https://stackoverflow.com/questions/19830053

 

 

반응형

댓글