易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Oracle

oracle中rownum的用法

 
rownum 真的是很好的东西,现在大多数用于存储过程分页. 但怎么用呢?这就来研究一下。 嘿嘿
--- 以下为转载之处,仅供学习
对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行数,而且rownum不能以任何表的名称作为前缀。
 举例说明:
例如表:student(学生)表,表结构为:
ID       char(6)      --学号
name    VARCHAR2(10)   --姓名
create table student (ID char(6), name VARCHAR2(100));
insert into sale values('200001',‘张一’);
insert into sale values('200002',‘王二’);
insert into sale values('200003',‘李三’);
insert into sale values('200004',‘赵四’);
commit;
(1) rownum 对于等于某值的查询条件

果希望找到学生表中第一条学生的信息,可以使用rownum=1作为条件。但是想找到学生表中第二条学生的信息,使用rownum=2结果查不到数据。因
为rownum都是从1开始,但是1以上的自然数在rownum做等于判断是时认为都是false条件, ......

Oracle学习笔记摘录1

 1.create alter insert update select等
如何建表
   学生表student
        create table student( --学生表
           xh number(4), --学号
           xm varchar2(10), --姓名
           sex char(2), --性别
           birthday date, --日期
           sal number(7,2) --奖学金
        );
   班级class
       create table class( --班级表
          classid number(2), --班级编号
          cname varchar2(20) --班级名字
       );
  添加字段(学生所在班级classid)
      ......

Oracle学习笔记摘录2

    单行函数   返回值只有一个
      
   分组函数   返回值是多条记录
      group by
      sum
      avg            
      
单行函数
  字符函数
    concat 连接  ||
   <1>显示dname和loc中间用-分隔
     select deptno,dname||'----'||loc from dept;
     
     dual哑元表   没有表需要查询的时候 可以用它
         select 'Hello World' from dual;
         select 1+1 from dual;
         查询系统时间
          select sysdate from dual;
   <2>  initcap 首字母大写
&nb ......

Oracle学习笔记摘录4

 建立表如下:
学生基本信息表
CREATE Student(
[Studentid][Int]IDENTITY(1,1)NOT NULL primary key,--主键
[StudentName][char]NOT NULL
)
课程信息表
CREATE Subject(
[SubjectID][char]NOT NULL primary key,          --主键
[SubjectName][char]NOT NULL
)
成绩表
CREATE Grade(
[Studentid][Int]NOT NULL,        --联合主键
[SubjectID][char]NOT NULL,        --联合主键
[Grade] [INT]NOT NULL,
primary key (studentid,subjectid)
)
1.将建表命令改为ORACLE语句在ORACLE中建表
create table student( --学生表
studentid number(3) primary key, --学生编号
studentname varchar2(20) --学生的姓名
);
create table subject( --课程表
subjectid char(3) primary key, --课程编号
subjectname varchar2(20)  --课程的名字
);
create table grade( --分数表
studentid number(3) references student(studentid), --学生id
subjectid char(3) references subject(subjectid), --课程id
mark     ......

Oracle学习笔记摘录5

 数据库对象
<1>表(约束)
<2>如何自动编号
SQLserver
  --IDENTITY属性
  create table test(
    xh int identity(1,2) primary key,
    name varchar(20)
);
  insert into test(name) values ('mike');
ORACLE
  一个对象(序列sequence)
  --最简单的一个序列,从1开始每次增加1,最大值38位精度10的38次方
和SQLSERVEr中的IDENTITY(1,1)类似
   create sequence seq1;
访问其中的值
  使用2个伪列 nextval,currval
    select seq1.nextval from dual;--新值
    
    select seq1.currval from dual; --当前值
 
从3开始每次增加2
  3,5,7,9
  create sequence seq2
        start with 3
        increment by 2;
从5开始每次增加5,最大值30,最小值是1
 循环序列(到最大值后回到最小值)
    5,10,15,20,25,30,1,6,11,......
  create sequence seq3
     ......

Oracle学习笔记摘录7

 用途: <1>模块化
<例子> --公司的员工的管理
         1.增加一个员工
         2.员工离职
用存储过程和函数来实现
1.增加一个员工
create sequence seq1 start with 7935;
create or replace function insert_emp(
   enm emp.ename%type,  --员工的名字
   ejob varchar2, --职务
   mgr number,   --上级
   ehiredate date,--参加工作时间
   esal number,  --工资
   ecomm number, --津贴
   dno number)         
return number
as
  a number;
begin
  --工号来自序列
  select seq1.nextval into a
  from dual;
  --增加了一个员工
  insert into emp values (
       a,enm,ejob,mgr,ehiredate,esal,ecomm,dno);
  return a;
end;              &nbs ......
总记录数:3994; 总页数:666; 每页6 条; 首页 上一页 [564] [565] [566] [567] 568 [569] [570] [571] [572] [573]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号