SQL Script for select data from ebs and make a csv file to FTP

DECLARE
  CURSOR cur_lcy_test IS
    SELECT rcta.customer_trx_id, rcta.trx_number, rcta.trx_date
      FROM ra_customer_trx_all rcta
     WHERE rcta.customer_trx_id = 11993;
  --
  rec_lcy_test cur_lcy_test%ROWTYPE;
  --
  w_csv_line_num  NUMBER := 0;
  TYPE tbl_varchar2 IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
  w_rec_data      tbl_varchar2;
  w_separator     VARCHAR2(1) := ',';
  w_file_name     xxifc_if_file_status.if_file_name%TYPE; -- ファイル名
  w_utl_file_type utl_file.file_type;
  w_flag          VARCHAR2(20) DEFAULT NULL;
  w_rec_count     NUMBER DEFAULT 0;
  w_loop_num      NUMBER DEFAULT 0;
  w_file_path     VARCHAR2(2000) DEFAULT NULL;
  w_filename      utl_file.file_type;
  --
  c_open_mode_read  CONSTANT VARCHAR2(2000) := 'r';
  c_open_mode_write CONSTANT VARCHAR2(2000) := 'w';
  c_true            CONSTANT VARCHAR2(2000) := 'TRUE';
  c_false            CONSTANT VARCHAR2(2000) := 'FALSE';
  --
BEGIN
  OPEN cur_lcy_test;
  <<get_lcy_test_loop>>
  LOOP
    FETCH cur_lcy_test
      INTO rec_lcy_test;
    EXIT WHEN cur_lcy_test%NOTFOUND;
    --
    w_csv_line_num := w_csv_line_num + 1;
    w_rec_data(w_csv_line_num) := xxcmpz11.func_make_qt2_str(to_char(rec_lcy_test.customer_trx_id)) ||
                                  w_separator ||
                                  xxcmpz11.func_make_qt2_str(to_char(rec_lcy_test.trx_number)) ||
                                  w_separator ||
                                  xxcmpz11.func_make_qt2_str(to_date(rec_lcy_test.trx_date,
                                                                     'yyyy/mm/dd'));
    --
  END LOOP get_lcy_test_loop;
  --
  w_file_name := 'LCY_WRITE_FILE_TEST.csv';
  w_file_path := 'XXIF_OUTPUT'; --all_directories.directory_name
  BEGIN
    w_utl_file_type := utl_file.fopen(location     => w_file_path,
                                      filename     => w_file_name,
                                      open_mode    => c_open_mode_read,
                                      max_linesize => 32767);
    w_flag          := c_true;
    utl_file.fclose(file => w_utl_file_type);
  EXCEPTION
    WHEN OTHERS THEN
      w_flag := c_false;
  END;
  IF (w_flag = c_true) THEN
    dbms_output.put_line('w_flag');
  END IF;
  --
  w_rec_count := w_rec_data.count;
  --
  w_utl_file_type := utl_file.fopen(location     => w_file_path,
                                    filename     => w_file_name,
                                    open_mode    => c_open_mode_write,
                                    max_linesize => 32767);
  --
  <<user_file_line_loop>>
  FOR w_loop_num IN 1 .. w_rec_count LOOP
    utl_file.put_line(file   => w_utl_file_type,
                      buffer => convert(w_rec_data(w_loop_num),
                                        'JA16SJIS',
                                        'UTF8')); --修改
  END LOOP user_file_line_loop;
  -- ファイルのクローズ
  IF (utl_file.is_open(file => w_utl_file_type)) THEN
    utl_file.fclose(file => w_utl_file_type);
  END IF;
  --
  --w_filename := utl_file.fopen(c_location, c_bat_name, 'a');

  --utl_file.put_line(w_filename,
  --                  convert('ren ' || w_file_name || ' ' || replace(w_file_name,' ','')||chr(13),
  --                                      'JA16SJIS',
  --                                      'UTF8'));
  --utl_file.fflush(w_filename);
  --utl_file.fclose(w_filename);             

  --
  CLOSE cur_lcy_test;
END;

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-08 22:33:36

SQL Script for select data from ebs and make a csv file to FTP的相关文章

SQL Script for read information from a csv file in FTP Server

DECLARE w_file_path VARCHAR2(4000) := 'XXIF_INPUT'; --all_directories.directory_name w_file_name VARCHAR2(4000) := 'lcytest001.csv'; --The file name w_file_exists BOOLEAN; w_file_length NUMBER(10) DEFAULT 0; w_file_type utl_file.file_type; w_line VAR

Delete All Umbraco Members by SQL Script (转自http://staheri.com/my-blog/2015/july/delete-all-umbraco-members-by-sql-script/)

Today I had to take the back-up off a live site and restore it on the staging server. However I had to remove all Umbraco members and thought it'd be easier to do that with SQL script than API. Despite Googling to find a firm solution (SQL script), I

doris: shell invoke .sql script for doris and passing values for parameters in sql script.

1. background in most cases, we want to execute sql script  in doris  routinely. using azkaban, to load data,etc.And we want to pass parameters to the sql script file. we can easily handle such situation in hive. 1.1 hive usage: using -hiveconf:  or

SQL Fundamentals: Basic SELECT statement基本的select语句

Basic SELECT statement基本的select语句 The basic syntax for a SELECT statement is presented below. SELECT语句的基本语法如下. |:多选一 []:可选择的内容 {}:多选一 没有被{}括起来的是必选 SELECT [DISTINCT | ALL] {* | select_list} FROM {table_name [alias] | view_name}     [{table_name [alias

csharp:SMO run sql script

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.SqlServer.Management.Common;//需添加microsoft.sqlserv

How to Enable Trace or Debug for APIs executed as SQL Script Outside of the Applications ?

In this Document   Goal   Solution   1: How do you enable trace for an API when executed from a SQL script outside of Oracle Applications ?   2: How do you get debug log for an API when executed from a SQL script outside of Oracle Applications ?   a)

oracle 不能更新 PL/SQL 点击“edit data”报“ these query results are not updateable”

你可以选择在查询语句的最后加上 for update,就可以打开编辑锁,直接修改数据. 而在默认查询下,点击Edit data,会报错:The query results are not updateable. SQL代码示例 select * from table_name for update; (table_name为要编辑的表)

We need the sql script to query the table Ditronics.Kiosk.Journal to find journal with mismatch denom information versus amount.

CREATE TABLE #MoneyTable ( Id INT IDENTITY(1, 1) PRIMARY KEY , MoneyName VARCHAR(50) , Cents INT ) INSERT INTO #MoneyTable ( MoneyName, Cents ) VALUES ( 'UnSupported', 0 ) INSERT INTO #MoneyTable ( MoneyName, Cents ) VALUES ( 'DollarOne', 100 ) INSER

教您如何使用SQL中的SELECT LIKE like语句

LIKE语句在SQL有着不可替代的重要作用,下文就将为您介绍SQL语句中SELECT LIKE like的详细用法,希望对您能有所帮助. LIKE语句的语法格式是:select * from 表名 where 字段名 like 对应值(子串),它主要是针对字符型字段的,它的作用是在一个字符型字段列中检索包含对应子串的. A:% 包含零个或多个字符的任意字符串: 1.LIKE'Mc%' 将搜索以字母 Mc 开头的所有字符串(如 McBadden). 2.LIKE'%inger' 将搜索以字母 in