Oracle数据库 如何根据某个字段名的值去查询存在的表列表
Posted 星小梦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle数据库 如何根据某个字段名的值去查询存在的表列表相关的知识,希望对你有一定的参考价值。
declare v_sql varchar2(1000); data_count number; begin -- OWNER是模式名 tablespace_name是表空间 for cur_table in (select distinct table_name from ALL_ALL_TABLES WHERE OWNER=\'NEWJNCJEXT\' and tablespace_name=\'JNCJ\') loop for cur_column in (select distinct column_name,data_type from all_tab_columns a where a.OWNER=\'NEWJNCJEXT\' and a.TABLE_NAME = cur_table.table_name) loop if cur_column.data_type = \'VARCHAR2\' then -- SQL 拼接 v_sql := \'select count(1) from \' || cur_table.table_name || \' where \' || cur_column.column_name || \'=\'\'EEB10A60-7117-11DE-8A60-CAAB113F4FFE\'\'\'; -- 执行SQL execute immediate v_sql into data_count; if (data_count > 0) then DBMS_OUTPUT.PUT_LINE(v_sql); end if; end if; end loop; end loop; end;
以上SQL是在Oracle 11g下执行的
关于 DBMS_OUTPUT.PUT_LINE 的输出方式,你可以参考 https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/controlstatements.htm#LNPLS399 里的一些示例
复制请注明出处,在世界中挣扎的灰太狼
修改数据库中所有表中包含某个字段名的值
1、查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like‘%你要查询的字段名%‘) and id in(select id from sysobjects where xtype=‘u‘) order by objname ; 2、查询包含某字段的所有存储过程 SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNER JOIN sysobjects obj ON sc.Id = obj.ID WHERE sc.TEXT LIKE ‘%你要查询的字段名%‘
declare @verId UNIQUEIDENTIFIER=‘xxxxx‘ BEGIN SET NOCOUNT ON; DECLARE @sql NVARCHAR(max) DECLARE cursorClearUserData CURSOR LOCAL FOR SELECT 表名 = D.name FROM syscolumns A LEFT JOIN systypes B ON A.xusertype=B.xusertype INNER JOIN sysobjects D ON A.id=D.id and D.xtype=‘U‘ and D.name<>‘dtproperties‘ LEFT JOIN sys.extended_properties g ON a.id=g.major_id AND a.colid=g.minor_id WHERE A.name= ‘IsUser‘ ORDER BY D.name ; OPEN cursorClearUserData DECLARE @tableName NVARCHAR(100); FETCH NEXT FROM cursorClearUserData INTO @tableName WHILE @@FETCH_STATUS = 0 BEGIN SET @sql = ‘update ‘ + @tableName + ‘ set IsUser= 0 where Pro_PrVeId=‘+ ‘‘‘‘+CAST(@verId AS NVARCHAR(36)) + ‘‘‘‘+‘;‘ print @tableName FETCH NEXT FROM cursorClearUserData INTO @tableName END CLOSE cursorClearUserData DEALLOCATE cursorClearUserData SET NOCOUNT OFF; END
以上是关于Oracle数据库 如何根据某个字段名的值去查询存在的表列表的主要内容,如果未能解决你的问题,请参考以下文章
oracle中已经知道一个具体值,如何根据该值查询出含有该值的表名和列名?