Re: A PL\SQL Questions

From: SteveC <carnwath_at_synygy.com>
Date: 8 Aug 2001 07:29:51 -0700
Message-ID: <cea788de.0108080629.3b4fe916_at_posting.google.com>


seems a bit more complex than need be (by using a cursor)... try

declare
 custct number(10,0);
begin
  Select count(*) into custct from customer_accounts;   dbms_output.put_line('The number of cusomter accounts is: ' || custct); end;

simple is good :)

oratune_at_msn.com (David Fitzjarrell) wrote in message news:<32d39fb1.0108061313.2ab5be96_at_posting.google.com>...
> Let's make that:
>
> dbms_output.put() and dbms_output.put_line()
>
> The first will output text without a newline character, allowing you
> to build output text of variable length (within the confines of the
> package limitations) whereas the second outputs text WITH a newline.
>
> Examples:
>
> rem
> rem DBMS_OUTPUT.PUT_LINE example
> rem
>
> rem
> rem Enable output
> rem
>
> set serveroutput on size 1000000
>
> declare
> --
> -- Declare cursor to return count of
> -- valid customer accounts
> --
> cursor custaccts is
> select count(*)
> from customer_accounts;
>
> --
> -- Variable to 'hold' returned count
> --
> custct number:=0;
> begin
> --
> -- Open the cursor
> --
> open cursor custaccts;
> --
> -- Fetch the value into the declared variable
> --
> fetch custaccts into custct;
> --
> -- Close the cursor
> --
> close custaccts;
>
> --
> -- Output the results to the terminal
> --
> dbms_output.put_line('The number of customer accounts is:
> '||custct);
> end;
> /
>
>
> rem
> rem DBMS_OUTPUT.PUT example
> rem
>
> rem
> rem Enable output
> rem
>
> set serveroutput on size 1000000
>
> declare
> --
> -- Declare cursor to return count of
> -- valid customer accounts
> --
> cursor custaccts is
> select count(*)
> from customer_accounts;
>
> --
> -- Variable to 'hold' returned count
> --
> custct number:=0;
>
> --
> -- Variable to 'hold' current date/time
> --
> currdt date;
> begin
> --
> -- Open the cursor
> --
> open cursor custaccts;
> --
> -- Fetch the value into the declared variable
> --
> fetch custaccts into custct;
> --
> -- Close the cursor
> --
> close custaccts;
>
> --
> -- Get current date
> --
> select sysdate into currdt from dual;
>
> --
> -- Output the results to the terminal
> --
> dbms_output.put('The number of customer accounts is: '||custct);
> dbms_output.put_line(' for period ending: '||currdt);
> end;
> /
>
>
> David Fitzjarrell
>
>
> "Steve Long" <slong3_at_mediaone.net> wrote in message news:<DNyb7.164$PE5.41026_at_typhoon.jacksonville.mediaone.net>...
> > look up dbms.output and dbmsw.putline
> >
> > "Frank" <fcolon_at_onebox.com> wrote in message
> > news:3271719f.0108031221.77749dec_at_posting.google.com...
> > > Quick question....is there a way to get a PL\SQL query to print some text?
> > >
> > > For example, if I had the query:
> > >
> > > Select count(*) from customer_accounts; (will return a count of 10)
> > >
> > > How can I change that query so that the following prints out:
> > >
> > > The number of cusomter accounts is: 10
> > >
> > > Thanks.
> > >
> > > --Frank
> > >
> > > P.S. Do you know of any good PL\SQL resources on the net?
Received on Wed Aug 08 2001 - 16:29:51 CEST

Original text of this message