有时我需要在DB中找到一些字符串,通常它只是主机名或IP地址。
是否有任何脚本在我有权访问的所有Sybase数据库对象(或至少在所有表中)中找到字符串。
答案 0 :(得分:1)
对sysobjects + cursor + EXECUTE的查询有效。有点儿。
sp__map_object 'SELECT * FROM %O where name like "bar%"', 'foo_%'
代码中存在很多错误/问题/担忧,我不愿意发布它,但我对Sybase患者有一定的同情。
Rob Verschoor有一堆很好的存储过程 http://www.sypron.nl/new_ssp_dwn.html
pjjH
289:1> ? sp__map_object (1 row affected) /* * * BE CAREFUL WHEN RUNNING THIS!!! * * See list of dire warnings in sp__map_db.sql * * Run the given command on the stored procedure for each object * matching @object_pat and replacing the first instance of %O with that * name. * * Just do this in Perl. Or refactor the sql so that it works for some sane * cross-product of users,logins, databases and objects. * * Paul Harrington * */ CREATE PROCEDURE sp__map_object @sql VARCHAR(255) = 'sp__help', @objpat VARCHAR(32) = NULL, @type VARCHAR(2) = 'U', @do_it INT = 1, @verbose INT = 0 AS BEGIN SET NOCOUNT ON DECLARE object_cursor CURSOR FOR SELECT DISTINCT name FROM sysobjects WHERE name LIKE @objpat AND type LIKE @type DECLARE @munged_sql VARCHAR(255) DECLARE @object_name varchar(64) OPEN object_cursor FETCH object_cursor INTO @object_name WHILE @@sqlstatus = 0 BEGIN IF CHARINDEX('%O', @sql) 0 SELECT @munged_sql = SUBSTRING(@sql, 1, CHARINDEX('%O', @sql) - 1) + @object_name + SUBSTRING(@sql, CHARINDEX('%O', @sql) + 2, 255) ELSE SELECT @munged_sql = @sql IF (@do_it = 0 OR @verbose = 1) BEGIN DECLARE @msg varchar(255) SELECT @msg = @munged_sql SELECT @msg END IF @do_it = 1 EXECUTE(@munged_sql) FETCH object_cursor INTO @object_name END CLOSE object_cursor DEALLOCATE CURSOR object_cursor SET NOCOUNT OFF END go
答案 1 :(得分:0)
我当然不知道。您也许可以滚动查询系统表的过程以获取对象列表,然后让光标通过并查询这些对象以查找给定的搜索条件。