今天用友軟件免費(fèi)下載網(wǎng)站要給大家分享一段SQL代碼,主要用于檢測(cè)用友軟件的數(shù)據(jù)庫(kù)是否有特殊字符?例如說(shuō)TAB鍵,空格,特殊符號(hào)等,可直接用于檢測(cè),廢話不多說(shuō),直接上源SQL代碼,大家自己嘗試使用吧!
-----檢測(cè)表中特殊字符,如tab、換行符、回車符--- ------將wa_gzdata替換成要檢查的表名即可 ---- ------將有特殊字符的列存放在tmp_aa臨時(shí)表中 go if exists(select * from sysobjects where name='tmp_aa' and xtype='U') drop table tmp_aa go CREATE TABLE tmp_aa( a varchar(20), b varchar(20)) go declare @tablename varchar (50) set @tablename='wa_gzdata' declare my_cur cursor for select name from syscolumns where id = object_id(@tablename) and xtype in (167,175,239,99)--nvarchar,varchar,char,nchar型 open my_cur declare @col_ls nvarchar(50) fetch next from my_cur into @col_ls while @@fetch_status=0 BEGIN declare @sql1 varchar(1000),@ls_where varchar(100),@ls_set varchar(100) declare @sql2 varchar(1000) declare @sql3 varchar(1000) --檢測(cè)tab鍵 select @sql1 = 'select '+@col_ls+' from '+@tablename +' where CHARINDEX(CHAR(9),'+@col_ls+')>0' set @ls_where=' where CHARINDEX(CHAR(9),'+@col_ls+')>0' select @sql1 = 'select '+@col_ls+' from '+@tablename +@ls_where EXEC(@sql1) --------替換tab if @@ROWCOUNT>0 begin insert into tmp_aa (a,b) values (@col_ls,'tab鍵') set @sql1='update'+@tablename +' set ' +@col_ls+'=' set @ls_set='REPLACE('+@col_ls+',char(9),'+''''+''''+')' select @sql2= 'update '+ @tablename+ ' set ' +@col_ls+'='+@ls_set+@ls_where --print @sql2 exec(@sql2) end set @sql1='' --char(10)檢測(cè)換行 select @sql1 = 'select '+@col_ls+' from '+@tablename +' where CHARINDEX(CHAR(10),'+@col_ls+')>0' set @ls_where=' where CHARINDEX(CHAR(10),'+@col_ls+')>0' select @sql1 = 'select '+@col_ls+' from '+@tablename +@ls_where --print @sql1 EXEC(@sql1) if @@ROWCOUNT>0 begin insert into tmp_aa (a,b) values (@col_ls,'換行符') set @sql1='update'+@tablename +' set ' +@col_ls+'=' set @ls_set='REPLACE('+@col_ls+',char(10),'+''''+''''+')' select @sql2= 'update '+ @tablename+ ' set ' +@col_ls+'='+@ls_set+@ls_where -- print @sql2 exec(@sql2) end set @sql1='' --- --char(13)檢測(cè)回車鍵 select @sql1 = 'select '+@col_ls+' from '+@tablename +' where CHARINDEX(CHAR(10),'+@col_ls+')>0' set @ls_where=' where CHARINDEX(CHAR(10),'+@col_ls+')>0' select @sql1 = 'select '+@col_ls+' from '+@tablename +@ls_where --print @sql1 EXEC(@sql1) if @@ROWCOUNT>0 begin insert into tmp_aa (a,b) values (@col_ls,'回車鍵') set @sql1='update'+@tablename +' set ' +@col_ls+'=' set @ls_set='REPLACE('+@col_ls+',char(13),'+''''+''''+')' select @sql2= 'update '+ @tablename+ ' set ' +@col_ls+'='+@ls_set+@ls_where --print @sql2 exec(@sql2) end fetch next from my_cur into @col_ls END close my_cur DEALLOCATE my_cur