db2

jquery radio取值,checkbox取值,select取值,radio选中,
jquery radio取值,checkbox取值,select取值,radio选中,

var item = $('input[@name=items][@checked]').val();


获取select被选中项的文本

var item = $("select[@name=items] option[@selected]").text();


select下拉框的第二个元素为当前选中值

$('#select_id')[0].selectedIndex = 1;


radio单选组的第二个元素为当前选中值

$('input[@name=items]').get(1).checked = true;


获取值:

文本框,文本区域:$("#txt").attr("value");

多选框checkbox:$("#checkbox_id").attr("value");

单选组radio: $("input[@type=radio][@checked]").val();

下拉框select: $('#sel').val();

控制表单元素:

文本框,文本区域:$("#txt").attr("value",'');//清空内容

   $("#txt").attr("value",'11');//填充内容


多选框checkbox: $("#chk1").attr("checked",'');//不打勾

   $("#chk2").attr("checked",true);//打勾

   if($("#chk1").attr('checked')==undefined) //判断是否已经打勾


单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项


下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项

   $("<optionvalue='1'>1111</option><optionvalue='2'>2222</option>").appendTo("#sel")//添加


下拉框的option

   $("#sel").empty();//清空下拉框


获取一组radio被选中项的值

var item = $('input[@name=items][@checked]').val();


获取select被选中项的文本

var item = $("select[@name=items] option[@selected]").text();


select下拉框的第二个元素为当前选中值

$('#select_id')[0].selectedIndex = 1;


radio单选组的第二个元素为当前选中值

$('input[@name=items]').get(1).checked = true;


获取值:

文本框,文本区域:$("#txt").attr("value");


多选框checkbox:$("#checkbox_id").attr("value");


单选组radio: $("input[@type=radio][@checked]").val();


下拉框select: $('#sel').val();


控制表单元素:

文本框,文本区域:$("#txt").attr("value",'');//清空内容


$("#txt").attr("value",'11');//填充内容


多选框checkbox: $("#chk1").attr("checked",'');//不打勾


$("#chk2").attr("checked",true);//打勾


if($("#chk1").attr('checked')==undefined) //判断是否已经打勾


单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项


下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项


$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option


$("#sel").empty();//清空下拉框

 

 


//遍历option和添加、移除option
function changeShipMethod(shipping){
 var len = $("select[@name=ISHIPTYPE] option").length
 if(shipping.value != "CA"){
  $("select[@name=ISHIPTYPE] option").each(function(){
   if($(this).val() == 111){
    $(this).remove();
   }
  });
 }else{
  $("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
 }
}


//取得下拉选单的选取值

$('#testSelect option:selected').text();
或$("#testSelect").find('option:selected').text();
或$("#testSelect").val();
//
记性不好的可以收藏下:
1,下拉框:

var cc1   = $(".formc select[@name='country'] option[@selected]").text(); //得到下拉菜单的选中项的文本(注意中间有空格)
var cc2 = $('.formc select[@name="country"]').val();   //得到下拉菜单的选中项的值
var cc3 = $('.formc select[@name="country"]').attr("id"); //得到下拉菜单的选中项的ID属性值
$("#select").empty();//清空下拉框//$("#select").html('');
$("<option value='1'>1111</option>").appendTo("#select")//添加下拉框的option

稍微解释一下:
1.select[@name='country'] option[@selected] 表示具有name 属性,
并且该属性值为'country' 的select元素 里面的具有selected 属性的option 元素;
可以看出有@开头的就表示后面跟的是属性。

2,单选框:
$("input[@type=radio][@checked]").val();   //得到单选框的选中项的值(注意中间没有空格)
$("input[@type=radio][@value=2]").attr("checked",'checked'); //设置单选框value=2的为选中状态.(注意中间没有空格)

3,复选框:
$("input[@type=checkbox][@checked]").val(); //得到复选框的选中的第一项的值
$("input[@type=checkbox][@checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出
   alert($(this).val());
   });

$("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined){} //判断是否已经打勾


当然jquery的选择器是强大的. 还有很多方法.

<script src="jquery-1.2.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
       //alert("Hello");
       //alert($("#selectTest").attr("name"));
       //$("a").attr("href","xx.html");
       //window.location.href="xx.html";
       //alert($("#selectTest").val());
       alert($("#selectTest option[@selected]").text());
       $("#selectTest").attr("value", "2");

});
});
</script>


<a href="#">aaass</a>

<!--下拉框-->
<select id="selectTest" name="selectTest">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>
jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关获取一组radio被选中项的值
var item = $('input[@name=items][@checked]').val();
获取select被选中项的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二个元素为当前选中值
$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中值
$('input[@name=items]').get(1).checked = true;
获取值:
文本框,文本区域:$("#txt").attr("value");
多选框checkbox:$("#checkbox_id").attr("value");
单选组radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();
控制表单元素:
文本框,文本区域:$("#txt").attr("value",'');//清空内容
                $("#txt").attr("value",'11');//填充内容
多选框checkbox: $("#chk1").attr("checked",'');//不打勾
                $("#chk2").attr("checked",true);//打勾
                if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
            $("<optionvalue='1'>1111</option><optionvalue='2'> 2222</option>").appendTo("#sel")//添加下拉框的option
            $("#sel").empty();//清空下拉框

获取一组radio被选中项的值
var item = $('input[@name=items][@checked]').val();
获取select被选中项的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二个元素为当前选中值
$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中值
$('input[@name=items]').get(1).checked = true;
获取值:
文本框,文本区域:$("#txt").attr("value");
多选框checkbox:$("#checkbox_id").attr("value");
单选组radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();
控制表单元素:
文本框,文本区域:$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框

 

只改动CSS让IE6支持透明PNG

作为浏览器市场的老大,IE6的罪恶罄竹难书,不支持透明PNG这一“特性”让IE6成为常用浏览器中唯一的异类。IE特有的CSS滤镜虽然可以做到这一点,但是代码比较复杂,而

且使用了该滤镜所属标签下的链接失效。在这里和大家分享一个能让IE6不完美支持透明PNG图片的“傻瓜式”脚本,至于为什么是不完美,我们稍后分析

 


来源:http://www.twinhelix.com/css/iepngfix/
预览:http://www.twinhelix.com/css/iepngfix/demo/
下载:http://www.twinhelix.com/css/iepngfix/iepngfix.zip
效果:允许IE6正常显示使用<img>标签插入或以CSS background-image方式写入的透明PNG图象。

使用方法:

1、下载脚本脚本,将其中的iepngfix.htc和blank.gif解压缩到合适的目录内,.htc即Html Components,该文件需要在CSS中被调用;blank.gif是一个1×1像素的透明GIF图片

,缺少该文件会使<img>标签插入的PNG图象显示为红色的叉烧包。

2、在iepngfix.htc中修改blank.gif的路径,var blankImg =‘blank.gif的正确路径’,这是惟一一个需要修改的配置。

if (typeof blankImg == ‘undefined’) var blankImg = ‘blank.gif’;

3、在css中将需要使用透明PNG的元素与.htc文件关联。

例如:*{behavior: url(iepngfix.htc) }

轻松三步,IE6就能支持透明PNG图片了。

进阶使用:

1、在css中使用通配符“*”调用.htc脚本会对body内所有标签进行处理,加大客户端的资源消耗,延缓页面载入时间。我们可以细化CSS选择器针对某一个标签甚至是某个ID的

元素来套用脚本以获得更好的用户体验。

例如:img,div{behavior: url(iepngfix.htc) }
div#header{behavior: url(iepngfix.htc)}

如果无法预见页面中哪些地方需要这个滤镜,还可以将behavior写入成class以便调用。

.pngsupport{behavior: url(iepngfix.htc)}

2、利用IE的条件注释使脚本只应用于IE6及以下版本,减少对IE7用户的影响。

<!–[if lte IE 6]>
*{behavior: url(iepngfix.htc)}
<![endif]–>

3、behavior是IE特有的属性,直接写入样式表将导致页面无法通过W3C的css验证。使用以下脚本写入behavior就可以解决这个问题,前提是页面必须有一个外部样式表,并且

位于这个脚本的上面。这种方法的不便之处每次只能添加一个选择符。
 

<script type=”text/javascript”>
if (document.all && /MSIE (5/.5|6)/.test(navigator.userAgent) &&
  document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {
 document.styleSheets[0].addRule(’*', ‘behavior: url(iepngfix.htc)’);
 document.styleSheets[0].addRule(’img’, ‘behavior: url(iepngfix.htc)’);
 document.styleSheets[0].addRule(’div’, ‘behavior: url(iepngfix.htc)’);
 }
 </script>.

缺陷:

在文章开头我就说过这个脚本不是完美的,一起来看看iepngfix.htc都有哪些短版吧。

1、使用PNG透明背景可能导致该元素内部链接无法点击,尤其在链接具有float属性的时候,如:存在于一个浮动列表中的链接。推荐解决方法:使用display:inline代替float

来实现块级元素的的横向排列。

2、img标签的插入的透明PNG图象无法使用右键保存,“另存为”只能取到覆盖在上面的blank.gif。什么?不要blank.gif?等着吃叉烧包吧。

3、作为背景的PNG图象无法被平铺,无法被定位,即background-repeat默认为no-repeat,而background-position彻底失效。

4、在页面刚载入的时候我们依旧能看到PNG图象因为IE6不支持而短暂出现的灰边,时间取决页面文件的大小和网络速度。

5、作者建议为使用PNG背景的元素设置一个固定宽度,但在我的使用中尚未发现width:auto会带来什么问题。

6、不支持低于5.5版本的浏览器,不过这个问题已经算不上问题。

 

 

 

 

 

 

 

 


DB2常用SQL的写法(持续更新中...)
-- Author: lavasoft
-- Date  :  2006-12-14
 
-- 创建一个自定义单值类型
create  distinct type var_newtype
 as decimal(5,2) with comparisons;
 -- var_newtype 类型名
 -- decimal(5,2) 实际的类型
 
-- 删除一个自定义单值类型
drop distinct type var_newtype;
 
-- 创建一个自定义结构数据类型
create type my_type as(
 username varchar(20),
 department integer,
 salary decimal(10,2))
 not final
 mode db2sql;

-- 修改自定义结构数据类型,我目前还没有发现删除属性的方法.
alter type my_type
add attribute hiredate date;
 
-- 删除自定义结构数据类型
drop type my_type;

-- 获取系统当前日期
select current date from sysibm.sysdummy1;
select current time from sysibm.sysdummy1;
select current timestamp from sysibm.sysdummy1;

 --sysibm.sysdummy1表是一个特殊的内存中的表,用它可以发现如上面演示的 DB2 寄存器的值。您也可以使用关键字 VALUES 来对寄存器或表达式求值。
VALUES current date;
VALUES current time;
VALUES current timestamp;
 
-- VALUES的更多用法
VALUES 2+5;
VALUES 'hello lavasoft!';
 
values 56
union all
values 45;
 
values 1,2,3,4,5,6
union all
values 7,8,9,10,11,12
order by 1;

-- 更多变态级DB2 SQL写法,AnyOneTable表示任意一个存在的表
select 234 from AnyOneTable;
select distinct 234 from AnyOneTable;
select distinct 234 as 1 from AnyOneTable;
 
select 'DB2变态级的SQL哈哈' from AnyOneTable;
select distinct 'DB2变态级的SQL哈哈' from AnyOneTable;
select distinct 'DB2变态级的SQL哈哈' as 1 from AnyOneTable;
     --(嘿嘿,好玩吧,你可以用任意一个表来当sysibm.sysdummy1用.不过不推荐这么做,除非你不记得sysibm.sysdummy1怎么写了,Oracle中(对应dual)也一样!哈哈哈哈!)
 
-- 定义变量,还可以设定默认值,给变量赋值
declare var1 char(2);
declare var2 int default 0;
set var1 = 'aa';
set var2 =23;
 
--创建一个动态游标变量
declare d_cur integer;
 
-- 给变量赋值的另一种方法
values expr1, expr2, expr3 into a, b, c;
 -- 相当于
set a = expr1;
set b = expr2;
set c = expr3;
 
-- 还有一种赋值方式
set prodname = (case
                  when (name is not null) then name
                  when (namestr is not null) then namestr
                  else  defaultname
                end);
 -- 相当于
set prodname = coalesce(name, namestr, defaultname);
 --这个类似oracle的decode()和nvl()函数的合并.

-- 定义一个游标
declare cur1 cursor with return to client for select * from dm_hy;
declare cur2 cursor for select * from dm_hy; -- 静态游标

-- 创建数据表,并添加注释,插入数据.
CREATE TABLE tbr_catalog (
  id bigint  not null  generated by default as identity,
  type smallint not null,
  name varchar(255),
  parentid bigint,
  cataloglevel bigint,
  description varchar(255),
  PRIMARY KEY  (id)
);
 comment on table tbr_catalog is 'Birt报表目录表';
 comment on column tbr_catalog.ID is '标识';
 comment on column tbr_catalog.type is '目录类型';
 comment on column tbr_catalog.name is '目录名称';
 comment on column tbr_catalog.parentid is '目录父标识';
 comment on column tbr_catalog.cataloglevel is '目录层次';
 comment on column tbr_catalog.description is '目录描述';
 -- 给数据表插入数据
insert into tbr_catalog(id, type, name, parentid, cataloglevel, description)
values (1, 0, '系统报表', 0, 0, '');
insert into tbr_catalog(id, type, name, parentid, cataloglevel, description)
values (2, 1, '用户报表', 0, 0, '');
 
-- 创建外键
alter table tbr_storage
 add constraint fk_tbr_storage
 foreign key (catalogid)
 references tbr_catalog(id);
 
-- 更改表,添加列
alter table aaa add sex varchar(1);

-- 更改表,删除列
alter table aaa drop column sex;
 
-- 去掉参数前后的空格
rtrim(dm_hy.mc);

-- 定义临时表,通过已有person表来创建
declare global temporary table gbl_temp
like person
on commit delete rows --提交时删除数据
not logged -- 不在日志中纪录
in usr_tbsp -- 选用表空间
 -- 此语句创建一个名为 gbl_temp 的用户临时表。定义此用户临时表 所使用的列的名称和说明与 person 的列的名称和说明完全相同。
 
-- 创建有两个字段的临时表 
    -- 定义一个全局临时表tmp_hy
declare global temporary table session.tmp_hy
    (
       dm varchar(10),
       mc varchar(10)        
    )
     with replace -- 如果存在此临时表,则替换
     not logged;  -- 不在日志里纪录
    -- 给临时表插入三条数据
    insert into session.tmp_hy values('1','1');
    insert into session.tmp_hy values('1','1');
    insert into session.tmp_hy values('1','1');
 
-- 通过查询批量插入数据
inster into tab_bk(select code,name from table book);
 
-- select ... into的用法
select * into :h1, :h2, :h3, :h4
     from emp
     where empno = '528671';
 
-- 语句的流程控制
if() then
 open cur1
 fetch cur1 into t_equipid;
 while(at_end<>1)do
  ......
 set t_temp=0;                                                           
 end while;
 close cur1;
else
 ......
end if;

-- 外连接
select empno,deptname,projname
  from (emplyoee
  left outer join project
  on respemp=empon)
  left outer join department
  on mgrno=empno;
 
-- in、like、order by(... ASC|DESC)的用法
select * from book t
where t.name like '%J_编程%'
and t.code in('J565333','J565222');
order by t.name asc
 
-- 汇总表(概念复杂,难以理解,不常用)
create summary table sumy_stable1
  as (select workdept,
    count(*) as reccount,
    sum(salary) as salary,
    sum(bonus) as bonus
  from employee group by workdept)
 data initially deferred
 refresh immediate;
 
-- 使用SQL一次处理一个集合语义
-- (优化前) select语句中每行的过程层和数据流层之间都有一个上下文切换
declare cur1 cursor for col1,col2 from tab_comp;
open cur1;
fetch cur1 into v1,v2;
while SQLCODE<> 100 do
 if (v1>20) then
  insert into tab_sel values(20,v1);
 else
  insert into tab_sel values(v1,v2);
 end if;
 fetch cur1 into v1,v2;
end while;
 
-- (优化后)没有过程层和数据流层之间的上下文切换
declare cur1 cursor for col1,col2 from tab_comp;
open cur1;
fetch cur1 into v1,v2;
while SQLCODE<> 100 do
 insert into tab_sel(select (case
         when col1>20 then 20
            else col1
        end),
        col2
      from tab_comp);
 fetch cur1 into v1,v2;
end while;
 
-- DB2函数分三类:列函数、标量函数、表函数
-- 列函数输入一组数据,输出单一结果。
-- 标量函数接收一个值,返回另外一个值。
-- 表函数只能用于SQL语句的from字句中,它返回一个表的列,类似于一个已创建的常规表。

-- 下面是个标量函数的例子。
create function (salary int,bonus_percent int)
returns int
language SQL contains SQL
return(
 salary * bonus_percent/100
)

-- 下面是表函数
create function get_marks(begin_range int,end_range int)
 returns table(cid candidate_id,
       number test_id,
       score score)
 language SQL reads SQL DATA
 return
    select cid,number,score
    from test_taken
    where salary between (begin_range) and score(end_range)
 
 
example 1: define a scalar function that returns the tangent of a value using the existing sine and cosine functions.
   create function tan (x double)
     returns double
     language sql
     contains sql
     no external action
     deterministic
     return sin(x)/cos(x)              

example 2: define a transform function for the structured type person.
    
   create function fromperson (p person)
     returns row (name varchar(10), firstname varchar(10))
     language sql
     contains sql
     no external action
     deterministic
     return values (p..name, p..firstname)

example 3: define a table function that returns the employees in a specified department number.
    
   create function deptemployees (deptno char(3))
     returns table (empno char(6),
                    lastname varchar(15),
                    firstname varchar(12))
     language sql
     reads sql data
     no external action
     deterministic
     return
       select empno, lastname, firstnme
         from employee
         where employee.workdept = deptemployees.deptno

example 4: define a scalar function that reverses a string.
   create function reverse(instr varchar(4000))
     returns varchar(4000)
     deterministic no external action contains sql
     begin atomic
     declare revstr, reststr varchar(4000) default '';
     declare len int;
     if instr is null then
     return null;
     end if;
     set (reststr, len) = (instr, length(instr));
     while len > 0 do
     set (revstr, reststr, len)
       = (substr(reststr, 1, 1) concat revstr,
       substr(reststr, 2, len - 1),
       len - 1);
     end while;
     return revstr;
   end

example 4: define the table function from example 4 with auditing.
   create function deptemployees (deptno char(3))
     returns table (empno char(6),
                    lastname varchar(15),
                    firstname varchar(12))
     language sql
     modifies sql data
     no external action
     deterministic
     begin atomic
       insert into audit
       values (user,
               'table: employee prd: deptno = ' concat deptno);
       return
         select empno, lastname, firstnme
           from employee
           where employee.workdept = deptemployees.deptno
     end
 
-- for循环语句的用法
begin atomic
 declare fullname char(40);
 for vl as
   select firstnme, midinit, lastname from employee
  do
  set fullname = lastname concat ','
    concat firstnme concat ' ' concat midinit;
  insert into tnames values (fullname);
 end for
end
 
-- leave的用法
create procedure leave_loop(out counter integer)
 language sql
 begin
   declare v_counter integer;
   declare v_firstnme varchar(12);
   declare v_midinit char(1);
   declare v_lastname varchar(15);
   declare at_end smallint default 0;
   declare not_found condition for sqlstate '02000';
   declare c1 cursor for
  select firstnme, midinit, lastname
    from employee;
   declare continue handler for not_found
  set at_end = 1;
   set v_counter = 0;
   open c1;
   fetch_loop:
   loop
  fetch c1 into v_firstnme, v_midinit, v_lastname;
  if at_end <> 0 then leave fetch_loop;
  end if;
  set v_counter = v_counter + 1;
   end loop fetch_loop;
   set counter = v_counter;
   close c1;
 end

 
-- if语句的用法
   create procedure update_salary_if
     (in employee_number char(6), inout rating smallint)
     language sql
     begin
       declare not_found condition for sqlstate '02000';
       declare exit handler for not_found
         set rating = -1;
       if rating = 1
         then update employee
         set salary = salary * 1.10, bonus = 1000
         where empno = employee_number;
       elseif rating = 2
         then update employee
         set salary = salary * 1.05, bonus = 500
         where empno = employee_number;
       else update employee
         set salary = salary * 1.03, bonus = 0
         where empno = employee_number;
       end if;
     end
 
-- loop的用法
   create procedure loop_until_space(out counter integer)
     language sql
     begin
       declare v_counter integer default 0;
       declare v_firstnme varchar(12);
       declare v_midinit char(1);
       declare v_lastname varchar(15);
       declare c1 cursor for
         select firstnme, midinit, lastname
           from employee;
       declare continue handler for not found
         set counter = -1;
       open c1;
       fetch_loop:
       loop
         fetch c1 into v_firstnme, v_midinit, v_lastname;
         if v_midinit = ' ' then
           leave fetch_loop;
         end if;
         set v_counter = v_counter + 1;
       end loop fetch_loop;
       set counter = v_counter;
       close c1;
     end
 
-- return的用法
   begin
   ...
     goto fail
   ...
     success: return 0
     fail: return -200
   end
 
-- set变量 的用法
set new_var.salary = 10000, new_var.comm = new_var.salary;
or:
set (new_var.salary, new_var.comm) = (10000, new_var.salary);
set (new_var.salary, new_var.comm)
  = (select avg(salary), avg(comm)
    from employee e
    where e.workdept = new_var.workdept);
 
-- whenever的用法
   exec sql whenever sqlerror goto handlerr;
   exec sql whenever sqlwarning continue;
   exec sql whenever not found go to enddata;
 
-- while的用法
   create procedure dept_median
     (in deptnumber smallint, out mediansalary double)
     language sql
     begin
       declare v_numrecords integer default 1;
       declare v_counter integer default 0;
       declare c1 cursor for
         select cast(salary as double)
           from staff
           where dept = deptnumber
           order by salary;
       declare exit handler for not found
         set mediansalary = 6666;
       set mediansalary = 0;
       select count(*) into v_numrecords
         from staff
         where dept = deptnumber;
       open c1;
       while v_counter < (v_numrecords / 2 + 1) do
         fetch c1 into mediansalary;
         set v_counter = v_counter + 1;
       end while;
       close c1;
     end
 
-- set schema的用法
set schema rick
 
-- DB2保留关键字
add                deterministic  leave         restart
after              disallow       left          restrict
alias              disconnect     like          result
all                distinct       linktype      result_set_locator
allocate           do             local         return
allow              double         locale        returns
alter              drop           locator       revoke
and                dsnhattr       locators      right
any                dssize         lock          rollback
application        dynamic        lockmax       routine
as                 each           locksize      row
associate          editproc       long          rows
asutime            else           loop          rrn
audit              elseif         maxvalue      run
authorization      encoding       microsecond   savepoint
aux                end            microseconds  schema
auxiliary          end-exec       minute        scratchpad
before             end-exec1      minutes       second
begin              erase          minvalue      seconds
between            escape         mode          secqty
binary             except         modifies      security
bufferpool         exception      month         select
by                 excluding      months        sensitive
cache              execute        new           set
call               exists         new_table     signal
called             exit           no            simple
capture            external       nocache       some
cardinality        fenced         nocycle       source
cascaded           fetch          nodename      specific
case               fieldproc      nodenumber    sql
cast               file           nomaxvalue    sqlid
ccsid              final          nominvalue    standard
char               for            noorder       start
character          foreign        not           static
check              free           null          stay
close              from           nulls         stogroup
cluster            full           numparts      stores
collection         function       obid          style
collid             general        of            subpages
column             generated      old           substring
comment            get            old_table     synonym
commit             global         on            sysfun
concat             go             open          sysibm
condition          goto           optimization  sysproc
connect            grant          optimize      system
connection         graphic        option        table
constraint         group          or            tablespace
contains           handler        order         then
continue           having         out           to
count              hold           outer         transaction
count_big          hour           overriding    trigger
create             hours          package       trim
cross              identity       parameter     type
current            if             part          undo
current_date       immediate      partition     union
current_lc_ctype   in             path          unique
current_path       including      piecesize     until
current_server     increment      plan          update
current_time       index          position      usage
current_timestamp  indicator      precision     user
current_timezone   inherit        prepare       using
current_user       inner          primary       validproc
cursor             inout          priqty        values
cycle              insensitive    privileges    variable
data               insert         procedure     variant
database           integrity      program       vcat
day                into           psid          view
days               is             queryno       volumes
db2general         isobid         read          when
db2genrl           isolation      reads         where
db2sql             iterate        recovery      while
dbinfo             jar            references    with
declare            java           referencing   wlm
default            join           release       write
defaults           key            rename        year
definition         label          repeat        years
delete             language       reset
descriptor         lc_ctype       resignal
 
-- SQL99关键字
absolute       describe        module      session
action         destroy         names       session_user
admin          destructor      national    sets
aggregate      diagnostics     natural     size
are            dictionary      nchar       smallint
array          domain          nclob       space
asc            equals          next        specifictype
assertion      every           none        sqlexception
at             exec            numeric     sqlstate
bit            false           object      sqlwarning
blob           first           off         state
boolean        float           only        statement
both           found           operation   structure
breadth        grouping        ordinality  system_user
cascade        host            output      temporary
catalog        ignore          pad         terminate
class          initialize      parameters  than
clob           initially       partial     time
collate        input           postfix     timestamp
collation      int             prefix      timezone_hour
completion     integer         preorder    timezone_minute
constraints    intersect       preserve    trailing
constructor    interval        prior       translation
corresponding  large           public      treat
cube           last            real        true
current_role   lateral         recursive   under
date           leading         ref         unknown
deallocate     less            relative    unnest
dec            level           role        value
decimal        limit           rollup      varchar
deferrable     localtime       scope       varying
deferred       localtimestamp  scroll      whenever
depth          map             search      without
deref          match           section     work
desc           modify          sequence    zone
 
--create type (结构化的)用法
   create type dept as
      (dept name     varchar(20),
         max_emps int)
         ref using int
      mode db2sql

   create type emp as
     (name      varchar(32),
     serialnum int,
     dept      ref(dept),
     salary    decimal(10,2))
     mode db2sql
 
   create type mgr under emp as
     (bonus     decimal(10,2))
     mode db2sql

 
   create type address_t as
     (street     varchar(30),
     number     char(15),
     city       varchar(30),
     state      varchar(10))
     not final
     mode db2sql
       method samezip (addr address_t)
       returns integer
       language sql
       deterministic
       contains sql
       no external action,
       method distance (address_t)
       returns float
       language c
       deterministic
       parameter style sql
       no sql
       no external action
 
   create type germany_addr_t under address_t as
     (family_name varchar(30))
     not final
     mode db2sql
 
   create type us_addr_t under address_t as
     (zip varchar(10))
     not final
     mode db2sql

   create type project as
     (proj_name  varchar(20),
      proj_id    integer,
      proj_mgr   mgr,
      proj_lead  emp,
      location   addr_t,
      avail_date date)
      mode db2sql

 
-- create type mapping的用法
create type mapping my_oracle_date
  from local type sysibm.date
  to server type oracle
  remote type date
 
create type mapping my_oracle_dec
  from local type sysibm.decimal(10,2)
  to server oracle1
  remote type number([10..38],2)
 
create type mapping my_oracle_char
  from local type sysibm.varchar()
  to server oracle1
  remote type char()
 
create type mapping my_oracle_dec
  to local type sysibm.decimal(10,2)
  from server oracle2
  remote type number(10,2)
 
-- create user mapping的用法
create user mapping for rspalten
  server server390
  options
  (remote_authid 'system',
  remote_password 'manager')
 
create user mapping for marcr
  server oracle1
  options
  (remote_password 'nzxczy')

 
-- case的用法
case v_workdept
  when'a00'
    then update department
    set deptname = 'data access 1';
  when 'b01'
    then update department
    set deptname = 'data access 2';
  else update department
    set deptname = 'data access 3';
end case
 
case
  when v_workdept = 'a00'
    then update department
    set deptname = 'data access 1';
  when v_workdept = 'b01'
    then update department
    set deptname = 'data access 2';
  else update department
    set deptname = 'data access 3';
end case
 
-- create trigger的用法
create trigger new_hired
  after insert on employee
  for each row
  update company_stats set nbemp = nbemp + 1
 
create trigger former_emp
  after delete on employee
  for each row
  update company_stats set nbemp = nbemp - 1
 
create trigger reorder
  after update of on_hand, max_stocked on parts
  referencing new as n
  for each row
  when (n.on_hand < 0.10 * n.max_stocked)
  begin atomic
  values(issue_ship_request(n.max_stocked - n.on_hand, n.partno));
  end
 
create trigger raise_limit
  after update of salary on employee
  referencing new as n old as o
  for each row
  when (n.salary > 1.1 * o.salary)
         signal sqlstate '75000' set message_text='salary increase>10%'
 
create trigger stock_status
  no cascade before update of quote on currentquote
  referencing new as newquote old as oldquote
  for each row
  begin atomic
     set newquote.status =
       case
          when newquote.quote >
                (select max(quote) from quotehistory
                where symbol = newquote.symbol
                and year(quote_timestamp) = year(current date) )
             then 'high'
          when newquote.quote < (select min(quote) from quotehistory
                where symbol = newquote.symbol
                and year(quote_timestamp) = year(current date) )
             then 'low'
          when newquote.quote > oldquote.quote
             then 'rising'
          when newquote.quote < oldquote.quote
             then 'dropping'
          when newquote.quote = oldquote.quote
             then 'steady'
       end;
  end
 
create trigger record_history
  after update of quote on currentquote
  referencing new as newquote
  for each row
  begin atomic
    insert into quotehistory
      values (newquote.symbol, newquote.quote, current timestamp);
  end

-- create tablespace 的用法
create tablespace payroll
  managed by database
  using (device'/dev/rhdisk6' 10000,
    device '/dev/rhdisk7' 10000,
    device '/dev/rhdisk8' 10000)
  overhead 12.67
  transferrate 0.18
 
create tablespace accounting
  managed by system
  using ('d:/acc_tbsp', 'e:/acc_tbsp', 'f:/acc_tbsp')
  extentsize 64
  prefetchsize 32

create tablespace plans
  managed by database
  using (device '/dev/rhdisk0' 10000, device '/dev/rn1hd01' 40000)
  on dbpartitionnum (1)
  using (device '/dev/rhdisk0' 10000, device '/dev/rn3hd03' 40000)
  on dbpartitionnum (3)
  using (device '/dev/rhdisk0' 10000, device '/dev/rn5hd05' 40000)
  on dbpartitionnum (5)

 
-- 带case查询条件语句
select (case b.organtypecode
         when 'D' then
          b.parent
         when 'S' then
          b.parent
         else
          b.id
       end),
       b.name
  from A_ORGAN b
 where b.id = 999

重新安装DB2后 创建数据库提示数据库别名已经存在的问题
这个原因,是由于在卸载DB2之后,由于没有在本地文件系统中将安装的文件清理干净,所以倒是了在DB2的本地目录中还存在这卸载的时候DB2中创建的数据库的别名(由于在系

统目录中已经不存在这些别名了,所以在控制中心的视图中是看不见的);具体的处理方法是:
1.把本地的目录信息重新设置到系统目录中去:
catalog db sample on d:
2.drop掉这个database
drop db sample
3.重新创建这个database
create db sample

注1: 如果不做第一步,直接做第二步系统会提示找不到sample的数据库别名,因为此时系统的目录中没有sample这样的数据库别名,所以我们必须把本地目录的数据库别名信

息同步到系统目录中,然后在去做第二步才能真正的drop这个数据库。

注2:查看目录信息的命令是:
list db directory ----查看系统的目录信息
list db directory on d: -----查看制定的本地路径的目录信息
在重新catalog之前最好使用这两个命令查看一下具体的目录信息

 


我们用db2look命令得到数据库对象的DDL 脚本
DB2的db2look命令诠释如下:
db2look 版本 8.2
db2look:生成 DDL 以便重新创建在数据库中定义的对象
语法: db2look -d DBname [-e] [-u Creator] [-z Schema] [-t Tname1 Tname2...TnameN] [-tw Tname] [-h] [-o Fname] [-a]
                        [-m] [-c] [-r] [-l] [-x] [-xd] [-f] [-fd] [-td x] [-noview] [-i userID] [-w password]
                        [-v Vname1 Vname2 ... VnameN]
                        [-wrapper WrapperName] [-server ServerName] [-nofed]

      db2look -d DBname [-u Creator] [-s] [-g] [-a] [-t Tname1 Tname2...TnameN]
                        [-p] [-o Fname] [-i userID] [-w password]
      db2look [-h]

        -d: 数据库名称:这必须指定

        -e: 抽取复制数据库所需要的 DDL 文件
            此选项将生成包含 DDL 语句的脚本
            可以对另一个数据库运行此脚本以便重新创建数据库对象
            此选项可以和 -m 选项一起使用
        -u: 创建程序标识:若 -u 和 -a 都未指定,则将使用 $USER
            如果指定了 -a 选项,则将忽略 -u 选项
        -z: 模式名:如果同时指定了 -z 和 -a,则将忽略 -z
            联合部分的模式名被忽略
        -t: 生成指定表的统计信息
            可以指定的表的数目最多为 30
       -tw: 为名称与表名的模式条件(通配符)相匹配的表生成 DDL
            当指定了 -tw 选项时,-t 选项会被忽略
        -v: 只为视图生成 DDL,当指定了 -t 时将忽略此选项
        -h: 更详细的帮助消息
        -o: 将输出重定向到给定的文件名
            如果未指定 -o 选项,则输出将转到 stdout
        -a: 为所有创建程序生成统计信息
            如果指定了此选项,则将忽略 -u 选项
        -m: 在模拟方式下运行 db2look 实用程序
            此选项将生成包含 SQL UPDATE 语句的脚本
            这些 SQL UPDATE 语句捕获所有统计信息
            可以对另一个数据库运行此脚本以便复制初始的那一个
            当指定了 -m 选项时,将忽略 -p、-g 和 -s 选项
        -c: 不要生成模拟的 COMMIT 语句
            除非指定了 -m 或 -e,否则将忽略此选项
            将不生成 CONNECT 和 CONNECT RESET 语句
            省略了 COMMIT。在执行脚本之后,需要显式地进行落实。
        -r: 不要生成模拟的 RUNSTATS 语句
            缺省值为 RUNSTATS。仅当指定了 -m 时,此选项才有效
        -l: 生成数据库布局:数据库分区组、缓冲池和表空间。
        -x: 如果指定了此选项,则 db2look 实用程序将生成授权 DDL
            对于现有已授权特权,不包括对象的原始定义器
       -xd: 如果指定了此选项,则 db2look 实用程序将生成授权 DDL
            对于现有已授权特权,包括对象的原始定义器
        -f: 抽取配置参数和环境变量
            如果指定此选项,将忽略 -wrapper 和 -server 选项
       -fd: 为 opt_buffpage 和 opt_sortheap 以及其它配置和环境参数生成 db2fopt 语句。
       -td: 将 x 指定为语句定界符(缺省定界符为分号(;))
            应该与 -e 选项一起使用(如果触发器或者 SQL 例程存在的话)
        -p: 使用明文格式
        -s: 生成 postscript 文件
            此选项将为您生成 postscript 文件
            当设置了此选项时,将除去所有 latex 和 tmp ps 文件
            所需的(非 IBM)软件:LaTeX 和 dvips
            注意:文件 psfig.tex 必须在 LaTeX 输入路径中
        -g: 使用图形来显示索引的页访存对
            必须安装 Gnuplot,并且 <psfig.tex> 必须在您的 LaTeX 输入路径中
            还将随 LaTeX 文件一起生成 <filename.ps> 文件
        -i: 登录到数据库驻留的服务器时所使用的用户标识
        -w: 登录到数据库驻留的服务器时所使用的密码
   -noview: 不要生成 CREATE VIEW ddl 语句
  -wrapper: 为适用于此包装器的联合对象生成 DDL
            生成的对象可能包含下列各项:
            包装器、服务器、用户映射、昵称、类型映射、
            函数模板、函数映射和索引规范
   -server: 为适用于此服务器的联合对象生成 DDL
            生成的对象可能包含下列各项:
            包装器、服务器、用户映射、昵称、类型映射、
            函数模板、函数映射和索引规范
    -nofed: 不要生成 Federated DDL
            如果指定此选项,将忽略 -wrapper 和 -server 选项

LaTeX 排版:latex filename.tex 以获得 filename.dvi

示例: db2look -d DEPARTMENT -u walid -e -o db2look.sql

 -- 这将生成由用户 WALID 创建的所有表和联合对象的 DDL 语句
 -- db2look 输出被发送到名为 db2look.sql 的文件中

示例: db2look -d DEPARTMENT -z myscm1 -e -o db2look.sql

 -- 这将为模式名为 MYSCM1 的所有表生成 DDL 语句
 -- 还将生成 $USER 创建的所有联合对象的 DDL。
 -- db2look 输出被发送到名为 db2look.sql 的文件中

示例: db2look -d DEPARTMENT -u walid -m -o db2look.sql

 -- 这将生成 UPDATE 语句以捕获关于用户 WALID 创建的表/昵称的统计信息
 -- db2look 输出被发送到名为 db2look.sql 的文件中

示例: db2look -d DEPARTMENT -u walid -e -wrapper W1 -o db2look.sql

 -- 这将生成由用户 WALID 创建的所有表的 DDL 语句
 -- 还将生成适用于包装器 W1 的用户 WALID 所创建所有联合对象的 DDL
 -- db2look 输出被发送到名为 db2look.sql 的文件中

示例: db2look -d DEPARTMENT -u walid -e -server S1 -o db2look.sql

 -- 这将生成由用户 WALID 创建的所有表的 DDL 语句
 -- 还将生成适用于服务器 S1 的用户 WALID 所创建所有联合对象的 DDL
 -- db2look 输出被发送到名为 db2look.sql 的文件中

 

使用 shell 脚本生成并导出所有数据的 DML 脚本,并将其重定向到 srcdb1_export.sql 文件中。对于熟悉 DB2 的用户来说,应该知道数据库中创建的每个表、视图、别名均

对应 SYSCAT.TABLES 中一行记录。因此可以通过相应的数据库 select 语句就可以获取所有需要的数据库表信息。根据需要,下述 shell 脚本将从系统表 SYSCAT.TABLES 中

根据 tabname 字段选出 SRCDB1 中所有 tabschema 表模式是 SRCDB1,ASN,SQLDBA,DB2DBG 的表名字,并根据它们的名字生成相应的 export 导出语句,到达批量导出的目

的。rtrim 函数用于去除 tabname 字段数据的右边的空格。

 


db2 "select 'export to ' || rtrim(tabname) || '.ixf of ixf select * from ' ||
rtrim(tabname) || ';' from syscat.tables
where tabschema in('SRCDB1', 'ASN', 'SQLDBA', 'DB2DBG')" > srcdb1_export.sql ;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值