CREATE OR REPLACE FUNCTION

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

时间: 2024-10-15 04:49:37

CREATE OR REPLACE FUNCTION的相关文章

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 Servicesincorporated, Guangzhou510300) Abstract  The latest version of DB QueryAnalyzer is 6.03 In DB Query Analyzer 6.03, without changing any Windows OS s

MySQL 5.7 create VIEW or FUNCTION or PROCEDURE

1.视图 a. CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY INVOKER VIEW `sakila`.`actor_info` AS SELECT `a`.`actor_id` AS `actor_id`, `a`.`first_name` AS `first_name`, `a`.`last_name` AS `last_name`, GROUP_CONCAT(DISTINCT CONCAT(`

Argument data type text is invalid for argument 1 of replace function

update Table set  content= replace(content,'222','') ERROR 更改为 update Table set content=replace(cast(content as varchar(8000)),'22','') 原文地址:https://www.cnblogs.com/wilsons/p/11289110.html

sql: Oracle 11g create table, function,trigger, sequence

--书藉位置Place目录 drop table BookPlaceList; create table BookPlaceList ( BookPlaceID INT PRIMARY KEY, --NUMBER BookPlaceName nvarchar2(500) not null, BookPlaceCode varchar(100) null, --位置編碼 BookPlaceParent INT null --BookPlaceKindId nvarchar(500) null --

CREATE FUNCTION - 定义一个新函数

SYNOPSIS CREATE [ OR REPLACE ] FUNCTION name ( [ argtype [, ...] ] ) RETURNS rettype { LANGUAGE langname | IMMUTABLE | STABLE | VOLATILE | CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT | [EXTERNAL] SECURITY INVOKER | [EXTERNAL] SECURITY

Oracle PLSQL Demo - 19.管道function[查询整表组成list管道返回]

create or replace function function_demo RETURN emp PIPELINED as Type ref_cur_emp IS REF CURSOR RETURN emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; begin Open cur_emp For select * from emp t; Loop fetch cur_emp InTo rec_emp; Exit When c

[独孤九剑]Oracle知识点梳理(六)数据库常用对象之Procedure、function、Sequence

本系列链接导航: [独孤九剑]Oracle知识点梳理(一)表空间.用户 [独孤九剑]Oracle知识点梳理(二)数据库的连接 [独孤九剑]Oracle知识点梳理(三)导入.导出 [独孤九剑]Oracle知识点梳理(四)SQL语句之DML和DDL [独孤九剑]Oracle知识点梳理(五)数据库常用对象之Table.View [独孤九剑]Oracle知识点梳理(七)数据库常用对象之Cursor [独孤九剑]Oracle知识点梳理(八)常见Exception [独孤九剑]Oracle知识点梳理(九)数

type和create type

type和create type 异同点:      create type 可在库中生成一个长期有效的自定义类型对象,而type作用域仅限于语句块中:      两者都可以自定义数据类型: 各种type实例: --[create type]***************************************************************** --①简单 type _object-------------------------------------- create

How to debug PostgreSQL function with pgAdminIII

How to debug plpgsql with pgAdminIII [[email protected] soft_bak]# git clone git://git.postgresql.org/git/pldebugger.git Initialized empty Git repository in /opt/soft_bak/pldebugger/.git/ remote: Counting objects: 445, done. remote: Compressing objec