能通过存储过程实现吗?

flame100 2018-08-21 07:54:05
同一服务器下,有多个数据库(百来个),有相同结构的数据表tableA, 表有字段phone,能通过字段phone,查找出对应的数据库名吗?已知该字段数据不会同时出现在2个不同的数据库中。
...全文
707 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2018-09-01
  • 打赏
  • 举报
回复
select 'db01' as db from db01.tableA where phone='010-1234 5678' union all
select 'db02' as db from db02.tableA where phone='010-1234 5678' union all
select 'db03' as db from db03.tableA where phone='010-1234 5678' union all
select 'db04' as db from db04.tableA where phone='010-1234 5678' union all
select 'db05' as db from db05.tableA where phone='010-1234 5678' union all
...
select 'db99' as db from db99.tableA where phone='010-1234 5678'
zjcxc 2018-08-21
  • 打赏
  • 举报
回复
select table_schema, table_name from information_schema.columns where column_name='phone';
flame100 2018-08-21
  • 打赏
  • 举报
回复
引用 1 楼 baidu_36457652 的回复:
information_schema.columns 和information_schema.tables就能查出来

通过这两个,我只能查出包含phone字段的所有数据库,不能定位到哪个库吧?
本来想用游标实现判断,但怎么试都不行。
  • 打赏
  • 举报
回复
information_schema.columns 和information_schema.tables就能查出来

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧