Use LOOP to INSERT Data To Table in Oracle

Posted by Agung Pambudi in ,
DECLARE
    firstuser VARCHAR(7) := 'SA3BEUR';
    descuser VARCHAR(4) := 'User';
 
BEGIN
   FOR i IN 1..10 LOOP
        INSERT INTO USER_SCRAPING (USERNAME, PASSWORD, AIRLINE, DESCRIPTION) VALUES (CONCAT(firstuser, i),'RRGHOL0408','Garuda Indonesia',CONCAT(descuser, i));
   END LOOP;
END;



Loop through letters of the alphabet...


DECLARE
    firstuser VARCHAR(11) := 'ONEHOLIDAY-';
    descuser VARCHAR(4) := 'User';
    l char;
BEGIN
   FOR al IN ascii('A')..ascii('Z') LOOP
        l := chr(al);
        INSERT INTO USER_SCRAPING (USERNAME, PASSWORD, AIRLINE, DESCRIPTION) VALUES (CONCAT(firstuser, l),'RRGHOL0807','Lion Air',CONCAT(descuser, l));
   END LOOP;
END;



atau


Loop through letters of the alphabet...

DECLARE
    firstuser VARCHAR(11) := 'ONEHOLIDAY-';
    descuser VARCHAR(4) := 'User';
    l char;
BEGIN
   FOR al IN 65..90 LOOP
        l := chr(al);
        INSERT INTO USER_SCRAPING (USERNAME, PASSWORD, AIRLINE, DESCRIPTION) VALUES (CONCAT(firstuser, l),'RRGHOL0807','Lion Air',CONCAT(descuser, al));
   END LOOP;
END;


No comments:

Post a Comment