29

I have some 800-1200 INSERT statements generated from an excel sheet. I want to run these in TOAD - Oracle db.

If I press F9, it runs only one line and F5 gives me syntax issue and do not seem to work? What am I missing here?

Andrea
  • 11,801
  • 17
  • 65
  • 72
user1191463
  • 395
  • 2
  • 5
  • 12
  • 1
    What is the error? Can you add a small example of the statements that fail? – Jon Heller Feb 07 '12 at 03:57
  • F5, hangs and does nothing, and I need to cancel the operation after a few minutes. F9 on one line with multiple statements separated by ";" gives an error saying there's an invalid character after the first ";" – user1191463 Feb 07 '12 at 04:04
  • 1
    It's been a while since I've used TOAD, but if I remember correctly there are a few cases where its parser doesn't work correctly. For example, the alternative quoting mechanism, e.g. `q'!...!'`, and comments after semicolons. Not sure why F5 would hang, unless it opens another session and is waiting for your current session to commit/rollback? Either way, it would help if you could post a small test case. – Jon Heller Feb 07 '12 at 04:24

10 Answers10

36

F9 executes only one statement. By default Toad will try to execute the statement wherever your cursor is or treat all the highlighted text as a statement and try to execute that. A ; is not necessary in this case.

F5 is "Execute as Script" which means that Toad will take either the complete highlighted text (or everything in your editor if nothing is highlighted) containing more than one statement and execute it like it was a script in SQL*Plus. So, in this case every statement must be followed by a ; and sometimes (in PL/SQL cases) ended with a /.

SQB
  • 3,926
  • 2
  • 28
  • 49
John Doyle
  • 7,475
  • 5
  • 33
  • 40
  • Know why F5 gives output as plain text, while F9 gives output as a spreadsheet or as a new TOAD window for something like a describe statement? – Peter Becich Jun 20 '13 at 22:04
  • @PeterBecich: that's because F5 is being executed in an external program; TOAD doesn't interpret the results which are plain text. F9, on the other hand, is being executed by TOAD directly so it can format the results in a nice grid layout. – Jeffrey Kemp Aug 19 '14 at 03:11
6

Wrap the multiple statements in a BEGIN END block to make them one statement and add a slash after the END; clause.

BEGIN
  insert into books
  (id, title, author)
  values
  (books_seq.nextval, 'The Bite in the Apple', 'Chrisann Brennan');

  insert into books
  (id, title, author)
  values
  (books_seq.nextval, 'The Restaurant at the End of the Universe', 'Douglas Adams');
END;
/

That way, it is just ctrl-a then ctrl-enter and it goes.

CSQ
  • 611
  • 8
  • 7
4

Highlight everything you want to run and run as a script. You can do that by clicking the icon on the menu bar that looks like a text file with a lightning bolt on it. That is the same as hitting F5. So if F5 doesn't work you probably have an error in your script.

Do you have semicolons after each statement?

nolt2232
  • 2,594
  • 1
  • 22
  • 33
3
begin

insert into fiscal_year values(2001,'01-jan-2001','31-dec-2001');
insert into fiscal_year values(2002,'01-jan-2002','31-dec-2002');
insert into fiscal_year values(2003,'01-jan-2003','31-dec-2003');
insert into fiscal_year values(2004,'01-jan-2004','31-dec-2004');

end;

Use like this and then commit.

niemiro
  • 1,778
  • 1
  • 20
  • 37
user3068880
  • 51
  • 2
  • 12
2

I prefer the Execute via SQL*Plus option. It's in the little down-arrow menu under the "Execute as script" toolbar button.

Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
1

Open multiple instances of Toad and execute.

Tony
  • 9,672
  • 3
  • 47
  • 75
skj
  • 15
  • 6
1

You can either go for f5 it will execute all the scrips on the tab.

Or

You can create a sql file and put all the insert statements in it and than give the file path in sql plus and execute.

Harshit
  • 560
  • 1
  • 5
  • 15
1
  1. Just finsih all of your queries with ;
  2. Select all queries you need (inserts, selects, ...).
  3. Push or F5 or F9 both Works.

Not necessary to execute as script

Dave
  • 7,028
  • 11
  • 35
  • 58
0

If you have Multiple Insert Statements then Toad has a simple Way to execute all the Insert Statements.

Right Click On the Highlighted Insert Statements --> Select Execute Menu --> Execute Script

This will automatically start running the Insert Statements

iLearn
  • 991
  • 1
  • 13
  • 27
0
  1. Select all statement make sure you have / at the end of the script.
  2. press F5
  3. check in output script you will be able to see all records in grid
  4. right click on output grid->save file(.txt,.csv) as per requirement.
Purnima
  • 61
  • 3