/*===
    hello.sql - creates and tests our first PL/SQL subroutine,
                the stored procedure hello_world

    by: Sharon Tuttle
    last modified: 2024-02-08
===*/

/*===
    procedure: hello_world: void -> void
    purpose: expects nothing, returns nothing, and has the
        side-effect of (IF serveroutput is on) printing to
        the screen a cheery greeting and the current date

    examples:
        if it is currently February 7, 2024, and in SQL/Plus you run:
        
        exec hello_world()

        and serveroutput is on, you should see printed to the screen:
Hello, world! on 24-FEB-07

        if you run:
   
        exec hello_world

        and serveroutput is on, you should see printed to the screen:
Hello, world! on 24-FEB-07

===*/

create or replace procedure hello_world as
    curr_date date;
begin
    -- use INTO clause to set local variable curr_date
    --     to what this SELECT projects

    select sysdate
    into curr_date
    from dual;

    dbms_output.put_line('Hello, world! on ' || curr_date);
end;

/*===
    need a FORWARD SLASH /  AFTER the end; of a PL/SQL subroutine creation,
        or it WILL NOT be created and compiled!
    (fun fact: do not put a COMMENT on the same line as the /,
        either!)
===*/

/              

/*===
    need the SQL*Plus command:
        show errors
    if you'd like to SEE any compiler error messages from the
    most-recent attempt to compile a PL/SQL subroutine
    (so a good idea to always put this, also)
===*/

show errors    

/*===
    need the SQL*Plus command:
        set serveroutput on
    if you'd like to see dbms_output.put_line output in your current
    sqlplus session
===*/

set serveroutput on

/*=== TESTING PL/SQL procedure hello_world ===*/

prompt
prompt ============
prompt TESTING hello_world, should see Hello, world! on the current date
prompt (using: exec hello_world() )
prompt

exec hello_world()

prompt ============
prompt TESTING hello_world, should see Hello, world! on the current date
prompt (using: exec hello_world )
prompt

exec hello_world()