开发者

Mysql stored function help needed

开发者 https://www.devze.com 2023-03-03 16:12 出处:网络
Can i pass a sql where condition string as a param to a SP and execute it inside? I would like to return the no. of rows inserted as well... but why its not working?

Can i pass a sql where condition string as a param to a SP and execute it inside? I would like to return the no. of rows inserted as well... but why its not working?

phpmyadmin says .. **#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 'WhereCond;**

 DELIMITER //
    DROP FUNCTION IF EXISTS ExecSQL //
    CREATE FUNCTION ExecSQL(WhereCond text) RETURNS INT DETERMINISTIC
    BEGIN
        INSERT INTO myTable WhereCond;

        return ROW_COUNT();
    END //

My WhereCond in php is

$WhereCond = " (ID, Name) VALUES (556, 'Suraj')";
开发者_JS百科

I'm just playing with SPs, so dont mind if these questions sound like stupid


It is not working because you can't pass a part of sql query as argument for the stored function.

What you try to do here is:

INSERT INTO myTable "(ID, Name) VALUES (556, 'Suraj')";

which obviously is not a valid sql query.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号