链接远程oracle
su - oracle
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" --设置编码和数据库一致
sqlplus "qqwcrm/密码@192.168.1.111:1521/orcl"
导入dmp
imp qqwcrm151/pwd@ORCL file=/oracle/qqwcrm164.dmp ignore=y full=y log=/oracle/impqqwcrm.log
导出
exp qqwcrm151/qwd@ORCL file=/oracle/qqwcrm151_user.dmp owner=qqwcrm151 log=/oracle/expqqwcrm.log
扫描二维码关注公众号,回复:
1349645 查看本文章
![](/qrcode.jpg)
解锁表
--1、查询出被锁的情况:
SELECT OBJECT_ID,SESSION_ID,SERIAL#, ORACLE_USERNAME,OS_USER_NAME,S.PROCESS
FROM V$LOCKED_OBJECT A, V$SESSION S
WHERE A.SESSION_ID=S.SID;
--2、解锁:
alter system kill session 'sid,serial#';
--解除所有被锁的记录
alter system kill session
SELECT SESSION_ID||','||SERIAL#
FROM V$LOCKED_OBJECT A, V$SESSION S
WHERE A.SESSION_ID=S.SID;
改变编码
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter system enable restricted session;
SQL> alter system set job_queue_processes=0;
SQL> alter database open;
SQL> alter database character set internal_use UTF8;
SQL> shutdown immediate;
SQL> startup
---修改序列的当前值
declare
LastValue integer;
begin
loop
select seq_bl.currval into LastValue from dual;
exit when LastValue >= 16000 - 1;
select seq_bl.nextval into LastValue from dual;
end loop;
end;
---------------------------------------
1.创建测试用序列S
sec@ora10g> drop sequence s;
sec@ora10g> create sequence s start with 99;
Sequence created.
2.使用seq简单查看一下s的基本信息
sec@ora10g> select * from seq where SEQUENCE_NAME = 'S';
SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------- --------- ---------- ------------ - - ---------- -----------
S 1 1.0000E+27 1 N N 20 99
3.使用dbms_metadata得到序列的详细的创建语句
sec@ora10g> set linesize 150
sec@ora10g> set longchunksize 1000
sec@ora10g> select dbms_metadata.get_ddl('SEQUENCE','S') as "Create Sequence Statements" from dual;
Create Sequence Statements
------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE SEQUENCE "SEC"."S" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 99 CACHE 20 NOORDER NOCYCLE
通过上面的创建,我们得到的序列s是从99开始的。
4.在对s取nextval时,推测一下,得到的值是多少??
重要结论一:在初创建的Sequence上第一次使用nextval的时候,得到是初始值,不是初始值加一!
请看下面的演示,得到的是初始化的99值,不是100!!
sec@ora10g> select s.nextval from dual;
NEXTVAL
----------
99
如果此时再继续取nextval的话,一切恢复正常
sec@ora10g> select s.nextval from dual;
NEXTVAL
----------
100
sec@ora10g> select s.nextval from dual;
NEXTVAL
----------
101
5.新开启的session中允许直接使用currval取Sequence的当前值么?
重要结论二:第一次NEXTVAL初始化之后才能使用CURRVAL取值。
sec@ora10g> conn sec/sec
Connected.
sec@ora10g> select s.currval from dual;
select s.currval from dual
*
ERROR at line 1:
ORA-08002: sequence S.CURRVAL is not yet defined in this session
sec@ora10g> select s.nextval from dual;
NEXTVAL
----------
102
sec@ora10g> select s.currval from dual;
CURRVAL
----------
102
6.虽然上面看到currval必须在nextval之后使用,不过,可以在一条SQL语句中同时得到nextval和currval值,而且它们在SQL中不分先后顺序,请看下面的演示。
sec@ora10g> conn sec/sec
Connected.
sec@ora10g> select s.currval from dual;
select s.currval from dual
*
ERROR at line 1:
ORA-08002: sequence S.CURRVAL is not yet defined in this session
sec@ora10g> select s.currval, s.nextval from dual;
CURRVAL NEXTVAL
---------- ----------
103 103
sec@ora10g> conn sec/sec
Connected.
sec@ora10g> select s.currval from dual;
select s.currval from dual
*
ERROR at line 1:
ORA-08002: sequence S.CURRVAL is not yet defined in this session
sec@ora10g> select s.nextval, s.currval from dual;
NEXTVAL CURRVAL
---------- ----------
104 104
7.将Oracle 10gR2官方文档关于序列的create和alter的命令语法copy一份在此,便于参考
CREATE SEQUENCE [ schema. ]sequence
[ { INCREMENT BY | START WITH } integer
| { MAXVALUE integer | NOMAXVALUE }
| { MINVALUE integer | NOMINVALUE }
| { CYCLE | NOCYCLE }
| { CACHE integer | NOCACHE }
| { ORDER | NOORDER }
]
[ { INCREMENT BY | START WITH } integer
| { MAXVALUE integer | NOMAXVALUE }
| { MINVALUE integer | NOMINVALUE }
| { CYCLE | NOCYCLE }
| { CACHE integer | NOCACHE }
| { ORDER | NOORDER }
]... ;
ALTER SEQUENCE [ schema. ]sequence
{ INCREMENT BY integer
| { MAXVALUE integer | NOMAXVALUE }
| { MINVALUE integer | NOMINVALUE }
| { CYCLE | NOCYCLE }
| { CACHE integer | NOCACHE }
| { ORDER | NOORDER }
}
[ INCREMENT BY integer
| { MAXVALUE integer | NOMAXVALUE }
| { MINVALUE integer | NOMINVALUE }
| { CYCLE | NOCYCLE }
| { CACHE integer | NOCACHE }
| { ORDER | NOORDER }
]... ;
8.小结
通过这个小实验,得到的结论有:
1)结论一:在初创建的Sequence上第一次使用nextval的时候,得到是初始值,不是初始值加一!
2)结论二:第一次NEXTVAL初始化之后才能使用CURRVAL取值;
3)结论三:可以在一条SQL语句中同时得到nextval和currval值;
4)结论四:从上面的alter sequence的语法看,可以得到这样一个结论,无法使用alter语句修改序列的当前值。
很有必要重点关注以上这些结论,尤其是第一条。
-- The End --