阅读背景:

mysql 将查询结果拼接输出到本地文件

来源:互联网 
--①第一种
create procedure proc(in stuid int,in stuname VARCHAR(255),in stuage VARCHAR(255))
begin
    declare cnt int ;
    declare  str VARCHAR(255);
    declare  temp VARCHAR(255);
    declare  i int;
    set i = 0;
        set temp = '';
    select count(1) INTO cnt from tb_student;
    IF (cnt < 5) THEN
        insert into tb_student(stuid,stuname,stuage) values(sid,sname,sage);
    ELSE
        WHILE i < 5 DO
            select stuname into str from tb_student LIMIT i,1;
            select concat(temp,str) into str from DUAL ;
            set temp = str ;
            set i = i + 1;
        END WHILE ;
        select str into outfile "C:\job\job.txt";
    END IF;
end

--②第二种
begin
    declare cnt int ;
    declare  str VARCHAR(255);

    select count(1) INTO cnt from tb_student;
    IF (cnt < 5) THEN
        insert into tb_student(stuid,stuname,stuage) values(stuid,stuname,stuage);
    ELSE
        select group_concat(stuname) into str from tb_student;
        select str into outfile "mysqlTest.txt" FIELDS TERMINATED BY ',';
    END IF;
end
--③第三种
repeat  ...... until  i>=5 end repeat ;--①第一种
create procedure proc(in stuid int,in st



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: