skip to main | skip to sidebar

SQL Tutorial with Examples

Pages

  • Home
 
  • RSS
  • Facebook
  • Twitter
Sunday, October 14, 2012

Oracle and SQL Server Database Search String procedure

Posted by Raju Gupta at 12:26 AM – 1 comments
 
This Procedure/Query is used to search list of strings available in Oracle/SQL server database. The strings to be searched should be passed as a parameter to the Procedure/Query. The results will be entered in a temporary table with the Table name and field name where the strings are found in the database.


CREATE PROCEDURE  strCheck 
(@strck varchar(100))

 AS

create table tbl3( num int)
create table TEMP_rec(tblName varchar(50),colName varchar(50))
Declare @tblName as varchar(25)
Declare @colName as varchar(25)
declare @colType as varchar(25)
declare @sql as varchar(200)

declare @num as int 
Declare tblcur cursor for 
select table_name as Name from INFORMATION_SCHEMA.Tables 
open tblcur 
 fetch next from tblcur into @tblName
while @@fetch_status=0

begin
 Declare colcur cursor for 
 SELECT column_Name,Data_Type FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =   @tblName
   
 open colcur 
  fetch next from colcur into @colName,@coltype
  while @@fetch_status=0
  begin
   if @coltype='char' or @coltype='varchar'
   begin
    set @sql=''
    set @sql='select 1 from '
    select @sql = @sql + @tblName + ' where ' + @colname + ' like ' + '''%' + @strck + '%'''
    insert into tbl3 
     exec (@sql)
    if exists (select * from tbl3)
    begin
     delete from tbl3
     insert into TEMP_rec
      select @tblName,@colName
    end
   end
   fetch next from colcur into @colName,@coltype
  end
 close colcur
 deallocate colcur
    fetch next from tblcur into @tblName

end

close tblcur
deallocate tblcur
select * from TEMP_rec
drop table tbl3
drop table TEMP_rec
GO
Labels: Oracle SQL Query, Stored Procedure Example, String Search Query Email This BlogThis! Share to X Share to Facebook

One Response so far.

  1. Unknown says:
    December 3, 2017 at 9:42 PM

    Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this."Oracle Training in Bangalore"

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments (Atom)
  • Popular
  • Recent
  • Archives

Popular Posts

  • Comparing data (rows)in two tables in PL/SQL
    Pl/sql code have Cursors that will fetch table and columns that you want to compare and it will Iterate through all tables in the local d...
  • Oracle Sql Queries to view dependencies and partitioning.
    This is the list of queries to find out the dependencies between databse objects and to find out the partitioning details of a table. 1...
  • Oracle PL/SQL Query for Pagination
    Oracle PL/SQL function makes the input query statement such a way that the query out put returns for a start row index to end row index. ...
  • Serial Number Related Query
    This query will let us know the corresponding Sales Order number associated with a given serial number installed in Installed Base. -...
  • Oracle and SQL Server Database Search String procedure
    This Procedure/Query is used to search list of strings available in Oracle/SQL server database. The strings to be searched should be passed...
  • Multi User session Kill in Oracle
    To kill the inactive users login in Oracle from any schema in a database.If any unwanted transactions were kept withput roll back it will...
  • SQL tips
    Re-usable SQL Queries useful in day-to-day scenario. COMMON QUERIES *************** SELECT instance_name FROM v$instance; ...
  • Query to search Special character in word
    The query looks for any special characters in column field (specially useful for password field) and reports it.   SELECT DISTINCT emp...
  • TABLE FINDER
    Table_Finder is a procedure to find all the tables that are queried in a particular package or procedure. It takes Package name or procedur...
  • Advance SQL
    The query that uses partition OVER PARTITION BY analytic function The below example shows the cumulative salary within a departement ...
Powered by Blogger.

Archives

  • ▼  2012 (11)
    • ▼  October (11)
      • Comparing data (rows)in two tables in PL/SQL
      • Serial Number Related Query
      • SQL tips
      • Advance SQL
      • Query to search Special character in word
      • Multi User session Kill in Oracle
      • TABLE FINDER
      • Oracle PL/SQL Query for Pagination
      • Oracle and SQL Server Database Search String proce...
      • Deletion Records of Duplicate
      • Oracle Sql Queries to view dependencies and partit...
 

Labels

  • Delete Query (1)
  • Oracle SQL Query (4)
  • PL/SQL Example (2)
  • Stored Procedure Example (3)
  • String Search Query (1)
  • System Query (1)

Followers

 
 
© 2011 SQL Tutorial with Examples | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger