当前位置:首页 » 编程软件 » 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

热点内容
c语言求质因子 发布:2024-05-04 02:10:56 浏览:754
sqlserver无法启动 发布:2024-05-04 01:37:19 浏览:848
php使用正则 发布:2024-05-04 01:36:12 浏览:119
玉石密度算法 发布:2024-05-04 01:24:49 浏览:334
我的世界云服务器怎么样 发布:2024-05-04 01:20:01 浏览:22
androidsdk包含 发布:2024-05-04 00:45:54 浏览:209
android拷贝文件 发布:2024-05-04 00:38:28 浏览:777
存储冗余比 发布:2024-05-04 00:12:58 浏览:405
oracle数据库存储原理 发布:2024-05-04 00:10:40 浏览:524
未拆封玩客云3怎么搭建服务器 发布:2024-05-04 00:06:11 浏览:798