当前位置:首页 » 存储配置 » mysql存储过程导入

mysql存储过程导入

发布时间: 2023-05-08 03:42:07

㈠ mysql存储过程怎么传入数组参数

没试过往里面传数组,一般都是多传几个参数,把几个参数放入SqlParameter[]中,然后cmd.Parameters.AddRange(pars);
创建方法:
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@PageIndex","ccc"),
new SqlParameter("@PageSize","ccc"),
new SqlParameter("@StrSql","ccc")
};
ccc就是你想传入的值,带@的就是你在存储过程中定义的参数。
算是一种另类的数组吧。要不你就把所有条件组合成一个字符串,中间用特殊符号隔开,到数据库用split方法再分回来,不过这个方法比较麻烦,不推荐

㈡ SQL Server 存储过程怎么导入Mysql

得首先知道你的角色,你是开发 那最好的办法估计悉袭就是重新写了,毕竟sql server与mysql还是有很大区别的,全部干掉后在mysql中重新写吧。
如果是DBA,那更加只扰消能先干睁李兄掉了,首先作为DBA并不知道业务逻辑,也不清楚sql server与mysql的存储过程的语法规则,而且作为数据库管理层面来看,尽量是不要写存储过程,触发器这类的东东,DBA仅能帮助的或许就是帮忙把数据迁移过来。
其实说白了,真的没什么好的办法,改写吧!

㈢ mysql 存储过程怎么调用

php调用mysql存储过程和函数的方法
存储过程和函数是MySql5.0刚刚引入的。关于这方面的操作在PHP里面没有直接的支持。但是由于Mysql PHP API的设计,使得我们可以在以前的PHP版本中的mysql php api中支持存储过程和函数的调用。

在php中调用存储过程和函数。

1。调用存储过程的方法。

a。如果存储过程有 IN/INOUT参数,声明一个变量,输入参数给存储过程,该变量是一对,

一个php变量(也可以不必,只是没有php变量时,没有办法进行动态输入),一个Mysql

变量。

b。如果存储过程有OUT变量,声明一个Mysql变量。

mysql变量的声明比较特殊,必须让mysql服务器知道此变量的存在,其实也就是执行一条mysql语句。

入set @mysqlvar=$phpvar ;

c。使用mysql_query()/mysql_db_query()执行mysql 变量声明语句。

mysql_query("set @mysqlvar=$pbpvar");

这样,在mysql服务器里面就有一个变量,@mysqlar。如果是IN参数,那么其值可以由phpar传入。

d。 如果是存储过程。

1。执行 call procere()语句。

也就是mysql_query("call proceer([var1]...)");

2. 如果有返回值,执行select @ar,返回执行结果。

mysql_query("select @var)"

接下来的操作就和php执行一般的mysql语句一样了。可以通过mydql_fetch_row()等函数获得结果。

如果时函数。 直接执行 select function() 就可以了。
$host="localhost";
$user="root";
$password="11212";
$db="samp_db";
$dblink=mysql_connect($host,$user,$password)
or die("can't connect to mysql");
mysql_select_db($db,$dblink)
or die("can't select samp_db");
$res=mysql_query("set @a=$password",$dblink);
$res=mysql_query("call aa(@a)",$dblink);
$res=mysql_query("select @a",$dblink);
$row=mysql_fetch_row($res);
echo $row[0];

㈣ mysql 存储过程总结(一)

1、存储过程定义:

存储过程是事先经过编译并存储在数据库中的一段 SQL 语句的集合,调用存储过程可以简化应用开发 人员的很多工作,减少数据在数据库和应用服务器之间的传输,对于提高数据处理的效率是有好处的。 存储过程思想上很简单,就是数据库 SQL 语言层面的代码封装与重用。

2、特点:

封装,复用 : 可以把某一业务SQL封装在存储过程中,需要用到 的时候直接调用即可。

可以接收参数,也可以返回数据 :再存储过程中,可以传递参数,也可以接收返回 值。

减少网络交互,效率提升 : 如果涉及到多条SQL,每执行一次都是一次网络传 输。 而如果封装在存储过程中,我们只需要网络交互一次可能就可以了。

3、基本语法

(1)创建:

(2)调用:

(3)查看:

(4)删除

注意: 在命令行中,执行创建存储过程的SQL时,需要通过关键字 delimiter 指定SQL语句的 结束符。

㈤ mysql sql语句导入excel

1.数据透视视图是处理Excel常用的手段,而应用数据透视视图的第一步就是导入数据,如本例中,表中有889167行数据,那么将这些数据导入Excel表中将是一个很漫长的过程,可以借助SQL语句选择性的导入数据,以此来提交数据加载的速度。

㈥ mysql 存储过程

你应该在做统计吧,估计你不会的就是mysql存储过程的语法 我之前也写过 很是郁闷 我给你一段代码 是我用mysql写过的一个存储过程 你看看 主要是了解里面的语法 看懂了 你所说的需求并不难
有看不懂的地方一起讨论 :
begin

declare tikk datetime ;
declare done int default 0;
declare userid int default 0;
declare moleid int default 0;
declare couid int default 0;
declare mname varchar(255) ;
declare opsid int default 0;

declare c1 cursor for Select I_userID,I_operationID from space_operation_record where status<>0 group by I_userID,I_operationID order by createtime desc;
declare continue handler for sqlstate '02000' set done =1;
set tikk = now();
open c1;
repeat
fetch c1 into userid, opsid;
if not done then
select I_moleID from space_operation where status<>0 and ID=opsid into moleid;
if moleid <> '' then
select Nvc_identification from space_operation where status<>0 and ID=opsid into @identiftion;
if moleid > 0 then
Select Nvc_ename from space_mole where status<>0 and ID=moleid into mname;
else
set mname = 'space';
end if;

create temporary table if not exists sp_tab1(id bigint(20),Nvc_content MEDIUMTEXT,I_obyuID bigint(20),I_tID bigint(20),createtime datetime);
INSERT INTO sp_tab1 Select ID,Nvc_content,I_objectID,I_tmID,createtime from space_operation_record where status<>0 and I_operationID=opsid and I_userID=userid ;
select count(*) from sp_tab1 into couid;

set @ihod = 0;
set @listp = '';
set @listpp = '';
set @content0p = '';
set @content0 = '';
while couid > 0 do
select ID,Nvc_content,I_obyuID,createtime,I_tID into @iok,@conuiy,@objiplk,@crtimhr,@tmids from sp_tab1 where ID > @ihod order by ID asc limit 0,1;
if @iok <> '' then
if mname = 'blog' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,tikk);
elseif mname = 'team' then
if(@identiftion = 'addblog' || @identiftion = 'mdyblog') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listpp = CONCAT(@listpp,CONCAT(@objiplk,','));
set @operarry1p = substring_index(@conuiy,'|',1);
set @operarry2p = substring_index(@conuiy,'|',-1);
set @content0p = CONCAT(@content0p,CONCAT(@operarry2p,SPACE(1)));
set @objlistp = substring(@listpp,1,length(@listpp)-1);
end if;
elseif mname = 'space' then
if(@identiftion = 'headphoto' || @identiftion = 'status') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listppr = CONCAT(@listppr,CONCAT(@objiplk,','));
set @operarry1pr = substring_index(@conuiy,'|',1);
set @operarry2pr = substring_index(@conuiy,'|',-1);
set @content0pr = CONCAT(@content0pr,CONCAT(@operarry2pr,SPACE(1)));
set @objlistpr = substring(@listppr,1,length(@listppr)-1);
end if;
else
set @listp = CONCAT(@listp,CONCAT(@objiplk,','));
set @operarry1 = substring_index(@conuiy,'|',1);
set @operarry2 = substring_index(@conuiy,'|',-1);
set @content0 = CONCAT(@content0,CONCAT(@operarry2,SPACE(1)));
set @objlist = substring(@listp,1,length(@listp)-1);
end if;
set @ihod = @iok;
end if;
set couid = couid -1;
end while;

if @content0 <> '' then
set @contentp = CONCAT(@operarry1,concat('|',@content0));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlist);
end if;
end if;
if @content0p <> '' then
if @identiftion = 'addphoto' then
set @contentp = CONCAT(@operarry1p,CONCAT('|',@content0p));
else
set @contentp = CONCAT(@operarry1p,CONCAT(@content0p,'|'));
end if;

Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
if @content0pr <> '' then
set @contentp = CONCAT(@operarry1p,concat('|',@content0pr));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
delete from sp_tab1;
end if;
end if;

until done end repeat;
close c1;
drop temporary table if exists sp_tab1 ;

UPDATE space_operation_play SET status=0;
UPDATE space_operation_display SET status=0;
Select createtime into @ptimes from space_operation_stat where status<>0 order by createtime desc limit 0,1;
if @ptimes <>'' then
create temporary table if not exists sp_tab2(id bigint(20),Nvc_content MEDIUMTEXT,I_userID bigint(20),I_lyuID bigint(20),D_stattime datetime);
INSERT INTO sp_tab2 Select ID,Nvc_content,I_userID,I_tmID,D_stattime from space_operation_stat where status<>0 and createtime=@ptimes order by D_stattime desc limit 0,30;
select count(*) from sp_tab2 into @cou1id;
set @uoj = 0;
while @cou1id > 0 do
select ID,Nvc_content,I_userID,D_stattime,I_lyuID into @io1k,@conui1y,@objipl1k,@crtimh1r,@unlpa from sp_tab2 where ID > @uoj order by ID asc limit 0,1;
if @io1k <> '' then
INSERT INTO space_operation_play(I_statID,Nvc_content,D_stattime,I_userID,Createtime,I_tmID) VALUES (@io1k,@conui1y,@crtimh1r,@objipl1k,now(),@unlpa);
set @uoj = @io1k;
end if;
set @cou1id = @cou1id -1;
end while;
drop temporary table if exists sp_tab2 ;
end if;

end

㈦ MYSQL如何把存储过程所返回的结果集插入到表

从存储过程返回表类型的值也有二种: 1.存储过程使用浮标参数,即同时指定CURSOR VARYING OUTPUT项.调用者可以使用while及fetch循环遍历该浮标. 2.直接将存储过程返回的结果集插入到表中,即使用insert into 表名 exec 存储过程.此种方式中注意存储过程返回的结果集列与insert的列要完全对应,可以在insert中指定列名来保证对应关系. ------------------------------------------------------------------------------测试:------------------------------------------------------------------------------ ----建立测试用的临时表 create table #tmp (colx int,coly int) insert into #tmp values(1,2) insert into #tmp values(2,3) insert into #tmp values(3,4) select * from #tmpGO----创建返回游标的存储过程 create proc sp_c @cur CURSOR VARYING OUTPUTASbeginset @cur = CURSOR for select colx from #tmp open @cur /*该过程返回游标,该游标为colx列的查询结果*/endGO----创建返回表的存储过程 create proc sp_dasselect coly from #tmp /*该过程返回coly列的查询结果*/go----创建用于调用以上二个存储过程的存储过程 create proc sp_easbegindeclare @x int declare @cur cursor ----接收游标,并遍历游标 EXEC sp_c @cur OUTPUT fetch next from @cur into @x while (@@FETCH_STATUS = 0)beginprint @xfetch next from @cur into @xENDclose @curdeallocate @cur ----将存储过程返回的列值再重新插入源表中 insert into #tmp(coly) EXEC sp_d select * from #tmpendGOEXEC sp_edrop proc sp_c drop proc sp_d

热点内容
电脑主机配置需要哪些硬件 发布:2025-02-10 08:22:52 浏览:706
平板太卡换存储卡有用吗 发布:2025-02-10 08:14:16 浏览:828
台北服务器搭建 发布:2025-02-10 08:13:33 浏览:273
webconfig数据库的连接配置 发布:2025-02-10 08:13:24 浏览:966
dell服务器背板什么意思 发布:2025-02-10 08:11:08 浏览:100
桑塔纳全秀和半袖哪个配置高 发布:2025-02-10 07:55:42 浏览:350
手纹算法 发布:2025-02-10 07:52:27 浏览:39
爱奇艺怎么看账号密码 发布:2025-02-10 07:51:43 浏览:352
破解访问权限 发布:2025-02-10 07:17:24 浏览:664
庆余年密码多少 发布:2025-02-10 07:16:38 浏览:202