断点

每天进步一点点!
posts - 174, comments - 56, trackbacks - 0, articles - 21

--情况1:多个参数的传递,由于多个文件编码不一致,可能出现乱码。

window.open(base+"/policy/universal/pop/flat_vhl_inf_query.jsp?

cLcnNo="+objPlateNo.value+"&cEngNo="+objEngNo.value+"&cVhlFrm="+objFrmNo.value+"&cPlateTy

p="+objPlateTyp+"&cProdNo="+objCProdNo+"&cDptCde="+objCDptCde+"&cNewMrk="+objNewMrk.value

+"&cEcdemicMrk="+objEcdemicMrk.value,"","scrollbars=yes,left=100,top=150,Toolbar=no,Locat

ion=no,Direction=no,Resizeable=no,Width="+800+" ,Height="+400);


--相应的jsp获得参数
<% 
 String CProdNo = request.getParameter("prodNo");
 String CDptCde = request.getParameter("dptCde");

 String CPlateNo = request.getParameter("plateNo");

 String CFrmNo = request.getParameter("frmNo");
 
 if("".equals(CPlateNo)&&"".equals(CFrmNo)){
  return;
 }
     
 String dwName = "policy.pub.flat_vhl_inf_DW";
%>


--情况2:解决乱码的问题。
function tool_uploadFile(clmNo,billType,maxFileNum,fileType,singleLimit,totalLimit) {//解决乱码的问题,增加变量paramObj。ztf 10.06.01
 var paramObj = {
  "clmNo" : clmNo,
  "billType" : billType,
  "maxFileNum" : maxFileNum,
  "fileType" : fileType,
  "singleLimit" : singleLimit,
  "totalLimit" : totalLimit
 };
 var r = window.showModalDialog(global.WEB_APP_NAME+"/core/jsp/common/uploadFile.jsp",paramObj,"dialogHeight:610px;dialogWidth:530px;center:1;help: 0; status: 0;");

 return r;
}

--在相应的jsp页面通过js获得参数:
<html>
  <head>
    <title>文件上传</title>
  </head>
  <script type="text/javascript" src="<%=webApp%>/core/js/core/Tool.js"></script>
  <body bgcolor="#85b7ec">
 
  <script>
 var paramObj = window.dialogArguments;
 var clmNo = paramObj.clmNo;
 var billType = paramObj.billType;
 var maxFileNum = paramObj.maxFileNum;
 var fileType = paramObj.fileType;
 var singleLimit = paramObj.singleLimit;
 var totalLimit = paramObj.totalLimit;
 tool.loadApplet('<%=agentIp%>','<%=agentPort%>','<%=orgId%
>',clmNo,billType,maxFileNum,fileType,singleLimit,totalLimit);
  </script>

</body>
</html>


vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])

posted @ 2010-07-24 16:57 断点 阅读(331) | 评论 (0)编辑 收藏

1、具体业务中用到的sql,这个是查找最近标志为1,且有多条记录的数据。 (这个sql查找错误比较有用。)
select a.c_ply_no ,count(1) from web_ply_base a
where  a.c_latest_mrk='1'
group by  a.c_ply_no
having count(1)>1

 

背景count(*)   count(1)   两者比较,主要还是要count(1)所相对应的数据字段:
 
如果你的数据表没有主键,那么count(1)比count(*)快  
  如果有主键的话,那主键(联合主键)作为count的条件也比count(*)要快  
  如果你的表只有一个字段的话那count(*)就是最快的啦
  如果count(1)是聚索引,id,那肯定是count(1)快。但是差的很小的。  
  因为count(*),自动会优化指定到那一个字段。所以没必要去count(?),用count(*),sql会帮你完成
优化的.
其他语句:select * from 表名 where 条件 order by 字段名 asc\desc     // asc 升序    desc  降序

2、C_Nme_En匹配多个 like 查询。
select distinct C_Spec_No
  from WEB_Prd_Fix_Spec
 WHERE C_Spec_No in (SELECT C_Spec_No
                       FROM web_Prd_Prod_Spec_Rel
                      WHERE C_Prod_No = '0326'
                        and C_Spec_No like '89%')
   and (C_Nme_En like '%000000%' or C_Nme_En like '%030006%' or
       C_Nme_En like '%030061%')

posted @ 2010-07-24 16:42 断点 阅读(270) | 评论 (0)编辑 收藏

--递归,树状结构的存储与展示
drop table article;
create table article
(
id number primary key,
count varchar2(4000),
pid number,
isleaf number(1), --0 代表非叶子节点,1代表叶子节点
alevel number(2)
);

insert into article values(1,'蚂蚁大战大象',0,0,0);
insert into article values(2,'大象被打趴下',1,0,1);
insert into article values(3,'蚂蚁也不好过',2,1,2);
insert into article values(4,'瞎说',2,0,2);
insert into article values(5,'没有瞎说',4,1,3);
insert into article values(6,'怎么可能',1,0,1);
insert into article values(7,'怎么没有可能',6,1,2);
insert into article values(8,'可能性是很大的',6,1,2);
insert into article values(9,'大象进医院了',2,0,2);
insert into article values(10,'护士是蚂蚁',9,1,3);
commit;

蚂蚁大战大象
    大象被打趴下了
        蚂蚁也不好过
        瞎说
            没有瞎说
        大象进医院了
            护士是蚂蚁
    怎么可能
        怎么没有可能
        可能性是很大的
 

--用存储过程展现树状结构。
create or replace procedure p(v_pid article.pid%type,v_level binary_integer) is
  cursor c is select * from article where pid = v_pid;
  v_preStr varchar2(1024) := '';
begin
  for i in 0..v_level loop
    v_preStr := v_preStr || '****';
  end loop;

  for v_article in c loop
    dbms_output.put_line(v_preStr ||v_article.cont);
    if(v_article.isleaf=0) then
       p(v_artile.id,v_levle +1);
    end if;
  end loop;
end;

posted @ 2010-07-24 16:25 断点 阅读(250) | 评论 (0)编辑 收藏

--触发器
create table emp2_log
(
uname varchar2(20);
action varchar2(10);
atime date
);

create or replace trigger trig
  after insert or delete or update on emp2 for each row
begin
  if inserting then
     insert into emp2_log values (USER,'insert',sysdate); --USER关键字,用户。
  elsif updating then
     insert into emp2_log values (USER,'update',sysdate);
  elsif deleting then
     insert into emp2_log values (USER,'delete',sysdate);
  end if;
end;

update emp2 set sal = sal*2 where deptno = 30;
select * from emp2_log;

drop trigger trig;

--直接执行时,出现违反完整约束条件,已找到子记录。
update dept set deptno = 99 where deptno = 10;

--使用下面的,把子表一起更新。
create or replace trigger trig
  after update on dept for each row
begin
  update emp set deptno =:NEW.deptno where deptno =:OLD.deptno;
end;

update dept set deptno = 99 where deptno = 10;

select * from emp;
rollback;

posted @ 2010-07-24 16:22 断点 阅读(285) | 评论 (0)编辑 收藏

--函数
create or replace function sal_tax
   (v_sal number)
   return number
is
begin
  if(v_sal < 2000) then
    return 0.10;
  elsif(v_sal < 2750) then
    return 0.15;
  else
    return 0.20;
  end if;
end;

数据库定义的函数money_to_chinese ,把数字转换正中文输出。
create or replace function money_to_chinese(money in VARCHAR2)
   return varchar2 is
     c_money   VARCHAR2(12);
     m_string VARCHAR2(60) := '分角圆拾佰仟万拾佰仟亿';
     n_string VARCHAR2(40) := '壹贰叁肆伍陆柒捌玖';
     b_string VARCHAR2(80);
     n         CHAR;
     len       NUMBER(3);
     i         NUMBER(3);
     tmp       NUMBER(12);
     is_zero   BOOLEAN;
     z_count   NUMBER(3);
     l_money   NUMBER;
     l_sign    VARCHAR2(10);

   BEGIN
     l_money := abs(money);
     IF money < 0 THEN
       l_sign := '负' ;
     ELSE
       l_sign := '';
     END IF;
     tmp      := round(l_money, 2) * 100;
     c_money := rtrim(ltrim(to_char(tmp, '999999999999')));
     len      := length(c_money);
     is_zero := TRUE;
     z_count := 0;
     i        := 0;
     WHILE i < len LOOP
       i := i + 1;
       n := substr(c_money, i, 1);
       IF n = '0' THEN
         IF len - i = 6 OR len - i = 2 OR len = i THEN
           IF is_zero THEN
             b_string := substr(b_string, 1, length(b_string) - 1);
             is_zero   := FALSE;
           END IF;
           IF len - i = 6 THEN
             b_string := b_string || '万';
           END IF;
           IF len - i = 2 THEN
             b_string := b_string || '圆';
           END IF;
           IF len = i THEN
              IF (len = 1) THEN
                 b_string := '零圆整';
              ELSE
                 b_string := b_string || '整';
              END IF;
           END IF;
           z_count := 0;
         ELSE
           IF z_count = 0 THEN
             b_string := b_string || '零';
             is_zero   := TRUE;
           END IF;
           z_count := z_count + 1;
         END IF;
       ELSE
         b_string := b_string || substr(n_string, to_number(n), 1) ||
                     substr(m_string, len - i + 1, 1);
         z_count   := 0;
         is_zero   := FALSE;
       END IF;
     END LOOP;
     b_string := l_sign || b_string ;
     RETURN b_string;
exception
   --异常处理
    WHEN OTHERS THEN
       RETURN(SQLERRM);
END;

posted @ 2010-07-24 16:19 断点 阅读(291) | 评论 (0)编辑 收藏

--创建存储过程:
create or replace procedure p
is
  cursor c is
  select * from emp2 for update;
begin
  for v_temp in c loop 
    if(v_temp.deptno = 10) then
      update emp2 set sal = sal+10 where current of c;
    elsif(v_temp.deptno = 20) then
      update emp2 set sal = sal+20 where current of c;
    else
       update emp2 set sal = sal+50 where current of c;
    end if;
  end loop;
  commit;
end;

--执行:
exec p;

begin
p;
end;


--带参数的存储过程,in传入参数,默认为传入,out传出。
create or replace procedure p
   (v_a in number,v_b number,v_ret out number,v_temp in out number)
is
begin
  if(v_a >v_b) then
    v_ret := v_a;
  else
    v_ret := v_b;
  end if;
  v_temp :=v_temp +1;
end;

declare
  v_a number := 3;
  v_b number := 4;
  v_ret number;
  v_temp number := 5;
begin
  p(v_a,v_b,v_ret,v_temp);
  dbms_output.put_line(v_ret);
  dbms_output.put_line(v_temp);
end;

posted @ 2010-07-24 16:17 断点 阅读(246) | 评论 (0)编辑 收藏

--游标
declare
  cursor c is
    select * from emp;
  v_emp c%rowtype;
begin
  open c;
  loop
    fetch c into v_emp;
    exit when(c%notfound);
    dbms_output.put_line(v_emp.ename);
  end loop;
  close c;
end;

declare
  cursor c is
    select * from emp;
  v_emp emp%rowtype;
begin
  open c;
  fetch c into v_emp;
    while(c%found) loop
      dbms_output.put_line(v_emp.ename);
      fetch c into v_emp;
      --fetch c into v_emp; 导致第一条没有打印,最后一条打印2遍。
      --dbms_output.put_line(v_emp.ename);
  end loop;
  close c;
end;


declare
  cursor c is
    select * from emp;
begin
  for v_emp in c loop
    dbms_output.put_line(v_emp.ename);
  end loop;
end;


--带参数的游标
declare
  cursor c(v_deptno emp.deptno%type,v_job emp.job%type)
  is
    select ename,sal from emp where deptno =v_deptno and job= v_job;
    --v_temp c%rowtype;
begin
  for v_temp in c(30,'CLERK') loop  --for自动打开游标。
    dbms_output.put_line(v_temp.ename);
  end loop;
end;


--可更新的游标
declare
  cursor c
  is
    select * from emp2 for update;
    --v_temp c%rowtype;
begin
  for v_temp in c loop 
    if(v_temp.sal <2000) then
      update emp2 set sal = sal*2 where current of c;
    elsif(v_temp.sal = 5000) then
      delete from emp2 where current of c;
    end if;
  end loop;
  commit;
end;

posted @ 2010-07-24 16:14 断点 阅读(236) | 评论 (0)编辑 收藏

PLSql是SQL的补充,PL过程语言procedure language,SQL:Structured Query Language。
PLSql    带有分支、循环的语言,SQL没有分支、循环的语言。

set serveroutput on;

-- 简单的PL/SQL语句块
declare
 v_name varchar2(20);
begin
  v_name :='myname';
  dbms_output.put_line(v_name);
end;
/


--语句块的组成
declare
 v_num number := 0 ;
begin
  v_num := 2/v_num;
  dbms_output.put_line(v_num);
exception
  when others then
     dbms_output.put_line('error');

end;
/

--变量声明的规则
1、变量名不能够使用保留字,如from、select等
2、第一个字符必须是字母
3、变量名最多包含30个字符
4、不要与数据库的表或者列同名
5、每一行只能声明一个变量


--常用变量类型
1、binary_integer:整数,主要用来计数而不是用来表示字段类型
2、number:数字类型
3、char:定长字符串
4、varchar2:变长字符串
5、date:日期
6、long:长字符串,最长2GB
7、boolean:布尔类型,可以取值true、false和null值


--变量声明
declare
  v_temp number(1);
  v_count binary_integer :=0;
  v_sal number(7,2):= 4000.00;
  v_date date:= sysdate;
  v_pi constant number(3,2) := 3.14;  --constant相当java的final常量
  v_valid boolean := false;
  v_name varchar2(20) not null :='MyName';
begin
  dbms_output.put_line('v_temp value:'|| v_temp);
end;
 

--变量声明,使用%type属性
declare
  v_empno number(4);
  v_empno2 emp.empno%type;
  v_empno3 v_empno2%type;
begin
  dbms_output.put_line('Test');
end;


--简单变量赋值
declare
  v_name varchar2(20);
  v_sal number(7,2);
  v_sal2 number(7,2);
  v_valid boolean :=false;
  v_date date;
begin
  va_name :='MyName';
  v_sal :=23.77;
  v_sal2 :=23.77;
  v_valid:=(v_sal = v_sal2);
  v_date:=to_date('1999-08-12 12:23:38','YYYY-MM-DD HH24:MI:SS');  
end;


--Table变量类型,定义一种新的类型,是数组。
declare
  type type_table_emp_empno is table of emp.empno%type index by binary_integer;
  v_empno type_table_emp_empno;
begin
  v_empnos(0) := 7369;
  v_empnos(2) := 7839;
  v_empnos(-1) := 9999;
  dbms_output.put_line(v_empnos(-1));
end;


--Record变量类型,类似java的类的概念。
declare
  type type_record_dept is record
  (
    deptno dept.deptno%type,
    dname dept.dname%type,
    loc dept.loc%type
  );
  v_tmp type_record_dept;
begin
  v_tmp.deptno := 50;
  v_tmp.dname := 'aaaa';
  v_tmp.loc := 'bj';
  dbms_output.put_line(v_temp.deptno||''||v_temp.dname);
end;


--使用%rowtype声明Record变量
declare
  v_temp dept%rowtype;
begin
  v_tmp.deptno := 50;
  v_tmp.dname := 'aaaa';
  v_tmp.loc := 'bj';
  dbms_output.put_line(v_temp.deptno||''||v_temp.dname);
end;


--SQL语句的运用,返回数据有且只有一条记录。
declare
  v_ename emp.ename%type;
  v_sal emp.sal%type;
begin
  select ename,sal into v_ename,v_sal from emp where empno = 7369;
  dbms_output.put_line(v_ename||''||v_sal);
end;

declare
  v_emp emp%rowtype;
begin
  select * into v_emp from emp where empno = 7369;
  dbms_output.put_line(v_emp.ename);
end;

declare
   v_deptno dept.deptno%type := 50;
   v_dname dept.dname%type := 'aaaa';
   v_loc dept.loc%type := 'bj';
begin
  insert into dept2 values (v_deptno,v_dname,v_loc);
  commit;
end;

declare
  v_deptno emp2.deptno%type := 10;
  v_count number ;
begin
  --update emp2 set sal = sal/2 where deptno = v_deptno;
  --select deptno into v_deptno from emp2 where empno = 7369;
  select count(*) into v_count from emp2;
  dbms_output.put_line(sql%rowcount||'条记录被影响');
  commit;
end;


DDL语句:
begin
  execute immediate 'create table T(nnn varchar2(20) default ''aaa'')';
end;

--if语句:取出7369的薪水,如果<1200,则输出'low',如果<2000则输出'middle',否则'high'
declare
  v_sal emp.sal%type;
begin
  select sal into v_sal from emp where empno = 7369;
  if(v_sal < 1200) then
    dbms_output.put_line('low');
  elsif(v_sal < 2000) then
    dbms_output.put_line('middle');
  else
    dbms_output.put_line('high');
  end if;
end;


--循环
declare
  i binary_integer := 1;
begin
  loop
    dbms_output.put_line(i);
    i := i+ 1;
    exit when (i >= 11);
  end loop;
end;

declare
  j binary_integer := 1;
begin
  while j< 11 loop
    dbms_output.put_line(j);
    j := j+ 1;
  end loop;
end;

begin
  for k in 1..10 loop
    dbms_output.put_line(k);
  end loop;

  for k in reverse 1..10 loop
    dbms_output.put_line(k);
  end loop;
end;


--错误处理
declare
  v_temp number(4);
begin
  select empno into v_temp from emp where deptno = 10;
exception
  when too_many_rows then
    dbms_output.put_line('太多记录了');
  when others then
    dbms_output.put_line('error');
end;


declare
  v_temp number(4);
begin
  select empno into v_temp from emp where empno = 2222;
exception
  when no_data_found then
    dbms_output.put_line('没数据');

end;


create table errorlog
(
id number primary key,
errcode number,
errmsg varchar2(1024),
errdate date
);


create sequence seq_errorlog_id start with 1 increment by 1;


declare
  v_deptno dept.deptno%type := 10;
  v_errmsg varchar2(1024);
begin
  delete from dept where deptno = v_deptno;
  commit;
exception
  when others then
  rollback;
  v_errcode := SQLCODE;  --关键字,代表出错的代码。
  v_errmsg := SQLERRM;
  insert into errorlog values (seq_errorlog_id.nextval,v_errcode,v_errmsg,sysdate);
  commit;
end;

posted @ 2010-07-24 16:03 断点 阅读(298) | 评论 (0)编辑 收藏

构造数据库必须遵循一定的规则。在关系数据库中,这种规则就是范式。关系数据库中的关系必须满足一定的要求,即满足不同的范式。目前关系数据库有六种范式:第一范式(1NF)、第二范式(2NF)、第三范式(3NF)、第四范式(4NF)、第五范式(5NF)和第六范式(6NF)。满足最低要求的范式是第一范式(1NF)。在第一范式的基础上进一步满足更多要求的称为第二范式(2NF),其余范式以次类推。一般说来,数据库只需满足第三范式(3NF)就行了。


第一范式(1NF):无重复的列。
    所谓第一范式(1NF)是指数据库表的每一列都是不可分割的基本数据项,同一列中不能有多个
值,即实体中的某个属性不能有多个值或者不能有重复的属性。如果出现重复的属性,就可能需要定义一个新的实体,新的实体由重复的属性构成,新实体与原实体之间为一对多关系。在第一范式(1NF)中表的每一行只包含一个实例的信息。简而言之,第一范式就是无重复的列。
   
   数据库表中的字段都是单一属性的,不可再分。这个单一属性由基本类型构成,包括整型、实数、字符型、逻辑型、日期型等。

说明:在任何一个关系数据库中,第一范式(1NF)是对关系模式的基本要求,不满足第一范式(1NF)的数据库就不是关系数据库。

 

第二范式(2NF):属性完全依赖于主键[消除部分子函数依赖]。
 
    第二范式(2NF)是在第一范式(1NF)的基础上建立起来的,即满足第二范式(2NF)必须先满
足第一范式(1NF)。第二范式(2NF)要求数据库表中的每个实例或行必须可以被惟一地区分。为实现区分通常需要为表加上一个列,以存储各个实例的惟一标识。例如员工信息表中加上了员工编号(emp_id)列,因为每个员工的员工编号是惟一的,因此每个员工可以被惟一区分。这个惟一属性列被称为主关键字或主键、主码。
    第二范式(2NF)要求实体的属性完全依赖于主关键字。所谓完全依赖是指不能存在仅依赖主
关键字一部分的属性,如果存在,那么这个属性和主关键字的这一部分应该分离出来形成一个新的实体,新实体与原实体之间是一对多的关系。为实现区分通常需要为表加上一个列,以存储各个实例的惟一标识。简而言之,第二范式就是属性完全依赖于主键。

第三范式(3NF):属性不依赖于其它非主属性[消除传递依赖]。
   
    满足第三范式(3NF)必须先满足第二范式(2NF)。简而言之,第三范式(3NF)要求一个数据库表中不包含已在其它表中已包含的非主关键字信息。例如,存在一个部门信息表,其中每个部门有部门编号(dept_id)、部门名称、部门简介等信息。那么在的员工信息表中列出部门编号后就不能再将部门名称、部门简介等与部门有关的信息再加入员工信息表中。如果不存在部门信息表,则根据第三范式(3NF)也应该构建它,否则就会有大量的数据冗余。简而言之,第三范式就是属性不依赖于其它非主属性。
    
所谓传递函数依赖,指的是如果存在"A → B → C"的决定关系,则C传递函数依赖于A。

posted @ 2010-07-18 10:23 断点 阅读(205) | 评论 (0)编辑 收藏

序列:sequence,产生一个独一无二的序列,是oracle特有的。

create table article
(
id number,
title varchar2(1024),
cont long
);
insert into article values(seq.nextval,'a','b');

select * from user_sequences; --查询序列

create sequence seq; --创建序列seq对象
select seq.nextval from dual;
drop sequence seq;

posted @ 2010-07-17 22:08 断点 阅读(194) | 评论 (0)编辑 收藏

仅列出标题
共18页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last