MDA/MDD/TDD/DDD/DDDDDDD
posts - 536, comments - 111, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

oracle TIPS

Posted on 2007-07-15 03:15 leekiang 阅读(602) 评论(0)  编辑  收藏 所属分类: oracle

1,"&"有时候不认,则改为"&"

   但在执行insert操作或update操作时如果sql语句中含"&",如何处理?

        1) update userinfo set pageurl='myjsp?page=1'||'&'||'pagesize=10' where id='test'         2) update userinfo set pageurl='myjsp?page=1'||chr(38)||'pagesize=10' where id='test'其中||是连字符, chr(38)跟ASCII的字符转码是一致的。plsql中还可以set define off来关闭特殊字符,还可以用show define来查看有些特殊定义的字符


2,慎用where pid!=3等用法,这样没有囊括is null的情况,要实现同样目的可where pid!=3 or pid is null
3,快速从另外一个表复制数据
  insert into tablea (id,name) select id,name from tableb
4,查版本
  select * from PRODUCT_COMPONENT_VERSION;或 select * from v$version;
5,nls==National   Language   Support   国际语言支持
6,PLSQL
  HKEY_CURRENT_USER\Software\Allround Automations
  HKEY_CURRENT_USER\Software\Microsoft\Security
7,查blob大小
  select dbms_lob.getlength(blobfield) from wd_blob
8,改变表空间
  alter table TB_USER move tablespace myspace;
  如果被转移表空间的表含有索引, 表转移后索引变得不可用. 要删除旧索引,建立新索引
  alter index user_name.index_name rebuild; 主键索引名与主键名相同
9,导入时表空间错误
  导出dmp时的用户的默认表空间必须是表所在的表空间,这样导入时才不会出错。
  如果dmp小,也可用UE打开直接修改表空间。

10,用select into 复制数据
insert into test
  (id, name)
  select id, name from mis@dblink;
  或
  create table test--需先删表
as (select * from mis@dblink)

11,中文字段按拼音排序:
select username from tab_name order by nlssort(username,'nls_sort=schinese_pinyin_m');
按偏旁部首:
select username from tab_name order by nlssort(username,'nls_sort=schinese_radical_m');
按笔画:
select username from tab_name order by nlssort(username,'nls_sort=schinese_stroke_m');

12,插入带单引号的字符

insert into t(a) values ('a'||chr(39)||'b' );
或insert into t(a) varlus ('a''b');

13,如果你连接到数据库后没有在取nextval之后再取currval,就会出现ORA-08002出错.  
  因此对每一个session来说,应该先用nextval,才可以取currval。

14

truncate table mapevent时,如果建了外键引用(外键所在那张表不一定有数据,有数据就会报另外一个错误了)
则报 ORA-02266:表中的唯一主键被启用的外部关键字引用
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
(外键所在那张表无数据时delete from table mapevent是可以执行的)
正确的步骤:
----------------
alter table mapevent disable primary key cascade;
truncate table mapevent;
alter table mapevent enable primary key;
---------------

15
查询某个表被哪些表引用
select *
  from user_constraints t
 where t.constraint_type = 'R'
   and t.r_constraint_name = '该表的主键名';

16,按中文排序,但中文的一二三四五有问题,可用下面的办法:

select * from T_TIME_SETUP order by translate(ccname,'一二三四五','12345')

来源:http://www.itpub.net/226375,1.html

17,误删了怎么办?用Oracle中的回闪查询

查20分钟前的数据:

 select * from tb_wz as of timestamp(sysdate - 20 / 1440)

  http://blog.csdn.net/xuyuan77/archive/2007/06/06/1640757.aspx

18,导出带有blobh或clob类型字段表时会出现:EXP-00003: 未找到段 (8,375419) 的存储定义
 原因见http://read.newbooks.com.cn/info/116619.html

19,导出命令

exp Test1/Test1passwd@服务名 owner=Test1 file=D:\files\Test1.dmp log=d:\log.log

exp还有一个参数full=y

imp aichannel/aichannel@HUST full=y  file=test.dmp ignore=y

20,查oracle的保留字 select * from v$reserved_words

21,修改序列的当前值

alter sequence userseq increment by 500;
 select userseq.nextval from dual;
alter sequence userseq increment by 1;


22,序列跳20号
create sequence ORA_SEQ
minvalue 100000000000
maxvalue 999999999999
start with 100000000260
increment by 1
cache 20
如果设置了cache 20,数据库关闭时这20个序列成员会丢失,造成序列不连续的现象。
序列设置nocache模式即可
http://topic.csdn.net/u/20090421/20/7edde8ab-dbcc-4765-b9b9-a7fae3d2af39.html
绝不能跳号的序列号设计问题 http://www.itpub.net/viewthread.php?tid=403149

23,用9i的OEM去连10g,如果是普通用户登录,就会报
你必须具有select any dictionary权限才能运行此应用程序,请要求DBA为你赋予此权限
 这是是9I的OEM在连接10G的数据库的时候的一个BUG,目前没有解决办法。
http://www.itpub.net/thread-888007-1-1.html

24,可用其他dba用户修改system用户的密码

25,查看oracle最大连接数
show parameter processes
show parameter sessions
一个session对应一个process,但是一个process未必对应一个session
SELECT * FROM v$process p
 WHERE NOT EXISTS (SELECT 1 FROM v$session WHERE p.paddr = p.addr);
 alter system set sessions=300 scope=spfile;需重启

v$resource_limit视图各字段的含义
current_utilization   -   Number   of   (resources,   locks,   or   processes)   currently
being   used

max_utization   -   Maximum   consumption   of   the   resource   since   the   last
instance   start   up 自从上次启动以来的最大值

initial_allocation   -   Initial   allocation.   This   will   be   equal   to   the   value
specified   for   the   resource   in   the   initialization   parameter
file   (UNLIMITED   for   infinite   allocation)

limit_value   -   Unlimited   for   resources   and   locks.   This   can   be   greater
than   the   initial   allocation   value   (UNLIMITED   for   infinite
limit).

26,
IMP-00003: 遇到 ORACLE 错误 959
ORA-00959: 表空间'TBS_BSS'不存在
这种类型的错误往往是因为表上有大字段,而大字段所在的表空间不存在。普通字段是可以导到不同名的表空间的。

27,
alter table USERS add  primary key (userid);//不好,会自动生成约束名,不利于移植数据
alter table USERS  add  constraint PK_USERS  primary key (userid);//ok.外键也是如此。

28,
INTERSECT 操作符用来返回两个查询中都存在的记录,即返回两个查询结果的交集,前提是两个查询的列的数量和数据类型必须完全相同。



只有注册用户登录后才能发表评论。


网站导航: