简单的sql语句分解,通过存储过程。

DELIMITER $$

DROP PROCEDURE IF EXISTS `simpleSqlAnalyze`$$

CREATE PROCEDURE `simpleSqlAnalyze`(   $sqlString NVARCHAR(2000),   OUT $tableString NVARCHAR(2000),   OUT $fieldString NVARCHAR(2000),   OUT $whereString NVARCHAR(2000),   OUT $orderString NVARCHAR(2000)  )     SQL SECURITY INVOKER BEGIN  SET @sql1=$sqlString; SET @sql2=TRIM(@sql1); SET @fromNum=LOCATE(‘ from ‘,@sql2); SET @field =SUBSTRING(@sql2,7,@fromNum-7); SET @sql3= SUBSTRING(@sql2,@fromNum+6); SET @byNum= LOCATE(‘ by ‘,@sql3); IF @byNum>0 THEN BEGIN SET @sql4=LEFT(@sql3,@byNum-6); SET @byfd=SUBSTRING(@sql3,@byNum-6); END; ELSE BEGIN SET @sql4=@sql3; SET @byfd=‘‘; END; END IF;

SET @whereNum=LOCATE(‘ where ‘,@sql4);

IF @whereNum>0 THEN SET @tablefd=LEFT(@sql4,@whereNum); ELSE SET @tablefd=@sql4; END IF; SET @wherefd=SUBSTRING(@sql4,@whereNum); SET $tableString=@tablefd; SET $fieldString=@field; SET $whereString=@wherefd; SET $orderString=@byfd;

END$$

DELIMITER ;

#CALL simplesqlanalyze(‘     select f * from medialist join fd on sf=23  gro  where 2w32 select from where  group by dfsd   ‘,@a,@b,@c,@d);

简单的sql语句分解,通过存储过程。,布布扣,bubuko.com

简单的sql语句分解,通过存储过程。

上一篇:iOS开发Swift篇—(四)运算符


下一篇:ORA-16072: a minimum of one standby database destination is required