excel生成mysql语句_通过SQL语句直接实现Excel与数据库的导入导出

1、在SQL数据库中直接从Excel里面查询数据:

select \* from

OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:\\test.xls',sheet1$)

2、从Excel文件中,导入数据到SQL数据库中,

select \* into 表 from

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,'Excel 5.0;HDR=YES;DATABASE=c:\\test.xls',sheet1$)

3、从SQL数据库中,导出数据到Excel(excel存在),

insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,'Excel 5.0;HDR=YES;DATABASE=c:\\test.xls',sheet1$)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) select \* from 表

4、从SQL数据库中,导出数据到Excel(excel不存在),

\---- 导出表

EXEC master..xp\_cmdshell 'bcp 数据库名.dbo.表名 out "c: est.xls" /c -/S"服务器名" /U"用户名" -P"密码"'

---- 导出查询语句

EXEC master..xp\_cmdshell 'bcp "SELECT au\_fname, au\_lname FROM pubs..authors ORDER BY au\_lname" queryout "c: est.xls" /c -/S"服务器名" /U"用户名" -P"密码"'

5、导入导出的存储过程

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--下面是导出真正Excel文件的方法:(请将一下所有代码复制到存储过程中)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifexists (select\*from dbo.sysobjects where id \=object\_id(N'\[dbo\].\[p\_exporttb\]') andOBJECTPROPERTY(id, N'IsProcedure') \=1)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)dropprocedure\[dbo\].\[p\_exporttb\]

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)GO

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)/\*\--数据导出EXCEL

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 导出表中的数据到Excel,包含字段名,文件为真正的Excel文件

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ,如果文件不存在,将自动创建文件

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ,如果表不存在,将自动创建表

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 基于通用性考虑,仅支持导出标准数据类型

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\--邹建 2003.10(引用请保留此信息)--\*/

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)/\*\--调用示例

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) p\_exporttb @tbname='地区资料',@path='c:',@fname='aa.xls'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\--\*/

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)createproc p\_exporttb

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@tbname sysname,    \--要导出的表名

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@pathnvarchar(1000),   \--文件存放目录

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@fnamenvarchar(250)\=''\--文件名,默认为表名

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)as

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)declare@errint,@srcnvarchar(255),@descnvarchar(255),@outint

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)declare@objint,@constrnvarchar(1000),@sqlvarchar(8000),@fdlistvarchar(8000)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--参数检测

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifisnull(@fname,'')\=''set@fname\=@tbname+'.xls'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--检查文件是否已经存在

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifright(@path,1)<>''set@path\=@path+''

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)createtable #tb(a bit,b bit,c bit)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\=@path+@fname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)insertinto #tb exec master..xp\_fileexist @sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--数据库创建语句

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\=@path+@fname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifexists(select1from #tb where a\=1)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) set@constr\='DRIVER={Microsoft Excel Driver (\*.xls)};DSN='''';READONLY=FALSE'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)       +';CREATE\_DB="'+@sql+'";DBQ='+@sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)else

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) set@constr\='Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties="Excel 8.0;HDR=YES'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    +';DATABASE='+@sql+'"'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--连接数据库

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oacreate 'adodb.connection',@obj out

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oamethod @obj,'open',null,@constr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)/\*\--如果覆盖已经存在的表,就加上下面的语句

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\--创建之前先删除表/如果存在的话

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)select @sql='drop table \['+@tbname+'\]'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)exec @err=sp\_oamethod @obj,'execute',@out out,@sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\--\*/

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--创建表的SQL

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@sql\='',@fdlist\=''

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@fdlist\=@fdlist+',\['+a.name+'\]'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,@sql\=@sql+',\['+a.name+'\] '

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  +case

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%char'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   thencasewhen a.length\>255then'memo'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    else'text('+cast(a.length asvarchar)+')'end

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%int'or b.name\='bit'then'int'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%datetime'then'datetime'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%money'then'money'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%text'then'memo'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   else b.name end

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)FROM syscolumns a leftjoin systypes b on a.xtype\=b.xusertype

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)where b.name notin('image','uniqueidentifier','sql\_variant','varbinary','binary','timestamp')

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) andobject\_id(@tbname)\=id

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@sql\='create table \['+@tbname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) +'\]('+substring(@sql,2,8000)+')'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,@fdlist\=substring(@fdlist,2,8000)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oamethod @obj,'execute',@out out,@sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oadestroy @obj

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--导入数据

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\='openrowset(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;HDR=YES;IMEX=1

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   ;DATABASE='+@path+@fname+''',\['+@tbname+'$\])'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec('insert into '+@sql+'('+@fdlist+') select '+@fdlist+' from '+@tbname)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)return

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)lberr:

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) exec sp\_oageterrorinfo 0,@src out,@desc out

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)lbexit:

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) selectcast(@errasvarbinary(4)) as 错误号

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  ,@srcas 错误源,@descas 错误描述

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) select@sql,@constr,@fdlist

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)go

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifexists (select\*from dbo.sysobjects where id \=object\_id(N'\[dbo\].\[p\_exporttb\]') andOBJECTPROPERTY(id, N'IsProcedure') \=1)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)dropprocedure\[dbo\].\[p\_exporttb\]

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)GO

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)/\*\--数据导出EXCEL

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 导出查询中的数据到Excel,包含字段名,文件为真正的Excel文件

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 如果文件不存在,将自动创建文件

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 如果表不存在,将自动创建表

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) 基于通用性考虑,仅支持导出标准数据类型

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\--邹建 2003.10(引用请保留此信息)--\*/

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)/\*\--调用示例

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) p\_exporttb @sqlstr='select \* from 地区资料'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  ,@path='c:',@fname='aa.xls',@sheetname='地区资料'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\--\*/

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)createproc p\_exporttb

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@sqlstrvarchar(8000),   \--查询语句,如果查询语句中使用了order by ,请加上top 100 percent

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@pathnvarchar(1000),   \--文件存放目录

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@fnamenvarchar(250),   \--文件名

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)@sheetnamevarchar(250)\=''\--要创建的工作表名,默认为文件名

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)as

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)declare@errint,@srcnvarchar(255),@descnvarchar(255),@outint

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)declare@objint,@constrnvarchar(1000),@sqlvarchar(8000),@fdlistvarchar(8000)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--参数检测

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifisnull(@fname,'')\=''set@fname\='temp.xls'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifisnull(@sheetname,'')\=''set@sheetname\=replace(@fname,'.','#')

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--检查文件是否已经存在

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifright(@path,1)<>''set@path\=@path+''

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)createtable #tb(a bit,b bit,c bit)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\=@path+@fname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)insertinto #tb exec master..xp\_fileexist @sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--数据库创建语句

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\=@path+@fname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)ifexists(select1from #tb where a\=1)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) set@constr\='DRIVER={Microsoft Excel Driver (\*.xls)};DSN='''';READONLY=FALSE'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)       +';CREATE\_DB="'+@sql+'";DBQ='+@sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)else

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) set@constr\='Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties="Excel 8.0;HDR=YES'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    +';DATABASE='+@sql+'"'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--连接数据库

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oacreate 'adodb.connection',@obj out

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oamethod @obj,'open',null,@constr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--创建表的SQL

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)declare@tbname sysname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@tbname\='##tmp\_'+convert(varchar(38),newid())

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\='select \* into \['+@tbname+'\] from('+@sqlstr+') a'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec(@sql)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@sql\='',@fdlist\=''

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@fdlist\=@fdlist+',\['+a.name+'\]'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,@sql\=@sql+',\['+a.name+'\] '

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  +case

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%char'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   thencasewhen a.length\>255then'memo'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    else'text('+cast(a.length asvarchar)+')'end

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%int'or b.name\='bit'then'int'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%datetime'then'datetime'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%money'then'money'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   when b.name like'%text'then'memo'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   else b.name end

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)FROM tempdb..syscolumns a leftjoin tempdb..systypes b on a.xtype\=b.xusertype

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)where b.name notin('image','uniqueidentifier','sql\_variant','varbinary','binary','timestamp')

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) and a.id\=(select id from tempdb..sysobjects where name\=@tbname)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@@rowcount\=0return

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)select@sql\='create table \['+@sheetname

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) +'\]('+substring(@sql,2,8000)+')'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ,@fdlist\=substring(@fdlist,2,8000)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oamethod @obj,'execute',@out out,@sql

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if@err<>0goto lberr

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec@err\=sp\_oadestroy @obj

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)\--导入数据

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\='openrowset(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;HDR=YES

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)   ;DATABASE='+@path+@fname+''',\['+@sheetname+'$\])'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec('insert into '+@sql+'('+@fdlist+') select '+@fdlist+' from \['+@tbname+'\]')

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set@sql\='drop table \['+@tbname+'\]'

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)exec(@sql)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)return

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)lberr:

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) exec sp\_oageterrorinfo 0,@src out,@desc out

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)lbexit:

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) selectcast(@errasvarbinary(4)) as 错误号

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  ,@srcas 错误源,@descas 错误描述

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) select@sql,@constr,@fdlist

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)go

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/426136.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基础知识小记:

什么时候用这些循环&#xff1f; 1,、for(i;i<n;i) 知道循环的起止数, 循环中需要用到不断递增/递减的变量 2、for(String s:slist) 叫foreach循环, 遍历数组/集合中元素用的 为了减少代码量 3、while 不知道确切的循环次数, 但知道循环结束条件时使用 4、do while 先执行一…

java学习(127):finally语句

finally作为异常处理的一部分&#xff0c;它只能用在try/catch语句中&#xff0c;并且附带一个语句块&#xff0c;表示这段语句最终一定会被执行&#xff08;不管有没有抛出异常&#xff09;&#xff0c;经常被用在需要释放资源的情况下。 之前在写爬虫的时候数据库连接的频率…

[剑指offer]面试题第[6]题[JAVA][旋转数组的最小数字][二分法]

####【问题描述】 把一个数组最开始的若干个元素搬到数组的末尾&#xff0c;我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转&#xff0c;输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转&#xff0c;该数组的最小值为1。 NOTE&#xff1a;给出…

mysql合并多条纪录字段_Mysql应用mysql合并多条记录的单个字段去一条记录编辑

《MysqL应用MysqL合并多条记录的单个字段去一条记录编辑》要点&#xff1a;本文介绍了MysqL应用MysqL合并多条记录的单个字段去一条记录编辑&#xff0c;希望对您有用。如果有疑问&#xff0c;可以联系我们。测试用表结构&#xff1a;代码如下:---- 表的结构 tet--CREATE TABLE…

git之项目上传

git之项目上传 需求&#xff1a;将项目代码上传至github 前期准备&#xff1a; 1.github账号注册 2.安装git环境&#xff0c;可以打开且使用git shell. 3.生成SSH key并与github账号绑定 步骤&#xff1a; 1.进入gitshell 2. 进入到项目指定的目录下&#xff0c;适用git命令初始…

[leedcode][409][java]

####【题目描述】 给定一个包含大写字母和小写字母的字符串&#xff0c;找到通过这些字母构造成的最长的回文串。在构造过程中&#xff0c;请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。注意: 假设字符串的长度不会超过 1010。示例 1:输入: "abccccdd…

玩转oracle 11g(35):rman备份-参数文件spfile损坏恢复

1.参数文件spfile损坏恢复 (1)选择“开始”“运行”&#xff0c;输入cmd&#xff0c;按回车。 (2)输入“ set oracle_siddocare”&#xff0c;按回车。 &#xff08;oracle_sid根据实际名称填写&#xff09; (3)输入“rman target /”&#xff0c;按回车 如果在64bit下安装…

python获取页面隐藏元素_selenium操作隐藏的元素(python+Java)

有时候我们会碰到一些元素不可见&#xff0c;这个时候selenium就无法对这些元素进行操作了。例如&#xff0c;下面的情况&#xff1a;Python页面主要通过“display:none”来控制整个下拉框不可见。这个时候如果直接操作这个下拉框&#xff0c;就会提示&#xff1a;from seleniu…

docker 配置文件:/etc/docker/daemon.json

/etc/docker/daemon.json 是 docker 的配置文件&#xff0c;默认是没有的&#xff0c;需要我们手动创建&#xff0c;可配置项如下&#xff1a; [rootlocalhost ~]$ vim /etc/docker/daemon.json {"authorization-plugins": [],"data-root": "", …

[leedcode][JAVA][365][BFS]

【问题描述】 有两个容量分别为 x升 和 y升 的水壶以及无限多的水。请判断能否通过使用这两个水壶&#xff0c;从而可以得到恰好 z升 的水&#xff1f;如果可以&#xff0c;最后请用以上水壶中的一或两个来盛放取得的 z升 水。你允许&#xff1a;装满任意一个水壶 清空任意一个…

玩转oracle 11g(36):rman备份-控制文件丢失恢复

ORA-00205: error in identifying control file, check alert log for more info 检查oracle的报警日志包含类似报错&#xff1a; ORA-00210: cannot open the specified control file ORA-00202: control file: D:\ORACLE\PRODUCT\10.2.0\ORADATA\DOCARE\C ONTROL01.CTL OR…

=在 java中怎么表示_在Java中各种类型运算符的介绍与其基本使用方式(有具体使用示例)...

一.算数运算符基本四则运算符 - * / %(使用规则简单&#xff0c;正常使用即可)注意事项&#xff1a;a) int/int 结果还是 int 要保留小数需要使用double来计算int a 1;int b 2;System.out.println(a/b);//结果为0b)0不能作为出除数c)%表示取余不仅仅可以对int求模&#xff0…

【旧文章搬运】无Device的驱动如何通信

原文发表于百度空间&#xff0c;2009-07-14 标准的驱动与ring3的通信过程是这样的&#xff1a;驱动中创建设备&#xff0c;并为设备创建符号链接&#xff0c;ring3用CreateFile打开符号链接得到设备句柄&#xff0c;然后DeviceIoControl发送ControlCodeDeviceIoControl的内容被…

[Leedcode][JAVA]第[945]题

【问题描述】 给定整数数组 A&#xff0c;每次 move 操作将会选择任意 A[i]&#xff0c;并将其递增 1。返回使 A 中的每个值都是唯一的最少操作次数。示例 1:输入&#xff1a;[1,2,2] 输出&#xff1a;1 解释&#xff1a;经过一次 move 操作&#xff0c;数组将变为 [1, 2, 3]。…

玩转oracle 11g(37):rman备份-数据库指定文件恢复

.数据库指定数据文件恢复 启动数据库的时候报错 ORA-01157: cannot identify/lock data file 5 - see DBWR trace file ORA-01110: data file 5: D:\ORACLE\PRODUCT\10.2.0\ORADATA\DOCARE\AP MEDCOMM.DBF ORA-27041: unable to open file OSD-04002: 无法打开文件 O/S-Erro…

java xpath 解析xml_使用XPATH解析XML文件

使用XPATH解析XML文件import java.util.Iterator;import java.util.List;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Node;import org.dom4j.io.SAXReader;public class TestXPath {public static void main(String[] args) throws Docum…

并发编程-concurrent指南-原子操作类-AtomicBoolean

类AtomicBoolean 可以用原子方式更新的 boolean 值。有关原子变量属性的描述&#xff0c;请参阅 java.util.concurrent.atomic 包规范。AtomicBoolean 可用在应用程序中&#xff08;如以原子方式更新的标志&#xff09;&#xff0c;但不能用于替换 Boolean。 2.构造函数 1.Atom…

[剑指offer]面试题第[7]题[JAVA][斐波那契数列][递归]

【问题描述】 大家都知道斐波那契数列&#xff0c;现在要求输入一个整数n&#xff0c;请你输出斐波那契数列的第n项&#xff08;从0开始&#xff0c;第0项为0&#xff09;。 n<39 【解答思路】 1.递归&#xff08;面试避免&#xff09; O(n^2) public class Solution {pu…

JVM 内存设置大小(Xms Xmx PermSize MaxPermSize 区别)

Eclipse崩溃&#xff0c;错误提示&#xff1a;MyEclipse has detected that less than 5% of the 64MB of Perm Gen (Non-heap memory) space remains. It is strongly recommendedthat you exit and restart MyEclipse with new virtual machine memoryparamters to increase …