首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > Oracle 的case when then语句、cursor游标的使用、动态组织sql语句
【标  题】:Oracle 的case when then语句、cursor游标的使用、动态组织sql语句
【关键字】:Oracle,case,when,then,cursor,sql
【来  源】:http://blog.csdn.net/jarry_hu/archive/2007/01/19/1487185.aspx

Oracle 的case when then语句、cursor游标的使用、动态组织sql语句


-- Created on 2007-1-18 by ADMINISTRATOR
declare
  -- Local variables here
  i integer;
  v_id vip_condition.vip_id %type;
  v_min vip_condition.vip_min%type;
  v_max vip_condition.vip_max%type;
 
  v_sql varchar2(5000);
  cursor cursor_c is select c.vip_id,c.vip_min,c.vip_max from vip_condition c order by c.vip_min ;
begin
  -- Test statements here
  v_sql:='select ';
  v_sql:=v_sql||'case ';
 
  open cursor_c;
  loop
      fetch cursor_c into v_id,v_min,v_max;
          v_sql:= v_sql||' when c.customer_prem>='||v_min||' and c.customer_prem<'||v_max||' then '||v_id;
      exit when cursor_c%NOTFOUND;
     
  end loop; 
  v_sql:=v_sql||' end ';
  v_sql:=v_sql||' ,c.* ';
  v_sql:=v_sql||' from vip_customer c ';
  insert into DEBUG_INFO(infor,Insertime)values(v_sql,sysdate);
  commit;
  --dbms_output.put_line(v_sql);
  close cursor_c;       
end;

 

 

 

 

 

==============================================

select * from user_all_tables t ;

create table vip_condition(
 vip_id number(20) not null,
 vip_min number(20) not null,
 vip_max number(20) not null
);

insert into vip_condition(vip_id,vip_min,vip_max)values(1,100,200);

insert into vip_condition(vip_id,vip_min,vip_max)values(2,200,300);

insert into vip_condition(vip_id,vip_min,vip_max)values(3,300,500);

select c.vip_id,c.vip_min,c.vip_max from vip_condition c;

 

drop table vip_customer;

create table vip_customer(
      
       customer_id number(10) not null,
       customer_name varchar(20) not null,
       customer_prem number(20,2) not null,
       customer_level varchar2(10)  null

);

insert into vip_customer(customer_id,customer_name,customer_prem)values(1,'Jarry',150);

insert into vip_customer(customer_id,customer_name,customer_prem)values(2,'Linda',270);

insert into vip_customer(customer_id,customer_name,customer_prem)values(3,'Kevin',180);


select
       case
            when c.customer_prem>=100 and c.customer_prem<200 then 'c=A'
            when c.customer_prem>=200 and c.customer_prem<300 then 'c=B'
            when c.customer_prem>=300 and c.customer_prem<400 then 'c=C'
            else ''
       end    ,c.*

from vip_customer c


create table DEBUG_INFO (

       infor varchar2(2000) null,
       insertime date
);

select * from DEBUG_INFO;
execute ('select count(*) from (select case  when c.customer_prem>=100 and c.customer_prem<200 then 1 when c.customer_prem>=200 and c.customer_prem<300 then 2 when c.customer_prem>=300 and c.customer_prem<500 then 3 when c.customer_prem>=300 and c.customer_prem<500 then 3 end  ,c.*  from vip_customer c )');

 

Python 流行 WEB FrameWork 之一《TurboGears快速入门》翻译:【上一篇】
GIS基本理论之三:空间数据处理理论与空间数据库:【下一篇】
【相关文章】
  • MSSQL如何获得新插入记录的ID值?
  • Myeclipse5中操作Oracle
  • 在java中处理oracle中的Index-by表类型
  • Java中使用MySQL从安装、配置到实际程序测试详解
  • java :MS-Sql 2000 数据库表转入二维容器的方法:ArrayList 和 Array
  • 用Oracle8的层次查询生成BOM树的实现方法
  • oracle RMAN快速指南
  • 用pl/sql来发邮件
  • SQL数据库管理系统的优化方案(表的主键、外键、索引设计)
  • SQL Tips:兼顾检索速度和精确性
  • 【随机文章】
  • 第一章: Jakarta Struts 项目的介绍和它的支持组件
  • 软件项目的核心风险
  • Struts 1.1 安装、示例篇
  • FTP工具32bit FTP教程
  • 利用Hosts文件防止QQ病毒
  • SMTP的基本命令及错误列表
  • 用文本+ASP打造新闻发布系统
  • 强烈推荐:销售经理的七大定理
  • windows 2003 虚拟服务器
  • Linux 网管 123 --- 第6章. 一般系统管理问题 -5.Linux 密码及 S
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.