Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

mysql - Why do I receive Null from this stored procedure?

I created a stored procedure with the output parameter @name. But when I call it, I receive Null. How do I correctly call the procedure or is there an error in the procedure?

CREATE PROCEDURE GetName(IN kartennummer CHAR(16), OUT name VARCHAR(91))
BEGIN
SELECT @name = (SELECT CONCAT_WS(' ', Vorname, Nachname) FROM Kunden kund JOIN Konten kont WHERE kund.KundenID = kont.KundenID AND kont.Kartennummer = kartennummer);
END;

I call the procedure like this:

CALL GetNAME("7717015800401117", @name);

Why do I receive Null and not the name? The Select statement alone works.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
DELIMITER $$
CREATE PROCEDURE GetName(IN kartennummer CHAR(16), OUT name VARCHAR(91))
BEGIN
    SELECT 
        CONCAT_WS(' ', Vorname, Nachname)
        INTO 
        name
    FROM
        Kunden kund
            JOIN
        Konten kont
    WHERE
        kund.KundenID = kont.KundenID
            AND kont.Kartennummer = kartennummer;
END;
DELIMITER ;

This will only work , if the result if the select query ihas onl1 name, but assume that is the case for you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...