資料庫匯出xml htm csv sql

2021-03-31 08:56:28 字數 3798 閱讀 7215

<%

'資料庫匯出記錄**

'作者海娃,haiwa#blueidea.***,http://.51windows.***

'用法:

'exportdb.asp?sql=select語句&tablename=表名(可選)&filetype=匯出格式(xml,htm,csv,sql)&pid=自動編號欄位名(僅當匯出sql型別時有用)

dim tablename,filetype,fieldpid

sql???= request("sql")

tablename?= request("tablename")

filetype?= lcase(request("filetype"))

fieldpid?= request("pid")

if fieldpid = "" then

?fieldpid = "id"

end if

fieldpid = lcase(fieldpid)

if lcase(left(sql,6))<>"select" then

?response.write "sql語句必須為select * from [table] where ......."

?response.end

end if

if tablename = "" then

?tablename = "資料匯出結果"

end if

function htmlencode(fstring)

?if not isnull(fstring) then

??fstring = server.htmlencode(fstring)

??fstring = replace(fstring, chr(10) & chr(10), "

")??fstring = replace(fstring, chr(10), "

")??fstring = replace(fstring, chr(9), "  ")

??htmlencode = fstring

?end if

end function

function myreplace(str)

?if not isnull(str) then

??fstring = replace(fstring,"""", """""")

??myreplace = str

?else

??myreplace = ""

?end if

end function

function myreplace2(str)

?if not isnull(str) then

??fstring = replace(fstring,"'", "''")

??myreplace2 = str

?else

??myreplace2 = ""

?end if

end function

dim def_export_sep,def_export_val

def_export_sep = ","

def_export_val = """"

set rs = conn.execute(sql)

'匯出xml檔案

if filetype="xml" then

?response.contenttype="text/xml"

?response.charset = "gb2312"

?response.addheader "content-disposition", "attachment;filename="&tablename&".xml"

?response.write "

" & vbnewline

?response.write "

"

?strline=""

?dim thefield(50)

?i = 0

?for? each? x? in? rs.fields

??thefield(i)=x.name

??i=i+1

?next

?while rs.eof =false

?strline= vbnewline&chr(9)&"

"

?k=0

?for? each? x? in? rs.fields

??strline=? strline & vbnewline&chr(9)&chr(9)&"<"&thefield(k)&">"

??if instr(x.value,"<")>0 or instr(x.value,">")>0 or instr(x.value,"&")>0 or len(x.value)>255 then

???strline=? strline &""

??else

???strline=? strline & x.value

??end if

??strline=? strline &"

"

??k=k+1

?next

?rs.movenext

?response.write strline &vbnewline& chr(9)&"

"

?wend

response.write vbnewline&"

"匯出資料 - .51windows.***>

?

<%i=0?for? each? x? in? rs.fields? ??strline=? strline? &chr(9)&chr(9)&"

"&? x.name? &"

"& vbnewline?next?response.write strline&chr(9)&"

"& vbnewline & vbnewline?while rs.eof =false??i=i+1??response.write chr(9)&"

"& vbnewline??strline= ""??for? each? x? in? rs.fields ???strline=? strline? &chr(9)&chr(9)&"

"&? htmlencode(x.value) &"

"& vbnewline??next??rs.movenext??response.write strline??response.write chr(9)&"

"& vbnewline & vbnewline?wendresponse.write "

"& vbnewline

if filetype<>"htm" and filetype<>"xls" and filetype<>"sql" then

response.write "

"&i&"條記錄 匯出html"

response.write "|匯出excel"

response.write "|匯出xml"

response.write "|匯出sql"& vbnewline

匯出資料庫

exp 引數例項 匯出整個例項 exp wjh orcl file wjh.dmp log wjh.log full y consistent y direct y wjh應具有dba許可權 匯出某個使用者所有物件 exp wjh orcl file wjh.dmp log wjh.log owne...

MySQL匯出匯出資料庫

預設匯出路徑為mysql的內建路徑,因此這裡都加上了 documents 作為路徑。匯出整個資料庫 mysqldump u root p test documents test.sql 匯出資料庫一個表 mysqldump h hostname u username p password datab...

搭建資料庫 匯出匯入資料庫

二 零碎知識 三 遇到的問題 expdp test source a123456 例項名 directory dump dir1 dumpfile test source.dmp schemas test source logfile test source.logexpdp test source...

資料匯出Excel表 資料庫資料匯出

public static hashmapcolumn new hashmap static param table 要匯出的表 param name 匯出的excel表名稱 表頭 throws exception public void createexcel string table,strin...

mysql匯出資料庫

mysql命令列匯出資料庫 1,進入mysql目錄下的bin資料夾 cd mysql中到bin資料夾的目錄 如我輸入的命令列 cd c program files mysql mysql server 4.1 bin 或者直接將windows的環境變數path中新增該目錄 2,匯出資料庫 mysql...