1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Loop MySQL to insert data in table

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 27, 2024 às 18:12.

  1. Stack

    Stack Membro Participativo

    I'm trying to insert data in a database for assign an id to each number

    table numbers

    id | number

    1 | 2560
    2 | 2561


    And this go on for 100 numbers. I found this for PL/SQL

    BEGIN
    FOR v_LoopCounter IN 2560..2660 LOOP
    INSERT INTO numbers (number)
    VALUES (v_LoopCounter);
    END LOOP;
    END;


    Also tried like

    BEGIN
    FOR v_LoopCounter IN 2560.2660 LOOP;
    INSERT INTO numbers (number);
    VALUES (v_LoopCounter);
    END LOOP;
    END;


    How can I do this in SQL using phpMyAdmin, for that's what I can use? I tried it but I get this error:


    There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

    I also have tried now

    SELECT * FROM table_name WHERE
    BEGIN
    FOR v_LoopCounter IN 2560..2660 LOOP
    INSERT INTO numbers (number)
    VALUES (v_LoopCounter);
    END LOOP;
    END;

    Continue reading...

Compartilhe esta Página