31.1:(若用程序調用cmd,則在備份和還原 末尾語句加上 2>&1 ,直接運行則不須要加)sql
--備份:
1) exp SA/"""abc@1234"""@192.168.31.1:1521/DB1 buffer=10240000 file=C:\bak\data_back.dmp log=C:\bak\data_bak_explog.txt owner=(sa,user1) 2>&1
--還原:還原前先執行刪除,後執行還原
1) sqlplus sa/"""abc@1234"""@192.168.31.1:1521/DB1 @C:\bak\deleteDBObjects.txt
2) imp SA/"""abc@1234"""@192.168.31.1:1521/DB1 file=C:\bak\data_back.dmp full=y ignore=y 2>&1async
deleteDBObjects.txt內容:
declare vsql varchar2(2000);
begin
--刪除表
BEGIN
for i in (select 'drop table '||owner||'.'||table_name||' cascade constraints' v_name
from dba_tables where owner='SA' or owner='user1')
loop
vsql:=i.v_name;
--dbms_output.put_line(vsql);
execute immediate vsql;
end loop;
end;函數
--刪除過程和函數
BEGIN
for i in (select 'drop '|| object_type||' '||owner||'.' || object_name||'' v_name
from dba_objects where (object_type='PROCEDURE' or object_type='FUNCTION' or object_type='PACKAGE') and (owner='SA' or owner='user1')
)
loop
vsql:=i.v_name;
--dbms_output.put_line(vsql);
execute immediate vsql;
end loop;
end;
end;
/
exit;oop
相關代碼以下:ui
public async void ExecuteCmd()
{
try
{
Process[] MyProcess = Process.GetProcessesByName("exp");//獲取已經存在的exp.exe和imp.exe進程
MyProcess.ToList().AddRange(Process.GetProcessesByName("imp"));
if (MyProcess.Length != 0)
{
for (int i = 0; i < MyProcess.Length; i++)
{
MyProcess[i].Kill();//關閉已存在的進程
MyProcess[i].Dispose();
}
}this
string cmd = txtInput.Text;// strInput;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";// @"D:\MyOracle\Oracle11g\product\11.2.0\dbhome_1\BIN\exp.exe";
//啓用操做系統外殼程序執行
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;操作系統
p.OutputDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);orm
p.Start(); //設置自動刷新緩衝並更新
//p.StandardInput.AutoFlush = true; //寫入命令
p.StandardInput.AutoFlush = true; //寫入命令
p.StandardInput.WriteLine(cmd); //p.StandardInput.WriteLine(strInput);
p.StandardInput.WriteLine("exit"); //等待結束 blog
p.BeginOutputReadLine();
p.WaitForExit();進程
}
catch (Exception ex)
{
}
}
delegate void AsynUpdateUI(string msg);
private void UpdataUIStatus(string msg)
{
if (InvokeRequired)
{
this.Invoke(new AsynUpdateUI(delegate (string argMsg)
{
txtShow.AppendText(argMsg + Environment.NewLine);
}), msg);
}
else
{
txtShow.AppendText(msg + Environment.NewLine);
}
}
private void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string x = e.Data.ToString();
UpdataUIStatus(x);
}
}
private void btnBAKUP_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(this.ExecuteCmd));
t.Start();
}