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

MySql 存储过程使用游标循环插入数据示例

本示例通过 while...end while 循环控制游标来实现插入表记录。
DROP PROCEDURE IF exists pro_initCategoryForTradingEntity;
create procedure pro_initCategoryForTradingEntity(tradingEntityId int)
begin
    declare f_parent,entityId  int;
    declare b int default 0;    /*是否达到记录的末尾控制变量*/
    declare f_name varchar(100);   
    DECLARE cur_1 CURSOR FOR select FName,FParent,tradingEntityId from t_category_tag;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
    OPEN cur_1;
    FETCH cur_1 INTO f_name, f_parent, entityId; /*获取第一条记录*/
    while b<>1 do           
        insert into t_category(FName,FParent,FTradingEntity)  values(f_name, f_parent, entityId);
        FETCH cur_1 INTO f_name, f_parent, entityId; /*取下一条记录*/
    end while;
    close cur_1;       
end;
call pro_initCategoryForTradingEntity(2);
另外循环也可以用repeat...end repeat 来循环控制,以下是我最初所做的示例代码,但结果是插入的实际数据总数多出一条,在此列出作为一个反面示例代码。当然最后用的是上面while...end while 方案。
DROP PROCEDURE IF exists pro_initCategoryForTradingEntity;
create procedure pro_initCategoryForTradingEntity(tradingEntityId int)
begin
        declare f_parent,entityId,b  int;
    declare f_name varchar(100);
    DECLARE cur_1 CURSOR FOR select FName,FParent,tradingEntityId from t_category_tag;
    DECLARE CONTINUE HANDLER FOR NOT FOUND
    SET b = 1;
    OPEN cur_1;
    REPEAT
        FETCH cur_1 INTO f_name, f_parent, entityId;
 &


相关文档:

mysql数据库备份与还原

mysql数据库备份与还原命令:
备份:
如我们需要把 数据库名为:shopping 的数据库备份: 用户名为:root,密码为:12345,那么命令如下:
直接进入dos,如果没有配置mysql的环境变量,那么需要把dos的当前目录切换到mysql的bin目录下,然后敲入一下命令:
        mysqldump -uroo ......

linux下解决mysql的字符编码问题

http://hi.baidu.com/emersonm/blog/item/ee230a36ca566fd7a2cc2b4a.html
linux下解决mysql的字符编码问题
2009-10-06 21:03
mysql的字符编码是比繁琐的事情,我用的fedora11默认安装mysql5.1
$mysql --user=root --password=布拉布拉布拉
进入后
mysql>show variables like 'character%';     ......

mysql 删除表中的重复记录,只保留其中一条

查询重复记录 select * from table GROUP BY name 
只把有重复的显示出来
select * ,count(*) as nums from tab_a group by name having nums>1
方法一:(这个方法比较不错,只是自增字段会重建)
  新建一个临时表  
  create   table   tmp   as   select   * &nb ......

Mysql 分区相关资源


Mysql 分区相关资源
http://www.bigheaddba.net/article/y2009/339_mysql%E5%88%86%E5%8C%BA%E8%A1%A8%E5%B1%80%E9%99%90%E6%80%A7%E6%80%BB%E7%BB%93.html
http://www.ooso.net/archives/217
http://dev.mysql.com/doc/refman/5.1/zh/partitioning.html#partitioning-range
http://hi.baidu.com/zhangguanshi/blog/i ......

linux下mysql5安装日志

step 1)下载源代码包到本地Linux主机,然后解压缩,进入该目录,进行配置,编译和安装
下载mysql5源码mysql-5.0.18.tar.gz到目录/usr/local
cd /usr/local
tar xzvf mysql-5.0.18.tar.gz
cd mysql-5.0.18
./configure --prefix=/usr/local/mysql
make && make install
make过程花的时间比较长
step 2)配置 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号