CREATE OR REPLACE FUNCTION SF_Taishou_Ksai_Date(v_receiptNum IN CHAR,
                                                v_his        IN CHAR)
  RETURN VARCHAR2 DETERMINISTIC IS
  RESULT              VARCHAR2(50);
  v_result_t          VARCHAR2(50);
  v_tmp_code          VARCHAR2(100);
  v_uriage_sha_code   VARCHAR2(50);
  v_Adv_Sha_Code      VARCHAR2(50);
  v_Taishou_Ksai_Date date;
BEGIN

select *
    INTO v_tmp_code, v_uriage_sha_code
    from (select REPLACE(atom_concat(Ksai_Sha_Code), ',', ''),
                 tafd.uriage_sha_code
         
            from TB_ADV_FEE_DETAIL tafd
           where tafd.receipt_num = v_receiptNum
             and tafd.his = v_his
           group by tafd.receipt_num, tafd.his, tafd.uriage_sha_code)
   where rownum = 1;

IF (INSTR(v_tmp_code, v_uriage_sha_code) = 0) THEN
 
    IF (INSTR(v_tmp_code, '1') = 0) THEN
      v_result_t := '';
    ELSE
      v_result_t := '1';
    END IF;
 
    IF (INSTR(v_tmp_code, '2') = 0) THEN
      v_result_t := v_result_t || '';
    ELSE
      v_result_t := v_result_t || '2';
    END IF;
 
    IF (INSTR(v_tmp_code, '3') = 0) THEN
      v_result_t := v_result_t || '';
    ELSE
      v_result_t := v_result_t || '3';
    END IF;
 
    IF (INSTR(v_tmp_code, '4') = 0) THEN
      v_result_t := v_result_t || '';
    ELSE
      v_result_t := v_result_t || '4';
    END IF;
 
    IF (INSTR(v_tmp_code, '5') = 0) THEN
      v_result_t := v_result_t || '';
    ELSE
      v_result_t := v_result_t || '5';
    END IF;
 
    v_uriage_sha_code := substr(v_result_t, 0, 1);
 
  END IF;

/**対象掲載日*/

SELECT Ksai_Date, Adv_Sha_Code
    INTO v_Taishou_Ksai_Date, v_Adv_Sha_Code
    FROM TB_ADV_FEE_DETAIL
   WHERE Receipt_Num = v_receiptNum
     AND His = v_his
     AND Ksai_Sha_Code = v_uriage_sha_code
     AND rownum = 1;

IF (v_Taishou_Ksai_Date = null) THEN
    v_Taishou_Ksai_Date := sysdate;
  END IF;

/**広告会社名略2  Adv_Sha_Name_Ryaku2*/
  SELECT Adv_Sha_Name_Ryaku2
    INTO RESULT
    FROM TB_ADV_SHA
   WHERE Adv_Sha_Code = v_Adv_Sha_Code
     AND v_Taishou_Ksai_Date between Apply_Start_Date and Apply_End_Date;

RETURN(RESULT);
END SF_Taishou_Ksai_Date;

/*SELECT BEFORE HOSEI*/
select tafd.Adv_Sha_Name,
       SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his),
       tafd.*
  from TB_ADV_FEE_DETAIL tafd
 where tafd.Adv_Sha_Name <>
       SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his)

/*HOSEI SQL*/
update TB_ADV_FEE_DETAIL tafd
set tafd.Adv_Sha_Name = SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his),
tafd.Del_Per_Code = 'founder'

where tafd.Adv_Sha_Name <>
       SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his),

/*SELECT AFTER HOSEI*/
 select tafd.Adv_Sha_Name,
        SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his),
        tafd.*
   from TB_ADV_FEE_DETAIL tafd
  where tafd.Adv_Sha_Name <>
        SF_Taishou_Ksai_Date(tafd.receipt_num, tafd.his),
    and tafd.Del_Per_Code = 'founder';

/*CLEAR HOSEI FLG*/
update TB_ADV_FEE_DETAIL tafd
   set tafd.Del_Per_Code = null
 where tafd.Del_Per_Code = 'founder';

/*HOSEI SQL*/

CREATE OR REPLACE FUNCTION的更多相关文章

  1. GreenPlum学习笔记:create or replace function创建函数

    原始表数据如下: 需求:现要求按分号“;”将rate_item列进行分割后插入到新的数据表中. CREATE OR REPLACE FUNCTION fun_gp_test_xxx_20181026( ...

  2. 新建体(2):create or replace object创建存储包、存储过程、函数

    http://heisetoufa.iteye.com/blog/366957/ 创建一个package(包) 声明: create or replace package mpay_route is ...

  3. orcle自定义类型type/create or replace type

    一.type / create or repalce type 区别联系 相同: 可用关键字create type 或者直接用type定义自定义类型, 区别: create type 变量 as ta ...

  4. How to create DB2 user function easily by DB Query Analyzer 6.03

    How to create DB2user function easily by DB Query Analyzer 6.03 Ma Genfeng (Guangdong Unitoll Servic ...

  5. Azure - Create your first function using Visual Studio

    Azure Functions lets you execute your code in a serverless environment without having to first creat ...

  6. MySQL 5.7 create VIEW or FUNCTION or PROCEDURE

    1.视图 a. CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY INVOKER VIEW `sakila` ...

  7. How can I create an Asynchronous function in Javascript?

    哈哈:)我的codepen 的代码笔记是:http://codepen.io/shinewaker/pen/eBwPxJ --------------------------------------- ...

  8. learning scala How To Create Variable Argument Function - varargs :_ *

    Scala collection such as List or Sequence or even an Array to variable argument function using the s ...

  9. behavior planning——11 create a cost function speed penalty

    A  key part of getting transitions to happen when we want  them to is the design of reasonable cost ...

随机推荐

  1. Python基础-列表、元组、字典、字符串

    Python基础-列表.元组.字典.字符串   多维数组 nums1 = [1,2,3] #一维数组 nums2 = [1,2,3,[4,56]] #二维数组 nums3 = [1,2,3,4,['a ...

  2. 操作系统 Lab1

    练习1 1 ucore.img 是如何生成的 使用 make V= 查看详细的步骤 cc kern/init/init.c 使用cc工具进行预处理 gcc -Idir 将dir 作为查找目录(头文件) ...

  3. 2019.8.3 NOIP模拟测试12 反思总结【P3938 斐波那契,P3939 数颜色,P3940 分组】

    [题解在下面] 早上5:50,Gekoo同学来到机房并表态:“打暴力,打暴力就对了,打出来我就赢了.” 我:深以为然. (这是个伏笔) 据说hzoi的人还差两次考试[现在是一次了]就要重新分配机房,不 ...

  4. deque简单解析

    deque是支持双端插入删除的容器,oi中用来维护单调队列 声明方式 deque<int> d1;//声明一个叫d1的双向队列 deque<int> d2(d1);//声明一个 ...

  5. 数据库Mysql监控及优化

    在做 性能测试的时候数据最重要,数据来源于哪里呢,当然是数据库了,数据库中,我们可以知道,数据从磁盘中要比从缓存中读取数据的时间要慢的多的多,还可以知道,同样的一个sql语句,执行的效率也不一样,这是 ...

  6. SpringCloud 融入 Python - Tornado

    前言 该篇文章分享如何将Python Web服务融入到Spring Cloud微服务体系中,并调用其服务,Python Web框架用的是Tornado 构建Python web服务 引入py-eure ...

  7. WPF MVVM简单介绍

     前面文章中,我们已经知道,WPF技术的主要特点是数据驱动UI,所以在使用WPF技术开发的过程中是以数据为核心的,WPF提供了数据绑定机制,当数据发生变化时,WPF会自动发出通知去更新UI. 我们不管 ...

  8. Python高级核心技术97讲 系列教程

    Python高级核心技术97讲 系列教程 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看的 ...

  9. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图 本章介绍一种在游戏和应用中,模拟动态阴影的基本阴影 ...

  10. prepareStatement设置参数,mysql数据出现中文‘?’的情景与解决方式

    在prepareStatement中传入中文的参数,mysql数据库中出现“?”号 try { Class.forName("com.mysql.jdbc.Driver"); co ...