Oracle(序列 视图)

来源:互联网 发布:js删除tbody中的tr 编辑:程序博客网 时间:2024/05/16 10:14
创建序列create sequence 名start with 1increment by 1如果就是自增 1 的话就直接写 create sequence 名;取值的话序列名.nextval 下一个值虚列名.currval 当前值注意:当第一次使用序列的时必须使用 序列名.nextval例如:建立序列create sequence seq_t;创建表create table a (id int, name varchar2(20));插入 insert into a values(seq_t.nextval,'Tom');

 

就是查看当前select 后的内容 视图 也就是 映射当前 物理地址的表比如说一个emp表里有14 条记录 PS:我们这里创建一个view as select * from emp where deptno=10也就是 10部分的 3条记录如果我们 修改 view 里的内容 则就是对那三条记录进行操作  这样更加安全1、创建视图create view 视图名 as 查询语句  ;这里创建的视图就是查询到的内容如果想限制view 的话 不能让你更改超出自己范围的东西则需要这样create view 视图名 as 查询语句 with check option; with read only;

 

创建索引create index idx_emp on emp(sal);建立这样的索引的话  他会自动拿出 当前字段 和 rowid  然后分别进行查找这样的话 会非常快 而且省资源create index 名 on 表名(字段名) 可以建立在多个 字段上。注意:当表中建立主键约束 和唯一性约束 会自动建立索引

 

下划线select * from t where name like '/_%'' escape '/';表TNAME--------_tomcattom_cattomcat_查询 以'_'开始 以_'结束  _'中间的三个1、select * from t where name like '%/_%' escape '/';2、select * from t where name like '%/_' escape '/';3、select * from t where ame like '_%/_%_' escape '/';

 

要求显示结果FIRST                SECOND                 RESVALUE 及格-------------------- -------------------- ---------- ------王无                 数学                         80 及格王无                 语文                         78 及格王无                 英语                         90 及格李远                 数学                         89 及格李远                 语文                         56 不及格李远                 英语                         68 及格赵家                 语文                         79 及格赵家                 英语                         90 及格张名                 数学                         88 及格三张表合并select s.name first,i.name second,resvalue from studentinfo s,itemcode i,testresult t where s.sid=t.sid and i.kid=t.kidFIRST                SECOND                 RESVALUE-------------------- -------------------- ----------王无                 数学                         80王无                 语文                         78王无                 英语                         90李远                 数学                         89李远                 语文                         56李远                 英语                         68赵家                 语文                         79赵家                 英语                         90张名                 数学                         88然后使用 case when then结果:select e.first,e.second,e.resvalue,(case when e.resvalue>60 then '及格' else '不及格' end) 及格 from (select s.name first,i.name second,resvalue from studentinfo s,itemcode i,testresult t where s.sid=t.sid and i.kid=t.kid) eFIRST                SECOND                 RESVALUE 及格-------------------- -------------------- ---------- ------王无                 数学                         80 及格王无                 语文                         78 及格王无                 英语                         90 及格李远                 数学                         89 及格李远                 语文                         56 不及格李远                 英语                         68 及格赵家                 语文                         79 及格赵家                 英语                         90 及格张名                 数学                         88 及格

 

原创粉丝点击