最近项目中用到,现记录一下:
/*添加主键*/
alter table shop_spec_detail add constraint spec_detail_id primary key(id);
/*添加索引*/
create index spec_detail_id on shop_spec_detail(id);
/*给表字段添加注释*/
COMMENT ON COLUMN shop_spec_detail.id IS '规格详情ID';
/*varchar2字段修改为clob类型 分两步走*/
alter table shop_spec_detail modify title_value varchar2(4000)
alter table shop_spec_detail modify title clob
/*clob字段修改为varchar2字段,分三步走*/
alter table shop_spec_detail add (title2 varchar2(100));
alter table shop_spec_detail drop (title);
alter table shop_spec_detail rename column title2 to title;
/*以下部分涉及到oracle正则表达式的*/
/*删除字段中包含数字的字段*/
delete from shop_spec_detail where regexp_like(title,'^([a-z]+|[0-9]+)$');
/*查询出字段中包含空格的字段*/
select * from shop_spec_detail where regexp_like(title,'[[:space:]]');
/*查询字段中包含标点符号的字段*/
select * from shop_spec_detail where regexp_like(title,'[[:punct:]]') for update
/*把字段中(2)替换成一个换行再加上一个(2)*/
update shop_spec_detail_3 set title_value = REPLACE(title_value, '(2)',chr(10)||'(2)');
/*创建用户及表空间*/
CREATE USER 用户名 IDENTIFIED BY 密码 DEFAULT TABLESPACE 表空间名 TEMPORARY TABLESPACE 临时表空间名 ACCOUNT UNLOCK;
GRANT CONNECT TO 用户名; 连接数据库
GRANT RESOURCE TO 用户名;
GRANT ALTER,DELETE,UPDATE,INSERT,SELECT ON 表名 TO 用户名;
/*示例*/
CREATE USER tomcatx IDENTIFIED BY 123456 DEFAULT TABLESPACE 表空间名 TEMPORARY TABLESPACE 临时表空间名 ACCOUNT UNLOCK;
GRANT DBA TO tomcatx;
/*-----查询是否锁定------*/
SELECT s.username,decode(l.type,'TM','TABLELOCK','TX','ROW LOCK',NULL) LOCK_LEVEL,o.owner,o.object_name,o.object_type,s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser
FROM v$session s,v$lock l,dba_objects o
WHERE l.sid = s.sid
AND l.id1 = o.object_id(+)
AND s.username is NOT Null
/*锁定了就kill*/
alter system kill session '44,2341';
sid:44,
serid:2341