oRacle 简单操作
2012-05-18 18:41
405 查看
oracle中设置自增id字段
create sequence GDID_ID increment by 1 start with 1 nomaxvalue nocycle nocache; create or replace trigger GDID before insert on tableTest for each row declare NEXTID Integer; BEGIN IF :NEW.GDID IS NULL OR :NEW.GDID=0 THEN SELECT GDID_ID.NEXTVAL INTO NEXTID FROM SYS.DUAL; :NEW.GDID:=NEXTID; End IF; END GDID;
-------------------------------------------------------------
--表
Create table E_MAILS
(
EMAILID NUMBER not null primary key,
EMAILNAME VARCHAR(50) not null,
HOST varchar(64) not null,
PSWD varchar(64) not null);
desc E_MAILS
--序列
CREATE sequence emaid_sequence
INCREMENT BY 1
start with 1
nomaxvalue
nocycle
nocache
--触发器
create or replace trigger TRI_EMAIDS
before insert on E_MAILS
for each row
declare
-- local variables here
begin
SELECT emaid_sequence.NEXTVAL
INTO :NEW.EMAILID
FROM DUAL;
end TRI_EMAIDS;
--查看触发器
select object_name from user_objects where object_type='TRIGGER';
--看索引 index
select object_name from user_objects where object_type='INDEX';
--查看表 table
select object_name from user_objects where object_type='TABLE';
--查看序列
select count(*) from dba_sequences where sequence_owner='submail';
select * from dba_sequences;
--查看当前序列号
select emaid_sequence.currval from dual;
--游标查询
set serveroutput on
declare
v_name varchar(20);
cursor emp_c1 is select emailname
from e_mails where emailname='xianshiming';
begin
open emp_c1;
fetch emp_c1 into v_name;
DBMS_OUTPUT.PUT_LINE(v_name);
close emp_c1;
end;
--用decode函数可以避免重复扫描相同的行或重复连接相同的表
--使用DECODE函数来减少处理时间
select count(decode(username,'han01','xx',null) ) num from users where username like '%an%'
相关文章推荐
- php连接oracle及简单操作
- Oracle-简单sql语句的操作(全汇总)
- oracle学习第一天【简单操作】
- Oracle起步学习(二)---简单的数据库初始操作、用户管理
- oracle理论学习详解及各种简单操作例子(菜鸟必备)
- Oracle 11g R1 for Linux(RHEL5)安装及简单操作命令
- oracle表的简单操作步骤
- oracle之sql简单操作
- Oracle简单操作
- Oracle简单操作总结
- oracle 视图创建和操作,创建简单,复杂的视图,创建基表不存在的视图,视图增删改,查看视图的结构
- Oracle基本操作五:简单查询与简单函数,组函数,分组
- oracle 视图 创建 操作 简单 复杂 基表 不存在 增 删 改 插入 修改 删除 查看 结构
- php连接oracle及简单操作
- Java程序操作Oracle两种方式之简单实现
- oracle跨数据库简单操作
- oracle 一些简单操作
- oracle简单操作
- Oracle中对XMLType的简单操作(extract、extractvalue)(转)
- oracle简单操作