Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Select query output in mysql and differes between SP and query execution

Why is my query output different between SP and query execution. I am executing a simple select query to assign some value..

SP:

CREATE DEFINER=`root`@`localhost` PROCEDURE `INS_EXPENSES`(
IN CATNAME varchar(100),
IN SUBCATNAME varchar(100),
IN AMOUNT INT,
IN USERID INT,
IN DESCRIPTIONS varchar(100)
)
BEGIN

SELECT SUBCATNAME;

SELECT * FROM SUBCAT WHERE SUBCATNAME='MISC';

END

THE ABOVE SELECT QUERY RETURNS ALL DATA FROM THE SUBCAT TABLE. WHERE IN SAME QUERY WORKS FINE IF EXECUTED OTHERWISE.

enter image description here


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

1 Answer

0 votes
by (71.8m points)

Your procedure has parameter SUBCATNAME and the WHERE-clause is using that value instead of the column with same name when it compares with the "MISC"-string.

You should use a prefix for the procedure parameters so that they would not get mixed up with column names (use parameter names like in_SUBCATNAME or similar)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...