當前位置:首頁 » 編程軟體 » scott腳本

scott腳本

發布時間: 2022-02-16 04:20:35

1. linux下編寫以個shell腳本,實現對oracle資料庫抽取指定條件的數據並且保存在一個文本文件中。

empno=100不存在的,改成有的數據了。
#!/bin/bash
result=$(sqlplus -s 'scott/tiger@dbname'<<EOF
spool test.txt
set pages 0
set feed off
set heading off;
set feedback off;
set verify off;
set linesize 1000;
SELECT * FROM scott.emp where empno=7369;
spool off
EOF
)
echo $result
~
~
~
~
~
~
~
~
~
"test.sh" 14L, 256C written
oracle@****:~> ./test.sh
7369 SMITH CLERK 7902 17-DEC-80 2240.06 20
oracle@****:~> more test.txt
7369 SMITH CLERK 7902 17-DEC-80 2240.06
20

2. shell腳本:sqlplus sys/oracle@orcl as sysdba <<SQL conn scott/oracle select * from dept;鏈接報錯

系統報錯是TNS:no listener,檢查一下監聽是否正常,檢查方法運行:
tnsping orcl
如果也是報監聽錯誤的話,需要檢查一下tnsname.ora文件是否配置正確。

3. 如何使用imp show 腳本

例如將scott用戶下所有表,導入到test用戶下
1 exp scott/tiger file=scott.dmp owner=scott
2 (1) 如果test用戶下有scott的表,哪些需要先刪除在導入
conn test/test
select 'drop table 'table_name' purge;' from user_tables;
imp test/test file=scott.dmp fromuser=scott touser=test
(2) 如果test用戶下沒有scott用戶的表,可以直接導入
imp test/test file=scott乏丁催股詘噶挫拴旦莖.dmp fromuser=scott touser=test

4. shell腳本語言如何和oracle結合在一起使用

如果是通過shell腳本運行Oracle的sql語句,可以這樣寫shell腳本:
echo 「Oracle SQL Example"
sqlplus / as sysdba <<EOF
select * from scott.emp;
EOF
也就是把sql語句寫到shell腳本的EOF之間。

5. 用ORACLE語句將SCOTT用戶下的EMP表進行導出TXT格式的文件

ORACLE語句將SCOTT用戶下的EMP表並進行到處文本文件:

使用SQLPlus的spool命令
操作步驟
1. 新建一個腳本文件,存放起來,如D:spool.sql,具體代碼如下 :

setechooff--在用start命令執行一個sql腳本時,是否顯示腳本中正在執行的SQL語句
setfeedbackoff--是否顯示當前sql語句查詢或修改的行數
setnewpagenone--會在頁和頁之間沒有任何間隔
setverifyoff--
setpagesize0--分多少頁
settermoff--在用spool命令將一個大表中的內容輸出到一個文件中時,將內容輸出在屏幕上會耗費大量的時間,設置settermspooloff後,則輸出的內容只會保存在輸出文件中,不會顯示在屏幕上,極大的提高了spool的速度。
settrimson--將SPOOL輸出中每行後面多餘的空格去掉
setlinesize600--設置屏幕顯示行寬,默認100
setheadingoff--禁止輸出列標題
settimingoff--默認為OFF,設置查詢耗時,可用來估計SQL語句的執行時間,測試性能
setnumwidth38
SPOOLD:aaa.txt
selectUserTelNo||','||to_char(ReceiveTime,'yyyy-MM-ddHH24:MI:SS')||','||UserContent||','||ReplyContentFROMLogSMSHall_MutualWHERErownum<=100;
SPOOLOFF

6. 如何在winform程序中調用CS-Script 腳本 這個腳本執行操作是簡單的增刪改查 最好有代碼示例 謝謝

private static String username="scott";
private static String password="tiger";
private static String url="jdbc:oracle:thin:@192.168.1.100:1521:ORCL";
static{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();

7. 如何在shell 腳本中使用imp命令

例如將scott用戶下所有表,導入到test用戶下
1 exp scott/tiger file=scott.dmp owner=scott
2 (1) 如果test用戶下有scott的表,哪些需要先刪除在導入
conn test/test
select 'drop table '||table_name||' purge;' from user_tables;
imp test/test file=scott.dmp fromuser=scott touser=test
(2) 如果test用戶下沒有scott用戶的表,可以直接導入
imp test/test file=scott.dmp fromuser=scott touser=test

8. oracle 11g 有沒有腳本scott.sql

11g裡面是沒有scott.sql腳本的,如果你是在裝資料庫的時候沒有選裝那個例子,又想使用scott用戶,應該找utlsampl.sql這個腳本運行,運行這個腳本後會退出sqlplus,再進去就可以使用scott了。

9. sqlplus 執行腳本文件時如何傳參數

d:\test.sql腳本如下:
[sql] view plain
select &1 from &2;
exit;

執行時這樣傳參數:sqlplus "scott/tiger@test" @d:\test.sql sysdate al
注意:參數必須用&[1-9]表示,不然傳不進去,會提示讓手動輸入參數
[sql] view plain
C:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate al

D:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate al

SQL*Plus: Release 11.2.0.1.0 Proction on 星期二 11月 1 21:59:00 2011

Copyright (c) 1982, 2010, Oracle. All rights reserved.

連接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Proction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

原值 1: select &1 from &2
新值 1: select sysdate from al

SYSDATE
--------------
01-11月-11

從 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Proction
With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷


D:\>

如果腳本中有重復用到相同的值,如果&1=&2:
d:\tes2.sql
[sql] view plain
delete scott.emp where no=&1 or deptno=&2;
commit;

執行時,就必須傳2個參數:
[sql] view plain
sqlplus "scott/tiger@test" @d:\test2.sql 10 10

小竅門: 這時用procere就可以不用傳多個相同的參數,則只用傳1個參數:
d:\test3.sql
[sql] view plain
declare
var_no number:=&1;
begin
delete scott.emp where no=var_no or deptno=var_no;
commit;
end;

sqlplus "scott/tiger@test" @d:\test3.sql 10

10. 怎麼樣用shell做一個連接oracle資料庫的腳本

shell中直接調用sqlplus即可
sqlplus -s 用戶名/口令@實例名<<EOF

熱點內容
網易我的世界監獄風雲的伺服器 發布:2024-04-20 22:35:41 瀏覽:185
linux服務自動重啟 發布:2024-04-20 22:34:54 瀏覽:961
編譯器最後的結果 發布:2024-04-20 22:30:38 瀏覽:820
安裝linuxoracle11g 發布:2024-04-20 22:29:02 瀏覽:532
android設置權重 發布:2024-04-20 22:20:08 瀏覽:724
什麼手機安卓系統80 發布:2024-04-20 21:37:29 瀏覽:379
浙江萬里的伺服器地址 發布:2024-04-20 21:16:59 瀏覽:407
ndklinux下載 發布:2024-04-20 21:05:22 瀏覽:566
王者榮耀解壓資源包97 發布:2024-04-20 20:46:10 瀏覽:397
蘋果手機沒有密碼怎麼打開 發布:2024-04-20 20:45:25 瀏覽:93