dbTalk Databases Forums  

how to accept a databasename in the input parameters of a procedure

comp.databases.mysql comp.databases.mysql


Discuss how to accept a databasename in the input parameters of a procedure in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
晓磊 贾
 
Posts: n/a

Default how to accept a databasename in the input parameters of a procedure - 12-15-2011 , 12:40 AM






hi,all:

I had used mysql procedure many times before, while how to accept
databasename in the inputparams stll is puzzled.

for instance:

create procedure sync_data_from_old_db(old_db varchar(10), new_db
varchar(10))

insert into old_db.[tablename]
select new_db.[tablename]

end;

I had made some tries, but still failed.
# 1: failed
CREATE PROCEDURE sync_database(db_old varchar(64),db_new varchar(64))
BEGIN
set @db_old=db_old
set @db_new=db_new
INSERT INTO
@db_new.T_XXT_USER(xxt_uid,login,password,name,mob ile,group_id,timestamp,service_id,status,optype,re mind_flag,plan_id)
SELECT
xxt_uid,login,password,name,mobile,group_id,timest amp,service_id,status,
optype,remind_flag,plan_id
FROM @db_old.T_XXT_USER
ON DUPLICATE KEY
UPDATE xxt_uid = VALUES (xxt_uid),
login = VALUES(login),
password = VALUES(password),
name = VALUES(name),
mobile = VALUES(mobile),
group_id = VALUES(group_id),
timestamp = VALUES(timestamp),
service_id = VALUES (service_id),
status = VALUES(status),
optype = VALUES(optype),
remind_flag = VALUES (remind_flag),
plan_id = VALUES(plan_id);
END
//
2: I have once did something about prepare sql query like below, but i
find it so ugly and do not like to use it.

CREATE PROCEDURE copy_sms_log(m_cmpp_id BIGINT(20),num bigint(20))
BEGIN

DECLARE copy_sql varchar(1000) ;
set copy_sql = "insert into T_SMS_LOG
(cmpp_id,mobile,content,inserttime,fetchtime,categ ory,state)
select cmpp_id,mobile,content,inserttime,fetchtime,catego ry,state
from T_SMS_LOG where cmpp_id = ? limit ?";
SET @SQUERY=copy_sql;
SET @fvar=m_cmpp_id;
SET @svar=num;
PREPARE STMT FROM @SQUERY;
EXECUTE STMT using @fvar,@svar;
END
//

Any reply is appreciated Thanks

-- Jia Xiaolei

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.