简体   繁体   中英

Can I run an IF statement form the mysql command line? v 5.6

SET @credit = 'True'; // This works query ok.

If @credit = 'True' THEN SET @credit = 'False'; // Get an error

SELECT @credit; // can't get this far

Trying to run a mysql IF statement from the console, but can't get the simplest of statements to work? What am I missing? The error: There is an error near If @credit = True THEN SET @credit = False'

The IF statement is for use in stored procedures.

You can use the IF function:

SET @credit='True';
SET @credit=IF(@credit='True','False',@credit);
SELECT @credit;

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