aes_cursor

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[aes_sessionschedule]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[aes_sessionschedule]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE procedure dbo.aes_sessionschedule
as
--
   declare @suser_sname nvarchar(50)
   declare @getdate nvarchar(50)
--
   declare @ID nvarchar(50)
   declare @ApplicationID nvarchar(50)
   declare @Program nvarchar(50)
   declare @ResourceID nvarchar(10)
   declare @ResourceGroupID nvarchar(10)
   declare @FamilyID nvarchar(10)
   declare @HHID nvarchar(10)
   declare @SecurityID nvarchar(10)
   declare @SecurityGroupID nvarchar(10)
   declare @SecurityOrgID nvarchar(10)
   declare @SecurityRegionID nvarchar(10)
   declare @SecurityMode nvarchar(50)
   declare @ValidFrom nvarchar(50)
   declare @ValidTo nvarchar(50)
   declare @Mon bit
   declare @Tue  bit
   declare @Wed bit
   declare @Thu bit
   declare @Fri bit
   declare @Sat bit
   declare @Sun bit
   declare @Day int
   declare @RightDay int
   declare @ActivityKey nvarchar(10)
--
   declare @KeyValue int
   declare @ActivityNumber nvarchar(10)
   declare @ActivityDetailsNumber nvarchar(10)
   declare @SourceID nvarchar(050)
   declare @Counts int
--
   declare @ExitKey nvarchar(10)
   declare @CountActivityDetails int
   declare @CountActivity int
   declare @error int
   declare @rowcount int
   declare @Activity nvarchar(50)
   declare @MilestoneStatusKey  nvarchar(50)
--
begin
--
   set @suser_sname = suser_sname()
-- ********************************************************************************
-- testing
--   set @getdate = convert(nvarchar,dateadd(day,1,getdate()),101)
-- ********************************************************************************
-- set @getdate = convert(nvarchar,dateadd(day,0,getdate()),101)
-- ********************************************************************************
   set @getdate=cast(datepart(mm,getdate())  as nvarchar)+'/'+cast(datepart(dd,getdate()) as nvarchar)+'/'+cast(datepart(yyyy,getdate()) as nvarchar)

declare
   C_sessionschedule
      cursor
   for
      select
         [Application].[ID],
         [Application].[ApplicationID],
         [Application].[Program],
         [Application].[ResourceID],
         [Application].[ResourceGroupID],
         [Application].[FamilyID],
         [Application].[HouseHoldID],
         [Application].[SecurityID],
         [Application].[SecurityGroupID],
         [Application].[SecurityOrgID],
         [Application].[SecurityRegionID],
         [Application].[SecurityMode],
         [AutoSchedule].[ValidFrom],
         [AutoSchedule].[ValidTo],
         isnull([AutoSchedule].[Mon],0) as Mon,
         isnull([AutoSchedule].[Tue],0) as Tue,
         isnull([AutoSchedule].[Wed],0) as Wed,
         isnull([AutoSchedule].[Thu],0) as Thu,
         isnull([AutoSchedule].[Fri],0) as Fri,
         isnull([AutoSchedule].[Sat],0) as Sat,
         isnull([AutoSchedule].[Sun],0) as Sun,
         datepart(dw,getdate())as [Day],
         [AutoSchedule].[ActivityKey],
         isnull([AutoSchedule].[MilestoneStatusKey],'') as MilestoneStatusKey,
         [ActivityTemplate].[Service] as Activity        
      from
         [Application],
         [AutoSchedule],
         [ActivityTemplate]
      where
         [Application].[ApplicationID] = [AutoSchedule].[ApplicationID] and
         [ActivityTemplate].EligibilityDescriptionKey=[AutoSchedule].[ActivityKey] and
         [Application].[Active] = 1 and
         [AutoSchedule].[Daily_Session]='Session' and
         ([AutoSchedule].[ValidFrom] is not null or [AutoSchedule].[ValidFrom] <>'')  and
         ([AutoSchedule].[ValidTo] is not null or  [AutoSchedule].[ValidTo]<>'') and
         datediff(day, isnull([AutoSchedule].[ValidFrom],'1/1/1900'), @getdate) >= 0 and
         datediff(day, @getdate, isnull([AutoSchedule].[ValidTo],'1/1/1900')) >= 0
-- ********************************************************************************
   open C_sessionschedule
      fetch
         next
      from
         C_sessionschedule
      into
         @ID,
         @ApplicationID,
         @Program,
         @ResourceID,
         @ResourceGroupID,
         @FamilyID,
         @HHID,
         @SecurityID,
         @SecurityGroupID,
         @SecurityOrgID,
         @SecurityRegionID,
         @SecurityMode,
         @ValidFrom,
         @ValidTo,
         @Mon,
         @Tue,
         @Wed,
         @Thu,
         @Fri,
         @Sat,
         @Sun,
         @Day,
         @ActivityKey,
         @MilestoneStatusKey,
         @Activity
--
      set @rowcount=0
      while
         (@@fetch_status = 0)
      begin
-- ********************************************************************************
-- check for [ActivityDetails] row
-- ********************************************************************************
         select
            @CountActivityDetails = count(*)
         from
            [ActivityDetails]
         where
            [ApplicationID] = @ApplicationID and
            [ID] = @ID and
            [Activity] = @Activity and
            [ActivityType] = 'Session' and
            [ActivityKey]=@ActivityKey and
            [StartDate] = @getdate
         if
            @CountActivityDetails = 0
         begin

--Check schedule
             set @RightDay=0
 if @Day=1 and @Sun=1
    set @RightDay=1
 else if @Day=2 and @Mon=1
    set @RightDay=1
 else if @Day=3 and @Tue=1
    set @RightDay=1
 else if @Day=4 and @Wed=1
    set @RightDay=1
 else if @Day=5 and @Thu=1
    set @RightDay=1
 else if @Day=6 and @Fri=1
    set @RightDay=1
 else if @Day=7 and @Sat=1
    set @RightDay=1   
        
 if @RightDay=1
 begin
-- *****************************************************************************************
-- get next keys for all of the tables involved
-- *****************************************************************************************
--
-- get next [ActivityNumber] from [SystemKey]
--
Print @RightDay
Print @GetDate

              exec aes_systemkey 'ActivityNumber', @ActivityNumber output

              if
                   @ActivityNumber = 'TimeOut'
               begin
                   return
             end
              exec aes_systemkey 'ActivityDetailsNumber', @ActivityDetailsNumber output
              if
                @ActivityDetailsNumber = 'TimeOut'
              begin
                return
              end
Print @ActivityDetailsNumber
--
             insert into
                [Activity]
                (
                   [ActivityNumber],
                   [ID],
                   [ApplicationID],
                   [SecurityID],
                   [SecurityGroupID],
                   [SecurityOrgID],
                   [SecurityRegionID],
                   [SecurityMode]
                )
             values
                (
                   @ActivityNumber,
                   @ID,
                   @ApplicationID,
                   @SecurityID,
                   @SecurityGroupID,
                   @SecurityOrgID,
                   @SecurityRegionID,
                   @SecurityMode
                )
 --
             insert into
                [ActivityDetails]
                (
                   [ActivityDetailsNumber],
                   [ActivityNumber],
                   [Activity],
                   [ActivityType],
                   [ID],
                   [ApplicationID],
                   [FamilyID],
                   [HouseholdID],
                   [resourceID],
                   [resourcegroupID],
                   [StartDate],
                   [ActivityKey],
                               [MilestoneStatusKey],
                   [AppointmentCheckIn],  
                   [AppointmentKept],
                   [AppointmentEnded],
                   [DateCheckIn],  
                   [DateKept],
                   [DateEnded],
                               [Attendance],
                   [SecurityID],
                   [SecurityGroupID],
                   [SecurityOrgID],
                   [SecurityRegionID],
                   [SecurityMode]
                )
             values
                (
                   @ActivityDetailsNumber,
                   @ActivityNumber,
                   @Activity,
                   'Session',
                   @ID,
                   @ApplicationID,
                   @FamilyID,
                   @HHID,
                   @ResourceID,
                   @ResourceGroupID,
                   @getdate,
                   @ActivityKey,
                               @MilestoneStatusKey,
       1,
       1,
       1,
                   @getdate,
                   @getdate,
                   @getdate,
                   1,
                   @SecurityID,
                   @SecurityGroupID,
                   @SecurityOrgID,
                   @SecurityRegionID,
                   @SecurityMode
                )
 end
         end
exit_trigger:
-- ********************************************************************************
         fetch
            next
         from
            C_sessionschedule
         into
            @ID,
            @ApplicationID,
            @Program,
            @ResourceID,
            @ResourceGroupID,
            @FamilyID,
            @HHID,
            @SecurityID,
            @SecurityGroupID,
            @SecurityOrgID,
            @SecurityRegionID,
            @SecurityMode,
            @ValidFrom,
            @ValidTo,
            @Mon,
            @Tue,
            @Wed,
            @Thu,
            @Fri,
            @Sat,
            @Sun,
            @Day,
            @ActivityKey,
            @MilestoneStatusKey,
            @Activity
--         goto C_BedSchedule_end
      end
C_sessionschedule_end:
--
close C_sessionschedule

deallocate C_sessionschedule
--
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

 

grant execute on dbms_crypto to system; declare input_string VARCHAR2 (200) := 'Secret Message'; output_string VARCHAR2(2000); encrypted_raw RAW(2000); decrypted_raw RAW(2000); num_key_bytes NUMBER := 256/8; key_bytes_raw RAW(32); encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; begin DBMS_OUTPUT.PUT_LINE(input_string); key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes); encrypted_raw := DBMS_CRYPTO.ENCRYPT ( src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_raw ); decrypted_raw := DBMS_CRYPTO.DECRYPT ( src => encrypted_raw, typ => encryption_type, key => key_bytes_raw ); output_string := UTL_I18N.RAW_TO_CHAR(decrypted_raw, 'AL32UTF8'); DBMS_OUTPUT.PUT_LINE(output_string); end; declare l_src_data varchar2(20); l_type pls_integer :=DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) :='0123456789123456'; l_encval raw(2000); CURSOR secret_cursor IS select phonenumber from customer; begin OPEN secret_cursor; LOOP FETCH secret_cursor INTO l_src_data; l_encval :=dbms_crypto.encrypt( src=>utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ=>l_type, key=>utl_i18n.string_to_raw(l_key,'AL32UTF8')); DBMS_OUTPUT.PUT_LINE (l_encval); EXIT WHEN secret_cursor%NOTFOUND; END LOOP; CLOSE secret_cursor; end; declare ;_src_data row(100) :=hextoraw("190248129038903853275ijdkvjkad'); l_type pls_integer :=dbms_crypto.encrypt_aes128+ + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) :='0123456789123456'; l_decval raw(200); begin l_decval :=dbms_crypto.decrypt( src=>l_src_data, typ=>l_type, key=>utl_i18n.string_to_raw(l_key,'AL32UTF8')); end; SELECT Price FROM PRODUCT WHERE ProductID = 5;修正这一段代码
05-26
grant execute on dbms_crypto to system; -- 第一个代码块 declare input_string VARCHAR2 (200) := 'Secret Message'; output_string VARCHAR2(2000); encrypted_raw RAW(2000); decrypted_raw RAW(2000); num_key_bytes NUMBER := 256/8; key_bytes_raw RAW(32); encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; begin DBMS_OUTPUT.PUT_LINE(input_string); key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes); encrypted_raw := DBMS_CRYPTO.ENCRYPT(src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_raw); decrypted_raw := DBMS_CRYPTO.DECRYPT(src => encrypted_raw, typ => encryption_type, key => key_bytes_raw); output_string := UTL_I18N.RAW_TO_CHAR(decrypted_raw, 'AL32UTF8'); DBMS_OUTPUT.PUT_LINE(output_string); end; -- 第二个代码块 declare l_src_data varchar2(20); l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) := '0123456789123456'; l_encval raw(2000); cursor secret_cursor is select phonenumber from customer; begin open secret_cursor; loop fetch secret_cursor into l_src_data; exit when secret_cursor%notfound; l_encval := dbms_crypto.encrypt(src => utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8')); dbms_output.put_line(l_encval); end loop; close secret_cursor; end; -- 第三个代码块 declare l_src_data raw(100) := hextoraw('190248129038903853275ijdkvjkad'); l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) := '0123456789123456'; l_decval raw(200); begin l_decval := dbms_crypto.decrypt(src => l_src_data, typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8')); end; -- SQL 查询语句 SELECT Price FROM PRODUCT WHERE ProductID = 5;declare * ERROR at line 18: ORA-06550: line 18, column 1: PLS-00103: Encountered the symbol "DECLARE"报错
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值