Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用IBexpert在整个SQL数据库中搜索指定字符?_Sql_Firebird_Firebird2.1_Ibexpert - Fatal编程技术网

如何使用IBexpert在整个SQL数据库中搜索指定字符?

如何使用IBexpert在整个SQL数据库中搜索指定字符?,sql,firebird,firebird2.1,ibexpert,Sql,Firebird,Firebird2.1,Ibexpert,如何使用IBexpert在整个数据库中搜索某些特定字符 例如: 我有一些“'”(')在某些部分的数据表,这是我以后得到一个错误,我有许多表手动搜索。。。我怎么做 Thx我认为最好的办法是您可以生成自己的脚本并在数据库上运行它。在这种情况下,isql(firebird的命令文本行工具)比IBExpert更好地完成这一点 因此,第一步是查找所有char或varchar列,并为每个表中的每个字段构造一个自定义查询。将此脚本另存为数据库所在目录下的create_search_script.sql(如果连

如何使用IBexpert在整个数据库中搜索某些特定字符

例如:

我有一些“'”(')在某些部分的数据表,这是我以后得到一个错误,我有许多表手动搜索。。。我怎么做


Thx

我认为最好的办法是您可以生成自己的脚本并在数据库上运行它。在这种情况下,isql(firebird的命令文本行工具)比IBExpert更好地完成这一点

因此,第一步是查找所有char或varchar列,并为每个表中的每个字段构造一个自定义查询。将此脚本另存为数据库所在目录下的create_search_script.sql(如果连接到远程数据库,则保存在任何目录下)

现在,启动新的命令会话,转到(cd)该文件夹并运行以下命令:

del search_results.txt
del search_script.sql
isql your-db.fdb -u sysdba -p masterkey -o search_script.sql -i create_search_script.sql
isql your-db.fdb -u sysdba -p masterkey -o search_results.txt -i search_script.sql
如果您使用的是linux,那么在某些发行版中,isql工具的名称是isql fb(我想是在firebird 1.5之后,不太确定)

在运行前,在命令行上替换为您自己的数据库名、用户名和密码

现在,search_results.txt文件将包含整个数据库的所有匹配记录的列表

set heading off;
set blob off;
set width sql 400;
select '--tables with a primary key' from rdb$database;

select
       trim(
         cast(
             'select '
           ||''''
           ||trim(rf.rdb$relation_name)
           ||''''
           ||', '
           ||(select list(trim(isg.rdb$field_name))
                from rdb$index_segments isg
               where isg.rdb$index_name = (select rc.rdb$index_name
                                             from rdb$relation_constraints rc
                                            where rc.rdb$relation_name = rf.rdb$relation_name
                                              and rc.rdb$constraint_type = 'PRIMARY KEY'))
           ||', '
           ||trim(rf.rdb$field_name)
           ||' from '
           ||trim(rf.rdb$relation_name)
           ||' where '
           ||trim(rf.rdb$field_name)
           ||' like ''%''''%'';'
           as varchar(2000))
       ) sql
  from rdb$relation_fields rf
       inner join rdb$relations r on r.rdb$relation_name = rf.rdb$relation_name
       inner join rdb$fields f on f.rdb$field_name = rf.rdb$field_source
       inner join rdb$types t on t.rdb$field_name = 'RDB$FIELD_TYPE' and t.rdb$type = f.rdb$field_type
 where t.rdb$type_name = 'TEXT'
   and coalesce(r.rdb$system_flag, 0) != 1
   and exists (select 1
                 from rdb$relation_constraints rc
                where rc.rdb$relation_name = rf.rdb$relation_name
                  and rc.rdb$constraint_type = 'PRIMARY KEY'
              )
;
select '--tables without a primary key' from rdb$database;
select trim(
         'select '
       ||''''
       ||trim(rf.rdb$relation_name)
       ||''''
       ||', tbl.*'
       ||' from '
       ||trim(rf.rdb$relation_name)
       ||' tbl where '
       ||trim(rf.rdb$field_name)
       ||' like ''%''''%'';'
       ) sql
  from rdb$relation_fields rf
       inner join rdb$relations r on r.rdb$relation_name = rf.rdb$relation_name
       inner join rdb$fields f on f.rdb$field_name = rf.rdb$field_source
       inner join rdb$types t on t.rdb$field_name = 'RDB$FIELD_TYPE' and t.rdb$type = f.rdb$field_type
 where t.rdb$type_name = 'TEXT'
   and coalesce(r.rdb$system_flag, 0) != 1
   and not exists (select 1
                 from rdb$relation_constraints rc
                where rc.rdb$relation_name = rf.rdb$relation_name
                  and rc.rdb$constraint_type = 'PRIMARY KEY'
              )
;
警告小心。。。如果该文件夹中有一个名为search_script.sql或search_results.txt的文件。。。在运行命令之前更改文件名,或调整命令以使用其他文件名

-o用于isql命令行工具的modifier不会覆盖文件,因此需要先删除该文件才能获得新的脚本和报告

该脚本在windows中针对firebird 2.1服务器进行了测试,但它适用于大多数firebird版本和平台


享受吧

我会在脚本中导出数据库数据,并使用我喜欢搜索的任何文本编辑器。