如何迁移'输入a_double表是'从Oracle到SQL Server

时间:2015-02-12 12:36:13

标签: sql-server oracle

如何迁移以下具有以下数据类型的Oracle代码  1. pkg_taxcalc_client.a_number  2. pkg_taxcalc_client.a_double  3. pkg_taxcalc_client.a_varchar 请帮助我并指导我在sql server中的相同内容以及如何编写..

create or replace 
PACKAGE PKG_TAXCALC_CLIENT
as
    type a_double is table of number(14,2) index by binary_integer;
    type a_number is table of number index by binary_integer;
    type a_varchar is table of varchar2(50) index by binary_integer;

procedure usp_CreateItemsTLine      (@p_ItemId in pkg_taxcalc_client.a_number ,        -- will be token
                                     @p_ItemClientId in pkg_taxcalc_client.a_number,
                                     @p_GroupId in int ,
                                     @p_ValueBeforeTax in pkg_taxcalc_client.a_double ,
                                     @p_TaxValue in pkg_taxcalc_client.a_double  ,
                                     @p_TaxId in pkg_taxcalc_client.a_number ,
                                     @p_TaxName in pkg_taxcalc_client.a_varchar ,
                                     @p_SequenceNumber in pkg_taxcalc_client.a_number ,
                                     @p_IsAbsolute in pkg_taxcalc_client.a_number ,
                                     @p_Precedence0 in pkg_taxcalc_client.a_number ,
                                     @p_Precedence1 in pkg_taxcalc_client.a_number ,
                                     @p_Precedence2 in pkg_taxcalc_client.a_number ,
                                     @p_Items out sys_refcursor,
                                     @p_IsError out int)
as
    @v_IsTrans int;
    @v_Count int;
    @v_ItemExists int;
    @v_ErrorCode  pls_integer;
    @v_ItemIdList varchar2(20);
    @v_ItemId int;
    @v_ItemCount int;
    @v_Items pkg_taxcalc_client.a_number;
    @v_Sql varchar2(1000);
begin
    @p_IsError := 0;
    @v_IsTrans := 0;
    @v_Count := 1;
    @v_ItemExists := 0;

    for @v_ItemCount in 1 .. @p_ItemId.count
    loop

         @v_ErrorCode :=1;
         select count(0)
         into  @v_ItemExists
         from  tbl_taxcalc_items/**chk name**/
         where ItemId = @p_ItemId(@v_ItemCount);    -- check if the item is present with current item id

         @v_ErrorCode :=2;
         if @v_ItemExists = 0 and ( @p_ItemId(@v_Count) = null or @p_ItemId(@v_Count) = 0) then    -- if not then insert it.this is new item id

             @v_ErrorCode := 3;
             if @p_ItemId(@v_Count) = null or @p_ItemId(@v_Count) = 0 then          -- if the ItemId(token value) being sent is null then auto generate the ItemId.

                 select seq_taxcalc_ItemId.nextval      --  auto generated item id (token value) is put in the @v_ItemId.
                 into   @v_ItemId
                 from   dual;

             else                                        -- else if not nulluse the inputed ItemId and perform insert

                @v_ItemId := @p_ItemId(@v_Count);

             end if;

             @v_ErrorCode :=4;
             @v_IsTrans := 1;
             insert into tbl_taxcalc_items/**chk name**/ (ItemId ,                    --- insert into item tables all the values jst entered
                                           GroupId ,
                                           ValueBeforeTax ,
                                           ItemClientId,
                                           TotalTax ,
                                           ValueAfterTax ,
                                           Active ,
                                           Show)
             values (@v_ItemId ,
                     @p_GroupId ,
                     @p_ValueBeforeTax(@v_ItemCount) ,
                     @p_ItemClientId(@v_ItemCount) ,
                     0 ,
                     0 ,
                     0 ,
                     0);
         end if;

         @v_ErrorCode :=5;

         if @v_ItemExists = 1 then           -- if it (item) exists then update it.

             @v_ItemId := @p_ItemId(@v_ItemCount);  -- current item id
             @v_IsTrans :=1;
             @v_ErrorCode :=6;

             update tbl_taxcalc_items/**chk name**/                   --- update into item tables all the values jst entered including the auto generated item id
             set    GroupId = @p_GroupId ,
                    ValueBeforeTax = @p_ValueBeforeTax(@v_ItemCount),
                    TotalTax = 0 ,
                    ValueAfterTax = 0 ,
                    Active  = 0 ,
                    Show    = 0
             where  ItemId = @v_ItemId ;

         end if;

         @v_ErrorCode :=7;

         delete                                   -- for an updated item id delete all the contents in the itemlines and insert new values as done below
         from   tbl_taxcalc_itemlines_invalid/**chk name**/             -- for a new item id the values will be not present as it is.
         where  ItemId = @v_ItemId;

         @v_ErrorCode :=8;

         for @v_Count in 1 .. @p_SequenceNumber.count
         loop

             @v_ErrorCode :=9;

             if @p_SequenceNumber(@v_Count) is null then
                 exit;
             end if;

             insert into tbl_taxcalc_itemlines_invalid/**chk name**/ (ItemId ,
                                                        TaxId ,
                                                        TaxName ,            --- insert in itemlines table whether a new item id or an existing one.
                                                        TaxValue ,
                                                        SequenceNumber ,
                                                        IsAbsolute ,
                                                        Precedence0 ,
                                                        Precedence1 ,
                                                        Precedence2)
             values (@v_ItemId,
                     @p_TaxId(@v_Count),
                     @p_TaxName(@v_Count) ,
                     @p_TaxValue(@v_Count) ,
                     @p_SequenceNumber(@v_Count) ,
                     @p_IsAbsolute(@v_Count)  ,
                     @p_Precedence0(@v_Count) ,
                     @p_Precedence1(@v_Count) ,
                     @p_Precedence2(@v_Count));

         end loop;

         @v_ErrorCode :=9;
         @v_Items(@v_ItemCount) := @v_ItemId;       -- @v_Items is sent to calculate tax so update the item ids in it.

    end loop;

    @v_ErrorCode :=10;

    usp_calculate_tax(@v_Items,@p_IsError);                -- calculate tax procedure is called with @v_Items array

    @v_ErrorCode :=11;

    @v_ErrorCode :=12;

    for @v_ItemCount in 1 .. @v_Items.count
    loop

        @v_ErrorCode :=13;
        @v_ItemIdList := @v_ItemIdList || ',' || @v_Items(@v_ItemCount);

    end loop;

1 个答案:

答案 0 :(得分:0)

    USE [Custom]
    GO

    /****** Object:  UserDefinedTableType [dbo].[tblNumbers]    Script Date: 04/02/2015 11:15:59 ******/
    CREATE TYPE [dbo].[tblNumber] AS TABLE(
        [Number] [int] NULL
    )
    GO

    USE [Custom]
    GO

    /****** Object:  UserDefinedTableType [dbo].[tblNumbers]    Script Date: 04/02/2015 11:15:59 ******/
    CREATE TYPE [dbo].[tblVarchar] AS TABLE(
        [Varchar] [Varchar](50) NULL
    )
    GO

    USE [Custom]
    GO

    /****** Object:  UserDefinedTableType [dbo].[tblNumbers]    Script Date: 04/02/2015 11:15:59 ******/
    CREATE TYPE [dbo].[tblDecimal] AS TABLE(
        [Decimal] [Decimal](14,2) NULL
    )
    GO
-------------------------------------------------------------------------------------------
CREATE PROCEDURE uspTaxCalcCreateItemsTLine
(
    @p_ItemId as dbo.tblNumber readonly,
    @p_ItemClientId as dbo.tblNumber readonly,
    @p_GroupId int,
    @p_ValueBeforeTax as dbo.tblDecimal readonly,
    @p_TaxValue as dbo.tblDecimal readonly,
    @p_TaxId dbo.tblNumber readonly,--------
    @p_TaxName dbo.tblVarchar readonly,
    @p_SequenceNumber dbo.tblNumber readonly,
    @p_IsAbsolute dbo.tblNumber readonly,
    @p_Precedence0 dbo.tblNumber readonly,
    @p_Precedence1 dbo.tblNumber readonly,
    @p_Precedence2 dbo.tblNumber readonly,
    @p_Precedence3 dbo.tblNumber readonly,
    @p_Precedence4 dbo.tblNumber readonly,
    @p_Precedence5 dbo.tblNumber readonly,
    @p_Precedence6 dbo.tblNumber readonly,
    @p_Precedence7 dbo.tblNumber readonly,
    @p_Precedence8 dbo.tblNumber readonly,
    @p_Precedence9 dbo.tblNumber readonly,
    @p_Precedence10 dbo.tblNumber readonly,
    @p_Precedence11 dbo.tblNumber readonly,
    @p_Precedence12 dbo.tblNumber readonly,
    @p_Precedence13 dbo.tblNumber readonly,
    @p_Precedence14 dbo.tblNumber readonly,
    @p_Precedence15 dbo.tblNumber readonly,
    @p_Precedence16 dbo.tblNumber readonly,
    @p_Precedence17 dbo.tblNumber readonly,
    @p_Precedence18 dbo.tblNumber readonly,
    @p_Precedence19 dbo.tblNumber readonly,
    @p_IsError int out
)
AS