oracle查询字段中值,oracle需要查询某个字段的值在其他某个表中有没的值有相同...

使用场景:知道某个字段的值(例如:“张三”),需要查询在其他某个表中有没有相同的值,常用于搜索关联表等。

对于oracle数据库:

Pl\sql没有搜索功能,需借助存储过程,完成搜索,搜索结果是将表名插入到一个表中。

[if !supportLists]1、[endif]创建临时表:

create table TMPTABLE

(

NAME VARCHAR2(500)

);

[if !supportLists]2、[endif]存储过程如下

create or replace procedure QUERY_KEY

(

keyword in varchar2

)

as

v_SQLStatement varchar2(300);

v_startRecord Number;

begin

FOR reInfo IN (select table_name from user_tables) LOOP

FOR colInfo IN (SELECT column_name, DATA_TYPE FROM all_tab_cols WHERE table_name=reInfo.table_name) LOOP

IF (colInfo.DATA_TYPE='VARCHAR2') THEN

v_SQLStatement := 'select count(*) from '|| reInfo.table_name || ' where ' || colInfo.column_name || ' = ''' || keyword|| '''';

-- dbms_output.put_line(v_SQLStatement);

execute immediate v_SQLStatement into v_startRecord;

IF(v_startRecord > 0) THEN

--  dbms_output.put_line(reInfo.table_name);

insert into TMPTABLE values (reInfo.table_name);

commit;

END IF;

END IF;

END LOOP;

END LOOP;

END QUERY_KEY;

[if !supportLists]3、[endif]在pl\sql中command窗口执行如下命令,其中“123”为要查询的数据

21fa461f8ab6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

[if !supportLists]4、[endif]然后在TMPTABLE中即可查询到包含此字段的数据

对于mysql数据库:

选择数据库,右键“在数据库中查找...”,在下方“查找”输入需要查询的字段,点击查找,右侧即显示查找结果

21fa461f8ab6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值