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是怎么对文件进行操作的呢? 1.什么是文件? 文件是一个存储在辅助存储器上的数据序列,可以包含任何数据内容. 文件包括两种类型:文本文件 ...

  2. 洛谷 P1036 选数【背包型DFS/选or不选】

    题目描述 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12, ...

  3. 使用neo4j-import导入数据及关系

    背景 上节我们了解了什么是图数据库,作为研究对象的neo4j的特点,优缺点以及基本的环境搭建. 现在我们要讲存储在csv中的通话记录数据导入到neo4j中去,并且可以通过cql去查询导入的数据及关系 ...

  4. UvaLive1347

    Programming contests became so popular in the year 2397 that the governor of New Earck — the largest ...

  5. Codeforces 851D Arpa and a list of numbers

    D. Arpa and a list of numbers time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Axure之母版窗口

  7. C# dataGridView_CellValueChanged事件

    C# 输入完以后立即更新缓冲区(DataGridView CheckBox列checked变化后就触发CellValueChanged事件) 在DataGridView添加如下的事件( Current ...

  8. Django基础内容整理

  9. ML面试1000题系列(51-60)

    本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 51.简单说下sigmoid激活函数 常用的非线 ...

  10. arcgis 点线面操作

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...