[firebase-br] vários linhas de insert

Alexandre Pereira Bühler alexandre em simaoebuhler.com.br
Qui Set 25 16:48:13 -03 2014


Não sei se é oque você quer:
fonte: http://www.firebirdfaq.org/faq336/


  How to insert multiple rows in a single statement?


There are various approaches. For example, if you wish to insert these:

2 two
4 four
5 five

you can use UNIONs:

INSERT INTO table1 (col1, col2)
SELECT 2, 'two ' FROM RDB$DATABASE UNION ALL
SELECT 4, 'four' FROM RDB$DATABASE UNION ALL
SELECT 5, 'five' FROM RDB$DATABASE;

Please note that datatypes must match, esp. if you use Firebird 1.x. In 
the above example, 'four' and 'five' are varchar(4), while 'two' would 
evaluate to varchar(3) and you would get an error with Firebird 1.x. To 
work around this, you can use CAST or, in this case, add anoter space 
after the word: two, to make it 'two '.

You can also use EXECUTE BLOCK (with Firebird 2.0 and above):

set term ^ ;
EXECUTE BLOCK AS BEGIN
INSERT INTO table1 (col1, col2) VALUES (2, 'two');
INSERT INTO table1 (col1, col2) VALUES (4, 'four');
INSERT INTO table1 (col1, col2) VALUES (5, 'five');
END^


Do you find this FAQ incorrect or incomplete? Please e-mail 
<mailto:faq em firebirdfaq.org> us what needs to be changed. To ensure 
quality, each change is checked by our editors (and often tested on live 
Firebird databases), before it enters the main FAQ database. If you 
desire so, the changes will be credited to your name. To learn more, 
visit our add content <http://www.firebirdfaq.org/addContent.php> page.

If you are a commercial tool maker and your tool features a great way to 
handle the issue written about in this FAQ, please check out our 
advertisement <http://www.firebirdfaq.org/marketing.php> page.



All contents are copyright © 2007-2014 FirebirdFAQ.org unless otherwise 
stated in the text.


Alexandre Pereira Bühler
Linux User: 397.546

Simão &  Bühler Ltda (Infobrindes)
http://www.simaoebuhler.com.br
alexandre em simaoebuhler.com.br
Telefone: (41) 3039-5428

Infobrindes (Simão &  Bühler Ltda)
Brindes e material promocional.
http://www.infobrindes.com.br
karin em infobrindes.com.br
Telefone: (41) 3082-8667






Mais detalhes sobre a lista de discussão lista