常用知识记录

sql 部分

 

1. 查询已创建的数据库
   // oracle 
   select name from v$database; 
   // db2
   db2 list db directory
2. 复制表结构
   // oracle
   create table tableName as select * from tableNameOld where 1=2;
   // db2
   # 保留 not null 和 默认值, 会丢失主键,自增量等信息
   create table tableName like tableNameOld;
   # 保留 not null, 丢失主键,自增量,默认值等信息
   create table tableName as (select * from tableNameOld) definition only;
3. 复制表结构及其数据
   // oracle
   create table talbeName as select * from tableNameOld;
   // db2
   ??
4. 修改表名
   // oracle, db2
   rename tableNameOld to tableName;   
5. 列
5.1 添加列
   // oracle, db2
   alter table tableName add columnName typeName;   
5.2 修改列
   // oracle
   alter table talbeName modify columnName typeName;
   // db2
   alter table tableName alter column columnName set data type typeName; 
5.3 删除列
   // oracle, db2
   alter table tableName drop column columnName;
6. 复制表数据
6.1 表结构一样
    // oracle, db2
    insert into tableName select * from tableNameOld;
6.2 表结构不一样
    // oracle, db2
    insert into tableName(col1,col2,...) select column1,column2,... from tableNameOld;
7. 分页
   // oracle    
    select * from (
        select A.*,rownum as rn from (sql) A where rownum <= ?
    ) where rn >= ?;
    
    select * from (
        select A.*,rownum as rn from (sql) A
    ) where rn >= ? and rn <=?;
   // db2
   select * from (
       select A.*,rownumber() over(order by columnName) rn from (sql) A
   ) where rn>=? and rn<=?;
8. null 
   判断字段为 null   : where columnName is null
   判断字段不为 null : where columnName is not null
   null 参与比较结果均为 false : > null, < null, <> null
   null 在 order by 时大于任何值
   # null     -> not null
   // oracle 
   alter table tableName modify columnName not null;
   // db2
   alter table tableName alter columnName set not null;
   # not null -> null
   // oracle
   alter table tableName modify columnName null; 
   // db2
   alter table tableName alter columnName drop not null;
9. 分组
   group by 需要和统计函数一起使用,例如 sum,avg,count,max,min等,
   且select 中出现的列必须在 group by 中出现
   select customer,sum(orderPrice) from orders group by customer;
10. 索引
   对于复合索引,where 条件中的列出现顺序必须与创建索引时的列顺序一致;
   如果 where 条件里只有复合索引中的部分列,则必须有前导列否则索引无效;
   所谓前导列可看作是创建索引时的第一个列名;
11. 系统时间
   // oracle
   select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
   // db2
   select current date from sysibm.dual;
   select current date from sysibm.sysdummy1;
   select current time from sysibm.sysdummy1;
   select current timestamp from sysibm.sysdummy1;
12. 批量更新
12.1 批量 insert
   // oracle
   ??
   // db2
   insert into tableName values (val1,val2,...),(val8,val9);
12.2 java code
   PreparedStatement prst = conn.prepareStatement(sql);
   prst.setXXX(index, value);
   prst.addBatch();          // !! 将参数添加到批处理命令中
   prst.executeBatch();      // !! 批量执行命令
13. 序列
13.1 创建序列
   # oracle, db2
   create sequence seqName increment by 1 start with 1 
     nomaxvalue nocycle cache 10;
13.2 查询序列
   # oracle 
   select seqName.currval from dual;
   select seqName.nextval from dual;
   # db2
   select seqName.currval from sysibm.dual;
   select seqName.nextval from sysibm.dual;   
   values prevval for seqName;
   values nextval for seqName;   
13.3 修改序列
   # oracle, db2
   alter sequence seqName increment by 1 maxvalue 9999
     cycle nocache;
13.4 删除序列
   # oracle, db2
   drop sequence seqName;
    

 

 

web 部分

1. session
   session 产生于用户第一次访问 jsp 页面或者第一次调用 request.getSession()
   或 request.getSession(true);
   首次访问的页面是静态页面的话不产生 session;
   session 存储在服务器上,每个 session 有一个 sessionId 与之对应,
   sessionId 存储在客户端的 cookie 中,客户端每次发送请求的时候都会发送相应的 sessionId,如果客户端禁用了 cookie 的话会采用 URL 重写的方式传递 sessionId;
2. js 中读取 cookie
function readCookies(){
    var result = "";
    var cks = document.cookie.split(";");
    for (var i=0; i<cks.length; i++){
        result += cks[i] + "\n";
    }
    alert(result);
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值