对于MySQL改变这个:
DECLARE @url VARCHAR(255)
SET @url = '1720'至:
SET @url := '1720'在MySQL中,您没有DECLARE用户变量,只需将它们设置为值即可。等号适用于赋值,但在SQL语句中除外,您需要使用Pascal样式的:=作为赋值运算符。 (我通常在SET语句的上下文中使用:=赋值运算符,即使在等号中也能正常工作。)
但是,在查看SQL语句时,似乎这是Microsoft SQL Server语法,+运算符用于连接,sysobjects的引用,syscolumns.xtype。
这句话无法从MySQL返回任何有用的东西。
整个语句需要重新编写才能查询:
information_schema.tables
information_schema.columns作为一个示例出发点:
SET @url := 'foobar';
SELECT CONCAT('select * from `',col.table_schema
,'`.`',col.table_name
,'` where `',col.column_name
,'` like ''%',RTRIM(@url),'%''') AS q
FROM information_schema.columns col
JOIN information_schema.tables tbl
ON tbl.table_schema = col.table_schema
AND tbl.table_name = col.table_name
AND tbl.table_type = 'BASE TABLE'
WHERE col.data_type IN ('varchar','char')
AND col.character_maximum_length >= 30
AND col.table_schema = 'mydatabase';
UPDATE: B>
要在每个查询的结果集中包含“查询ID”,以便您可以识别哪些查询返回行...
SELECT CONCAT('select ',@rn := @rn + 1, ' as q, t.* from `',col.table_schema
,'`.`',col.table_name
,'` t where `',col.column_name
,'` like ''%',RTRIM(@url),'%''') AS q
FROM (SELECT @rn := 0) r
JOIN information_schema.columns col
JOIN information_schema.tables tbl
ON tbl.table_schema = col.table_schema
AND tbl.table_name = col.table_name
AND tbl.table_type = 'BASE TABLE'
WHERE col.data_type IN ('varchar','char')
AND col.character_maximum_length >= 30
AND col.table_schema = 'mydatabase';