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