Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    14

    Unanswered: Trying to run a simple pl\sql anonymous block

    Hi, Im trying to execute a simple block of pl sql, so I can see the output on the screen.

    Firstly I created a file called tmp.sql, in the current directory.

    Code:
    DECLARE 
    amount NUMBER := 0;
    BEGIN
      SELECT COUNT(*)
      INTO amount
      FROM Artist
      WHERE Artist.managedby = 1;
      DBMS_OUTPUT.PUT_LINE(amount);
    END;
    Then on the sql command line i typed:

    SQL> SET SERVEROUTPUT ON

    When I try to execute the command I type:

    @tmp

    and then I press enter and it doesn't run and display the output, it just moves the to the next line like this until i type a full stop and press enter.

    SQL> @tmp
    10
    11
    12
    13
    14
    15
    16
    17
    18 .


    How do you run this code so i can see the output?

    thank you.

  2. #2
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    To tell it to execute, a block must be followed by a "/", use the following code.
    Code:
    DECLARE 
    amount NUMBER := 0;
    BEGIN
      SELECT COUNT(*)
      INTO amount
      FROM Artist
      WHERE Artist.managedby = 1;
      DBMS_OUTPUT.PUT_LINE(amount);
    END;
    /
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  3. #3
    Join Date
    May 2009
    Posts
    14
    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •