假設你有權創建和執行存儲過程,你可以這樣做:
awoolford$ mysql -u root -p
Enter password:
mysql> use test;
mysql> delimiter //
mysql> CREATE PROCEDURE createDateRange (IN startDate DATE, IN endDate DATE)
-> BEGIN
-> DECLARE currentDate DATE;
-> SET currentDate := startDate;
-> DROP TABLE IF EXISTS dateRange;
-> CREATE TABLE dateRange(`date` date);
-> WHILE currentDate <= endDate DO
-> INSERT INTO dateRange VALUES (currentDate);
-> SET currentDate := DATE_ADD(currentDate, INTERVAL 1 DAY);
-> END WHILE;
-> END//
mysql> delimiter ;
mysql> CALL createDateRange('2015-04-24', '2015-05-01');
Query OK, 1 row affected (0.01 sec)
mysql> select * from dateRange;
+------------+
| date |
+------------+
| 2015-04-24 |
| 2015-04-25 |
| 2015-04-26 |
| 2015-04-27 |
| 2015-04-28 |
| 2015-04-29 |
| 2015-04-30 |
| 2015-05-01 |
+------------+
8 rows in set (0.00 sec)
您是否有權在數據庫中創建對象(例如,表,存儲過程)還是隻能執行select語句? –
@AlexWoolford沒有先生。我只能執行select語句。 – jclima05