易截截图软件、单文件、免安装、纯绿色、仅160KB

oracle xunhuan

测试table
create table table1 (id int,name char)
insert into table1
select 1,'q'
union all select 2,'r'
union all select 3,'3'
union all select 4,'5'
要求按指定的id顺序(比如2,1,4,3)排列获取table1的数据
方法1:使用union all,但是有256条数据的限制
select id,name from table1 where id=2
union all
select id,name from table1 where id=1
union all
select id,name from table1 where id=4
union all
select id,name from table1 where id=3
方法2:在order by中使用case when
select id ,name from t where id in (2,1,4,3)
order by (case id
when 2 then 'A'
when 1 then 'B'
when 4 then 'C'
when 3 then 'D' end)
*以上两种方法适合在数据量非常小的情况下使用
方法3:使用游标和临时表
先建一个辅助表,里面你需要的顺序插入,比如2,1,4,3
create table t1(id int)
insert into t1
select 2
union all select 1
union all select 4
union all select 3
declare @id int --定义游标
declare c_test cursor for
select id from t1
select * into #tmp from table1 where 1=2 --构造临时表的结构
OPEN c_test
FETCH NEXT from c_test
INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN
--按t1中的id顺序插数据到临时表
insert into #tmp select id,name from table1 where id=@id
FETCH NEXT from c_test INTO @id
End
Close c_test
deallocate c_test
*该方法适合需要按照辅助表的顺序重排table的顺序时使用
(即辅助表已经存在的情况)
方法4:分割字符串参数
select * into #tmp from table1 where 1=2 --构造临时表的结构
declare @str varchar(300),@id varchar(300),@m int,@n int
set @str='2,1,4,3,' ---注意后面有个逗号
set @m=CHARINDEX(',',@str)
set @n=1
WHILE @m>0
BEGIN
set @id=substring(@str,@n,@m-@n)
--print @id
insert into #tmp select id,name from table1 where id=convert(int,@id)
set @n=@m+1
set @m=CHARINDEX(',',@str,@n)
END
*该方法比较有通用性
测试结果
id name
----------- ----
2 r
1 q
4 5
3 3


相关文档:

Oracle 冷拷备实例挂到新ORACLE时应注意问题。

冷拷备了一个原有数据库,要把他移植到新的数据库中时,要注意一下:
1.Oradim -new -sid [实例名:demo] -intpwd [PWD]  -pfile= [要创建实例的配置文件:*.ora]
2.set Oracle_SID=[实例名](装完后记得要在注册表里加上:HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb10g_home1:ORACLE_SID,值为实例名。)
3.sql ......

oracle中执行存储过程

创建了一oracle的定时任务,定时的将一个表中的记录插入到另一个表中,查询的时候表中竟然没数据,在pl/sql中查看建的任务发现failures的值为3,难道建的存储过程有错?运行一下存储过程试试吧,查数据库书,执行存储过程命令是:call procedure 过程名;
执行一下命令,不对?再从网上查吧,一查,oracle中执行存储过程的 ......

oracle 定时 作业 例子

sql > variable jobno  number ;
sql > begin
sql > DBMS_JOB.submit(:jobno, ' pro_name(); ' ,sysdate, ' sysdate+1 ' ); 
 dbms_job.submit(:job1, ' MYPROC; ' ,sysdate, ' sysdate+1/1440 ' );   -- 每天1440分钟,即一分钟运行test过程一次
sql > commit ;
sql > end ; ......

oracle的基本知识

练习:
  drop  table  Employee;
create  table    Employee(
                 id         number    primary key,
    ......

在oracle中临时表的种类

     临时表的概念:
在Oracle数据库中还有一种类型的表,叫做临时表。这个临时表跟永久表最大的区别就是表中的数据不会永远的存在。当一个会话结束或者事务结束的时候,这个临时表中的数据,不用用户自己删除,数据库自己会自动清除。(表是全局,只是数据消失)
      O ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号