Check value String in SQL

1

I am creating a trigger in SQL, in which I use the UDFs to invoke a JAVA code. This Java code returns a string, from which I have to check the value to allow an action or not. What SQL function can I use to check the contents of that String in an IF condition?

TRIGGER CODE:

CREATE TRIGGER ContentInsert

BEFORE INSERT ON joomladb.joomla_content
FOR EACH ROW
BEGIN
#DECLARE cmd CHAR(255);
DECLARE status CHAR(10);


SET status = sys_exec('java /rutadelarchivo/check_status.jar');

IF status NOT IN ("off") THEN
SIGNAL SQLSTATE '45000' -- "unhandled user-defined exception"
SET MESSAGE_TEXT = ' Cerrado';
END IF;
END

JAVA CODE:

public class check_status {
final static String APP_ID ="CADENADEEJEMPLO";

public static String principal_status(String accountId){
    LatchApp latch= new LatchApp(APP_ID,LATCH_SECRET);
    LatchResponse response=latch.status(accountId);
    String status=response.getData().get("operations").getAsJsonObject().get(APP_ID).getAsJsonObject().get("status").getAsString();
    return status;

}


}
    
asked by Mateo 11.08.2017 в 13:50
source

1 answer

0

In SQL standard the = is used if you know that the string will match and it is not a sub-string inside it, otherwise you will have to use LIKE.

if status = "off" then

with LIKE

if status like '%off%' then

I leave you a MySql manual, keep in mind that it may vary a bit depending on the database engine you use.

link

    
answered by 03.04.2018 в 15:20