2016-07-24 12 views
0

MariaDB 10 auf WindowsFehler Verfahren

gespeichert erstellen, wenn die folgende gespeicherte Prozedur in MySQL Workbench erstellen, erhalte ich Fehler 1064. Der Fehler in der letzten Zeile „LIMIT 1“ gekennzeichnet ist. Der Versuch, es in HeidiSQL zu erstellen, gibt ebenfalls den Fehler 1064 zurück. Dies deutet auf fehlende Klammern hin, aber keine fehlen.

Jede Hilfe dankbar:

CREATE PROCEDURE `available_room` (in p_client_id int(11), in p_room_id int(11), in dateQF date, in a_gender varchar(3)) 
BEGIN 
SELECT 
    room_name, 
    room_type_name, 
    counted, 
    num_guests, 
    minimum, 
    room_id AS room_id_selected 
FROM (SELECT * FROM room 
WHERE room_id=p_room_id AND 
(NOT EXISTS (
SELECT * FROM invoice 
WHERE client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    commit_invoice=1 AND 
    room_id = product_id AND 
    gender != a_gender 
    ) OR 
(NOT EXISTS (
SELECT * FROM invoice 
WHERE client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    commit_invoice=1 AND 
    room_id = product_id 
    ))))A 
LEFT JOIN room_type_content ON 
    room_type_content.room_type_id=A.room_type AND 
    language_id='en' 
LEFT JOIN(SELECT product_id, count(product_id)AS counted, MIN(NULLIF(quantity,0))AS minimum FROM invoice 
WHERE gender =a_gender AND 
    client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    (commit_invoice=1 OR commit_invoice=3) AND 
    invoice_set !='SYSTEM' 
GROUP BY product_id)B 
ON  B.product_id=p_room_id 
ORDER BY counted DESC 
LIMIT 1 
END 

Antwort

0

Sie haben vergessen, ein Semikolon nach LIMIT 1.

Sie müssen auch das Standardtrennzeichen vor und nach dem Erstellen der Prozedur ändern.

Dokumentation: CREATE PROCEDURE and CREATE FUNCTION Syntax

Feste Ausführung des Codes:

DELIMITER $$ 
CREATE PROCEDURE `available_room` (in p_client_id int(11), in p_room_id int(11), in dateQF date, in a_gender varchar(3)) 
BEGIN 
SELECT 
    room_name, 
    room_type_name, 
    counted, 
    num_guests, 
    minimum, 
    room_id AS room_id_selected 
FROM (SELECT * FROM room 
WHERE room_id=p_room_id AND 
(NOT EXISTS (
SELECT * FROM invoice 
WHERE client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    commit_invoice=1 AND 
    room_id = product_id AND 
    gender != a_gender 
    ) OR 
(NOT EXISTS (
SELECT * FROM invoice 
WHERE client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    commit_invoice=1 AND 
    room_id = product_id 
    ))))A 
LEFT JOIN room_type_content ON 
    room_type_content.room_type_id=A.room_type AND 
    language_id='en' 
LEFT JOIN(SELECT product_id, count(product_id)AS counted, MIN(NULLIF(quantity,0))AS minimum FROM invoice 
WHERE gender =a_gender AND 
    client_id=p_client_id AND 
    product_type = 'LODGING' AND 
    dateQF BETWEEN date1 AND DATE(DATE_ADD(date2, INTERVAL -1 DAY)) AND 
    (commit_invoice=1 OR commit_invoice=3) AND 
    invoice_set !='SYSTEM' 
GROUP BY product_id)B 
ON  B.product_id=p_room_id 
ORDER BY counted DESC 
LIMIT 1; 
END $$ 
DELIMITER ; 
+0

Nein, das es nicht ist. Semikolon macht keinen Unterschied. – user34682

+0

Es tut. Ich habe Ihren Code mit dem hinzugefügten Semikolon ausgeführt und es erstellt die Prozedur ohne Fehler. – Jocelyn