0

Window-7 で MySQL にストアド プロシージャを作成しました。Windowsで正常に実行されます。しかし、Ubuntu に切り替えると、ストアド プロシージャでエラーが発生します。Windows では、ストアド プロシージャの作成に SQLyog を使用しています。Ubuntu では、SQL スクリプトを実行してそのストアド プロシージャを呼び出しますが、エラーが発生します。以下は私のストアドプロシージャです。

DELIMITER $$

USE `adserver`$$

DROP PROCEDURE IF EXISTS `getDaypartTimeDetail`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `getDaypartTimeDetail`
(currentDate DATE,noOfdays INT,cityId BIGINT)
BEGIN

DECLARE i INT;
DECLARE dateCnt INT;
SET dateCnt = 0;

DROP TEMPORARY TABLE IF EXISTS OnlyDate;
DROP TEMPORARY TABLE IF EXISTS AdvScheduleData;
CREATE TEMPORARY TABLE OnlyDate(dday DATE); 
CREATE TEMPORARY TABLE AdvScheduleData(dday BIGINT,daypartId INT,totalFile BIGINT,totalDur BIGINT); 

/* Generate Dates */
WHILE(dateCnt < noOfdays) DO
    SET i = 1;
    INSERT INTO OnlyDate(dday) VALUES (DATE_ADD(currentDate, INTERVAL dateCnt DAY));
SET dateCnt = dateCnt + 1;
END WHILE;

/* Insert all dayparts for all dates */ 
INSERT INTO AdvScheduleData (dday, daypartID) SELECT (UNIX_TIMESTAMP(dday)*1000), id FROM OnlyDate, daypart;
/* Update total files and duration */       
UPDATE AdvScheduleData SET 
    TotalFile =    (SELECT COUNT(advt_id) 
            FROM adv_schedule AdvSch
            INNER JOIN advertisement Adv ON Adv.id = AdvSch.advt_id
              WHERE AdvScheduleData.dday BETWEEN AdvSch.start_date AND AdvSch.end_date
              AND AdvSch.status = 2
              AND AdvSch.active = 1
              AND AdvSch.id IN (SELECT schedule_id FROM schedule_daypart 
               WHERE daypart_id = AdvScheduleData.daypartId )
              AND AdvSch.id IN (SELECT schedule_id FROM schedule_cities WHERE city_id = cityId)
              AND Adv.is_active = 1 
              AND Adv.is_deleted = 0
              AND Adv.status = 2 
              AND Adv.expiry_date >= AdvScheduleData.dday),
    totalDur =    (SELECT SUM(Adv.duration)
            FROM adv_schedule AdvSch
            INNER JOIN advertisement Adv ON Adv.id = ADVSCH.advt_id
              WHERE AdvScheduleData.dday BETWEEN AdvSch.start_date AND AdvSch.end_date
              AND AdvSch.status = 2
              AND AdvSch.active = 1
              AND AdvSch.id IN (SELECT schedule_id FROM schedule_daypart 
               WHERE daypart_id = AdvScheduleData.daypartId )
              AND AdvSch.id IN (SELECT schedule_id FROM schedule_cities WHERE city_id = cityId)
              AND Adv.is_active = 1 
              AND Adv.is_deleted = 0
              AND Adv.status = 2 
              AND Adv.expiry_date >= AdvScheduleData.dday);
SELECT * FROM AdvScheduleData;
END$$

DELIMITER ;

Ubuntuで得られる出力は

mysql> call getDaypartTimeDetail('2012-08-13',5,30534); エラー 1054 (42S22): 'on 句' の不明な列 'ADVSCH.advt_id'

4

1 に答える 1

1

Ubuntu では、テーブル名とエイリアスは大文字と小文字が区別されます。

したがって、この参照はエラーを出しています:

totalDur =    (SELECT SUM(Adv.duration)
        FROM adv_schedule AdvSch
        INNER JOIN advertisement Adv ON Adv.id = ADVSCH.advt_id

に変更しますAdvSch.advt_id

于 2012-08-13T06:02:38.130 に答える