[转帖]mysql执行脚本报错_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2791 | 回复: 0   主题: [转帖]mysql执行脚本报错        下一篇 
gunrose
注册用户
等级:新兵
经验:36
发帖:79
精华:0
注册:2011-7-21
状态:离线
发送短消息息给gunrose 加好友    发送短消息息给gunrose 发消息
发表于: IP:您无权察看 2014-11-26 9:59:17 | [全部帖] [楼主帖] 楼主

mysql> source D:\jreate_fun_getID.sql
Query OK, 0 rows affected, 1 warning (0.00 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' atline 3
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'DECLARE char_round varchar(6)' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'DECLARE char_return varchar(26)' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL serverversion for the right syntax to use near 'DECLA
RE count TINYINT' at line 1
ERROR 1193 (HY000): Unknown system variable 'count'
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'while
count=1
do
select NOW()+'' into char_now from dual' at line 1
ERROR 1327 (42000): Undeclared variable: char_round
ERROR 1193 (HY000): Unknown system variable 'char_return'
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'if LE
NGTH(char_return)=20 then
select count('x') into count from pk_tbl where' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'if co
unt=0 THEN
insert into pk_tbl (cloum) values(char_return)' at line
1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'end i
f' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'end i
f' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'end w
hile' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'retur
n char_return' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'end'
at line 1


贴出D:\jreate_fun_getID.sql

看上去应该是有 create procedure 语句,但未使用 delimiter //

引用 1 楼 ACMAIN_CHM 的回复:

贴出D:\jreate_fun_getID.sql

看上去应该是有 create procedure 语句,但未使用 delimiter //

drop function if EXISTS getID;#删除方法
#创建获取唯一20位ID的方法
create FUNCTION getID()RETURNS VARCHAR(26)
BEGIN
DECLARE char_now VARCHAR(20);
DECLARE char_round varchar(6);
DECLARE char_return varchar(26);
DECLARE count TINYINT ;
set count=1;
while count=1
do
select NOW()+'' into char_now from dual;
select round(round(rand(),6)*1000000) into char_round from dual;
set char_return=CONCAT(char_now,char_round);
if LENGTH(char_return)=20 then
select count('x') into count from pk_tbl where cloum=char_return;
#判断是否存在
if count=0 THEN
insert into pk_tbl (cloum) values(char_return);
end if;
end if;
end while;
return char_return;
end;


要怎么写 啊

delimiter //
create FUNCTION getID()RETURNS VARCHAR(26)
BEGIN
DECLARE char_now VARCHAR(20);
DECLARE char_round varchar(6);
DECLARE char_return varchar(26);
DECLARE count TINYINT ;
set count=1;
while count=1
do
select NOW()+'' into char_now from dual;
select round(round(rand(),6)*1000000) into char_round from dual;
set char_return=CONCAT(char_now,char_round);
if LENGTH(char_return)=20 then
select count('x') into count from pk_tbl where cloum=char_return;
#判断是否存在
if count=0 THEN
insert into pk_tbl (cloum) values(char_return);
end if;
end if;
end while;
return char_return;
end;
//
delimiter ;


引用 3 楼 ACMAIN_CHM 的回复:

delimiter //
create FUNCTION getID()RETURNS VARCHAR(26)
BEGIN
DECLARE char_now VARCHAR(20);
DECLARE char_round varchar(6);
DECLARE char_return varchar(26);
DECLARE count TINYINT ;
set count=1;
while count=1
do
select NOW()+'' into char_now from dual;
select round(round(rand(),6)*1000000) into char_round from dual;
set char_return=CONCAT(char_now,char_round);
if LENGTH(char_return)=20 then
select count('x') into count from pk_tbl where cloum=char_return;
#判断是否存在
if count=0 THEN
insert into pk_tbl (cloum) values(char_return);
end if;
end if;
end while;
return char_return;
end;
//
delimiter ;


按你说的 我成功了,在cmd里面执行 可以,

还有两个问题帮忙解答下:

1,怎么些批次执行脚本

2 我在可视花窗口执行报错下面的:

mysql> \. D:\jreate_fun_getID.sql;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\. D:\jreate_fun_getID.sql' at line 1
mysql>


把所有的脚本都改正。

修改脚本,在WINDOWS的DOS窗口下

mysql -u -p<D:\jreate_fun_getID.sql;


--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论