简体   繁体   中英

how can i pass input parameter with single quote in Stored Procedure

i have a stored procedure r, i'm passing the below string but it's not working??

call Prc_SearchKeyword('randomize', "'girl', 'playing'",2,0,31);

the below syntax is working fine..

call Prc_SearchKeyword('randomize', 'girl',1,0,31);



DELIMITER $$

CREATE PROCEDURE `Prc_SearchKeyword`(IN filter VARCHAR(50), IN midquery varchar(200), IN keywordcount int(10), In firstimage int(10), in lastimage int(10) )
BEGIN
IF(filter = 'nbofviews') Then
SELECT sd.imageid, sd.imgcollection, sd.Caption FROM   (SELECT p.imageid  FROM searchinitial_views p join searchkwdmgmt s on p.primarykeyword = s.primary_kwd and s.allkwd in (midquery) GROUP  BY p.imageid HAVING Count(distinct p.primarykeyword) = keywordcount order by views desc  LIMIT  firstimage, lastimage ) q join searchdetails sd ON sd.imageid = q.imageid ;
END IF;
IF(filter = 'shootdate') Then
SELECT sd.imageid, sd.imgcollection, sd.Caption FROM   (SELECT p.imageid  FROM searchinitial_shootdate p join searchkwdmgmt s on p.primarykeyword = s.primary_kwd and s.allkwd in (midquery) GROUP  BY p.imageid HAVING Count(distinct p.primarykeyword) = keywordcount order by shootdate desc  LIMIT  firstimage, lastimage ) q join searchdetails sd ON sd.imageid = q.imageid ;
END IF;
IF(filter = 'randomize') Then
SELECT sd.imageid, sd.imgcollection, sd.Caption FROM   (SELECT p.imageid  FROM searchinitial_random p join searchkwdmgmt s on p.primarykeyword = s.primary_kwd and s.allkwd in (midquery) GROUP  BY p.imageid HAVING Count(distinct p.primarykeyword) = keywordcount order by random desc  LIMIT  firstimage, lastimage ) q join searchdetails sd ON sd.imageid = q.imageid;
END IF;
IF(filter = 'priority') Then
SELECT sd.imageid, sd.imgcollection, sd.Caption FROM   (SELECT p.imageid  FROM searchinitial_priority p join searchkwdmgmt s on p.primarykeyword = s.primary_kwd and s.allkwd in (midquery) GROUP  BY p.imageid HAVING Count(distinct p.primarykeyword) = keywordcount order by priority desc  LIMIT  firstimage, lastimage ) q join searchdetails sd ON sd.imageid = q.imageid ;
END IF;
END

您需要查找如何转义字符,即使用两个单引号而不是一个''girl'',''playing''

You can escape single quotes with two single quotes: for example:

... where lastname='O''Malley'

in your case:

''girl'',''playing''

Since MySQL recognizes both single and double quotes as string delimiters, one option is to use double quotes when you want to include single quotes in the value, or vice versa.

call YourProc("'girl', 'playing'");

The alternative is to escape the quotes with backslash:

call YourProc('\'girl\', \'playing\'');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM