1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[sql]
DELIMITER //
DROP
PROCEDURE
IF EXISTS uppercase //
CREATE
PROCEDURE
uppercase(
IN
dbname
VARCHAR
(200))
BEGIN
DECLARE
done
INT
DEFAULT
0;
DECLARE
oldname
VARCHAR
(200);
DECLARE
cur
CURSOR
FOR
SELECT
table_name
FROM
information_schema.TABLES
WHERE
table_schema = dbname;
DECLARE
CONTINUE
HANDLER
FOR
NOT
FOUND
SET
done = 1;
OPEN
cur;
REPEAT
FETCH
cur
INTO
oldname;
SET
@newname =
UPPER
(oldname);
#IF newname equals
to
oldname, do nothing;
#
select
'a'
<>
'A'
; -> 0
#
select
'a'
<>
BINARY
'A'
; -> 1
SET
@isNotSame = @newname <>
BINARY
oldname;
IF
NOT
done && @isNotSame
THEN
SET
@SQL = CONCAT(
'rename table '
,oldname,
' to '
,@newname);
PREPARE
tmpstmt
FROM
@SQL;
EXECUTE
tmpstmt;
DEALLOCATE
PREPARE
tmpstmt;
END
IF;
UNTIL done
END
REPEAT;
CLOSE
cur;
END
//
DELIMITER ;
#調用存儲過程
#call uppercase(
'數據庫名'
);
#