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

本人写的第一个PL/SQL过程

看到别人在论坛的提问:
一个表的效率问题
今天碰到2张表
1张 有字段
表A有
jtbh(家庭编号) hzxm(户主姓名) hnbh(户内最大编号) 
1000          张三            03
1001          赵六..........................
表B有
grbh(个人编号=家庭编号+2位户内编号) xm(姓名) gz(工资)
100001                          张三      1000
100002                          李四      1000
100003                          王五      1000
2张表数据几十W。。。。现在由于之前维护不好,表A的最大编号没有更新,例如表B 1001这户人有4个编号,100101,100102 ,100103,100105这样,但是我表A户内最大编号可能只到了04,而实际上要到05,请问各位大侠如何更新有效率,我自己写了个效率太低了。。。。。
于是写了下面的过程,第一次写,记录一下。
CREATE PROCEDURE update_for_csdner();
  CURSOR v_cursor IS SELECT MAX(substr(grbh, 4, 2)) hnbh, substr(grbh, 0, 4) jtbh from b GROUP BY substr(grbh, 0, 4);
  v_jtbh VARCHAR2(4);
  v_hnbh VARCHAR2(2);
BEGIN
  OPEN v_cursor;
  LOOP
    FETCH v_cursor INTO v_hnbh, v_jtbh;
    EXIT WHEN v_cursor%NOTFOUND;
    UPDATE A SET hnbh = v_hnbh WHERE jtbh = v_jtbh;
    COMMIT;
  END LOOP;
  CLOSE v_cursor;
END;


相关文档:

oracle sql语言模糊查询 通配符like的使用教程

在Where子句中,可以对datetime、char、varchar字段类型的列用Like子句配合通配符选取那些“很像...”的数据记录,以下是可使用的通配符:
%   零或者多个字符
_    单一任何字符(下划线)
\     特殊字符
[]     在某一范围内的字符,如 ......

SQL数据中运行cmd命令

在sql查询分析器里面是不能直接运行cmd命令的
但是SQL给出了一个接口
--打开高级设置
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
--打开xp_cmdshell扩展存储过程
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
首先 打开一些配置
然后执行你要运行cmd命令
exec master..xp_cmdshell 'net star ......

oracle sql 求种菜时间

-- create by zh
-- n 是作物的时间,x 是希望在几点成熟,返回播种的时间
with t as
(
select 64 n,9 x from dual union all
select 64 n,13 x from dual union all
select 64 n,17 x from dual union all
select 64 n,20 x from dual
)
select '成熟时间:'     || lpad(to_char(n),4,' ' ......

在SQL中向多个数据库中插入相同的记录

今天一个朋友问到这个问题,其实很好解决:
declare   @dbname   varchar(50)  
  declare   c_database   cursor   for  
      select   name   from   master.dbo.sysdatabas ......

SQL Lite

SQL Lite
SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine.
It is a open source product and can be downloaded from http://www.sqlite.org/ . SQL Lite is best suited in Smart Client architecture, where we can locally store all ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号