oracle学习之第一个存储过程:打印Hello World

数据库对象:表、视图、索引、序列、同义词、存储过程、存储函数
存储过程:指的是存储在数据库中供全部用户程序调用的子程序叫存储过程、存储函数
存储过程和存储函数的同样点:完毕特定功能的程序
存储过程和存储函数的差别:是否用return语句返回值(存储函数能够,可是存储过程不行)


--第一个存储过程:打印Hello World
/*
     调用存储过程2种方式:
     1、exec sayhelloworld();
     2、begin
            sayhelloworld();
            sayhelloworld();
        end;
        /
*/
create or replace procedure sayhelloworld  --假设这个存储过程存在就replace替换否则create创建,这里创建无參数的存储过程
as --不可省略

begin
   dbms_output.put_line('Hello World');--注意不是双引號而是单引號,否则调用存储过程会报错
end;
/


在dos窗体连接oracle数据库方式:sqlplus username/password@127.0.0.1:1521/orcl。或者直接打开sql plus输入username和password
SQL> set serveroutput on
SQL> exec sayhelloworld();
或者:
SQL>begin
         sayhelloworld();
         sayhelloworld();
    end;
    /


原文地址:https://www.cnblogs.com/cynchanpin/p/6973720.html