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基础--闭包and装饰器

    闭包函数:函数内部定义的函数:引用了外部变量但非全局变量 装饰器:有了闭包的概念再去理解装饰器就会相对容易一些.python装饰器本质上就是一个函数,它可以让其他函数在不需要做任何代码变动的前提下增加 ...

  2. appium+python 启动一个app步骤

    询问度娘搭好appium和python环境,开启移动app自动化的探索(基于Android),首先来记录下如何启动待测的app吧! 如何启动APP?1.获取包名:2.获取launcherActivit ...

  3. 2018-2-13-C#-相对路径转绝对路径

    title author date CreateTime categories C# 相对路径转绝对路径 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...

  4. 洛谷P2723 丑数 Humble Numbers [2017年 6月计划 数论07]

    P2723 丑数 Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括, ...

  5. httpserver支持路由传输控制器

    main.go package main import ( "net/http" "com.jtthink.net/myhttpserver/core" ) t ...

  6. Linux下安装配置git

    参考博客: https://www.cnblogs.com/luhouxiang/p/5801853.html但执行git --version命令会出现 git version 1.8.3.1 不是最 ...

  7. 移动端适配之二:visual viewport、layout viewport和ideal viewport介绍

    上一篇博文,可算把像素这个东西讲清楚了.在这篇博文里面,将继续介绍viewport相关的内容. 很多博客都会提到PPK所讲的三个viewport,有的讲的比较复杂,看的云里雾里,我这里也大概介绍一下, ...

  8. python 对位运算

  9. R语言实现Xbar-R控制图

    R语言实现Xbar-R控制图 Xbar-R控制图在质量管理中主要用于对计量数据进行检测,以达到控制对象质量的目的. 虽然用Excel可以轻松实现控制图的操作,不过作为R软件初学者,我试着用仅有的一点R ...

  10. Directx11教程40 纹理映射(10)

    原文:Directx11教程40 纹理映射(10)      本章尝试使用纹理行列式,或者说纹理数组,在ps中,使用2个纹理,最终的像素颜色,是光照颜色*纹理1采样颜色*纹理2采样颜色,主要是想达到如 ...