declare a variable in mysql

i have created a script to insert 100K rows into mysql db.

But the forst line where i declare the variable is giving error. I am new to mysql. Can anyone help me in this?

the script is

======================================
DECLARE
c INT(10) := 54;
BEGIN
WHILE c < 100 LOOP
insert into CLDB (COMPID, COMPONENT, COMPONENT_DATA) values(c,'A000000'.c,'C_Subscription');
commit;
c := c + 1;
END LOOP;
WHILE c < 1000 LOOP
insert into CLDB (COMPID, COMPONENT, COMPONENT_DATA) values(c,'A00000'.c,'C_Subscription');
commit;
c := c + 1;
END LOOP;
WHILE c < 10000 LOOP
insert into CLDB (COMPID, COMPONENT, COMPONENT_DATA) values(c,'A0000'.c,'C_Subscription');
commit;
c := c + 1;
END LOOP;
WHILE c < 100000 LOOP
insert into CLDB (COMPID, COMPONENT, COMPONENT_DATA) values(c,'A000'.c,'C_Subscription');
commit;
c := c + 1;
END LOOP;
WHILE c < 1000054 LOOP
insert into CLDB (COMPID, COMPONENT, COMPONENT_DATA) values(c,'A00'.c,'C_Subscription');
commit;
c := c + 1;
END LOOP;
END;
/

What language is this script written in? To my knowledge, mySQL has no scripting language as such.

Hi amitranjansahu,

I have never written a mysql script. I would like to know how you are running this script?

I have a suggestion.

Instead of

DECLARE c INT(10) := 54;

try

DECLARE c INT(10) DEFAULT 54

latter i came to know that no scrpting is there in mysql.So populate the db with 100K rows i had to write a procedure and its working

=========================

DELIMITER $$

DROP PROCEDURE IF EXISTS `AMITDB`.`test_proc3` $$
CREATE PROCEDURE `test_proc3`(IN c INT)
begin
while c < 1000001 do
insert into AMITDB (ID, COMPONENT, COMPONENT_TYPE) values(c,c,'AMIT_ALCATEL');
set c=c+1;
end while;
END $$

DELIMITER ;

cool :slight_smile: