在Oracle DB 10g中创建包

时间:2018-07-18 06:09:04

标签: sql plsql

我已经创建了过程(例如Insert_stkqntyInsert_receipt),但是假设我想将这些过程放入一个包中,那我该怎么办?

CREATE OR replace PROCEDURE Insert_stkqnty 
    (p_itemid stock_quantity.Item_Id % TYPE, p_date stock_quantity.Date_Received % TYPE, 
     p_supplier stock_quantity.Supplier_Challan % TYPE, p_type stock_quantity.Transaction_Type % TYPE, 
     p_transaction stock_quantity.Transaction_Id % TYPE, p_quantity stock_quantity.Quantity % TYPE) IS
BEGIN
    INSERT INTO stock_quantity (ID, Item_ID, Date_Received, Supplier_Challan, Transaction_Type, Transaction_ID, Quantity)
    VALUES (seq.nextval, p_itemid, p_date, p_supplier, p_type, p_transaction, p_quantity);

    COMMIT;
END;

和另一个

CREATE OR replace PROCEDURE Insert_receipt 
    (p_receipt receipt.Receipt_Number % TYPE, p_transaction receipt.Transaction_Id % TYPE, p_amount receipt.Amount % TYPE) IS
BEGIN
    INSERT INTO receipt (ID, Receipt_Number, Transaction_ID, Amount)
    VALUES (seq.nextval, p_receipt, p_transaction, p_amount);

    COMMIT;
END;

1 个答案:

答案 0 :(得分:0)

我会给你一个例子,看起来像这样:

功能

create or replace package body hamming# is   function distance (
    i_first                                       varchar2    ,i_second                                      varchar2   ) return pls_integer   is
    conta                           pls_integer := 0;
    i                             pls_integer := 0;   begin
    for i in 1 .. least(length(i_first), length(i_second)) loop
      if substr(i_first, i, 1) != substr(i_second, i, 1) then
        conta := conta + 1;
      end if;
    end loop;
    return conta;   end distance; end hamming#;

程序

create or replace package body binary# is   function to_decimal (
    i_binary                                      varchar2   ) return pls_integer   is
    l_pos_fact                      pls_integer := 1;
    l_pos_val                       number(1);
    l_pos                           pls_integer := length(i_binary);
    l_char                          char(1);
    l_decimal                       pls_integer := 0;   begin
    while l_pos > 0 loop
      l_pos_val := substr(i_binary, l_pos, 1);
      if(not l_pos_val between 0 and 1) then
        raise value_error;
      end if;
      l_decimal  := l_decimal + substr(i_binary, l_pos, 1) * l_pos_fact;
      l_pos      := l_pos - 1;
      l_pos_fact := l_pos_fact * 2;
    end loop;
    return l_decimal;   exception
    when value_error then
      return 0;   end to_decimal; end binary#;