0

I am bit confused with Mysql syntax. I want to check for NULL the value of ExtractValue(xml, '//order[1]/quantity[$@i]') function. It can be assign to variable or this action can be skipped. I tried this and there is syntax error:

DELIMITER $$

DROP PROCEDURE IF EXISTS `sp_test_for_null`$$

CREATE PROCEDURE `sp_test_for_null`()
BEGIN
DECLARE xml VARCHAR(1000);
SET xml = '';
DECLARE test VARCHAR(1000);
SET test = (SELECT ExtractValue(xml, '//order[1]/quantity[$@i]');
IF (test IS NULL) THEN SELECT 1; END IF;
END$$

DELIMITER ;

CALL sp_test_for_null;

1 Answer 1

1

I'd try this (note that all DECLAREs are at the beginning:

DELIMITER $$

DROP PROCEDURE IF EXISTS `sp_test_for_null`$$

CREATE PROCEDURE `sp_test_for_null`()
BEGIN
    DECLARE xml VARCHAR(1000);
    DECLARE test VARCHAR(1000);

    SET xml = '';
    SET test = (SELECT ExtractValue(xml, '//order[1]/quantity[$@i]');
    SELECT ISNULL(test, 1, 0);
END$$

DELIMITER ;

CALL sp_test_for_null;
Sign up to request clarification or add additional context in comments.

5 Comments

Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE test VARCHAR(1000)' at line 1
I updated the question. It is inside the stored proc. @ does not work either
Query: CREATE PROCEDURE sp_test_for_null() BEGIN DECLARE xml VARCHAR(1000); DECLARE test VARCHAR(1000); SET xml = ''; SET test = (SEL... Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; IF (test IS NULL) THEN SELECT 1; END IF; END' at line 6
I updated again. It doesn't make sense to select nothing if test is not null.
I modified the question, there was [$@i], I put 1 there, but still error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.