廣告聯播

顯示具有 PL/SQL 標籤的文章。 顯示所有文章
顯示具有 PL/SQL 標籤的文章。 顯示所有文章

2012年2月18日 星期六

PL/SQL Function 函數建立說明

From: Polin Wei

建立子程序的語法有以下幾個重點:

  • 語法是CREATE PROCEDURE,可加入OR REPLACE來自動取代現有的子程序。
  • IS保留字也可以改成AS。
  • 跟合法的區塊語法一樣,BEGIN和END也是必須的,但不用DECLARE來宣告,只要在CREATE PROCEDURE...IS 之後宣告即可。

當您提交一個CREATE PROCEDURE指令到SQL*Plus後,會發生以下事情:

  • 程式碼會儲存在Data Dictionary,無論程式碼是否解析成功,可以從VIEW:USER_OBJECTS 查詢。
  • 程式碼的語法會被解析,然後決定它是「合法」(VALID)還是「不合法」(INVALID)。
  • 如果是VALID,就會得到Procedure created的訊息,而子程序也可以被執行。
  • 如果是INVALID,就會得到錯誤訊息,這時子程序不可以被執行。

PL/SQL Function 建立的語法如下:

 

1
2
3
4
5
6
7
8
9
10
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [function_name];

傳入的參數有三種型態:

  • IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
  • OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
  • IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.
繼續閱讀

2011年12月21日 星期三

PL/SQL Procedure 程序建立說明

From: Polin Wei

建立 PL/SQL Procedure

建立子程序的語法有以下幾個重點:

  • 語法是CREATE PROCEDURE,可加入OR REPLACE來自動取代現有的子程序。
  • IS為保留字。
  • 跟合法的區塊語法一樣,BEGIN和END也是必須的,但不用DECLARE來宣告,只要在CREATE PROCEDURE...IS 之後宣告即可。

當您提交一個CREATE PROCEDURE指令到SQL*Plus後,會發生以下事情:

  • 程式碼會儲存在Data Dictionary,無論程式碼是否解析成功,可以從VIEW:USER_OBJECTS 查詢。
  • 程式碼的語法會被解析,然後決定它是「合法」(VALID)還是「不合法」(INVALID)。
  • 如果是VALID,就會得到Procedure created的訊息,而子程序也可以被執行。
  • 如果是INVALID,就會得到錯誤訊息,這時子程序不可以被執行。

PL/SQL Procedure 建立的語法如下:
CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];


傳入的參數有三種型態:

  1. IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
  2. OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
  3. IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.
參考: MIS Workplace By Polin Wei

2010年12月21日 星期二

PL/SQL Control Statements 控制語法

From: Polin Wei

PL/SQL 在程式語法中對於狀態的判別有兩個語法可作判別:IF 與 CASE 語法 (statements):


IF statements 語法使用方法有下列幾個方式:

IF-THEN Statement

IF condition THEN
sequence_of_statements
END IF;

IF-THEN-ELSE Statement

IF condition THEN
sequence_of_statements1
ELSE
sequence_of_statements2
END IF;

IF-THEN-ELSIF Statement

IF condition1 THEN
sequence_of_statements1
ELSIF condition2 THEN
sequence_of_statements2
ELSE
sequence_of_statements3
END IF;

IF-THEN-ELSE 的例子


WordPress 架站必備外掛