1)A.sql
DECLARE
CURSOR c_get_sup_list IS
SELECT source_name, source_org_id, org_name, country_code
FROM agg_supplier
WHERE record_status = 'm'
AND generated_date is null
ORDER BY source_name;
BEGIN
FOR rec_supplier_list IN c_get_sup_list LOOP
DBMS_OUTPUT.PUT_LINE('"' || rec_supplier_list.source_name || '","' || rec_supplier_list.source_org_id || '","' || rec_supplier_list.org_name || '","' || rec_supplier_list.country_code || '"');
END LOOP;
END;
2) B.sql
WHENEVER SQLERROR EXIT 79
set serveroutput on
set feedback off
set trims on
set pagesize 0
set timing off
set lin 5000
spool /home/gsol/cnsqlsetup/ supp.csv
@/home/gsol/cnsqlsetup/ A;
spool off
set serveroutput off
EXIT 76
3)C.sh
DATEYMD=`date +%Y%m%d`
DATEHM=`date +%H%M`
BACKUP=~/cnsqlsetup/backup_dedup
EMAILRCP='dingxy@aa.com bb@aas.com'
cd ~/cnsqlsetup/
sqlplus usrname/password@DBname @B;
CSV_FILE_TODAY='supp_'$DATEYMD$DATEHM'.csv'
CSV_GBK_FILE_TODAY='supp_'$DATEYMD$DATEHM'_GBK.csv'
mv supp.csv $CSV_FILE_TODAY
iconv -c -f UTF-8 -t GBK -o $CSV_GBK_FILE_TODAY $CSV_FILE_TODAY
cat $CSV_GBK_FILE_TODAY |(uuencode $CSV_GBK_FILE_TODAY; echo "Hi. Thanks")| mail -s "subject ($DATEYMD)" $EMAILRCP
mv $CSV_FILE_TODAY $CSV_GBK_FILE_TODAY $BACKUP
这是从数据从数据库里extract出来,保存为||给分隔符的csv file.并且保存为两种encoding的文件。
这种方法可以避免这样的问题:
ORA-01489: result of string concatenation is too long。
cause :A concatenated string value cannot exceed 4000 characters. When you create a column by concatenating the columns, for some rows the length exceeds 4000 characters.
A concatenated string value cannot exceed 4000 characters. When you create a column by concatenating the columns, for some rows the length exceeds 4000 characters.
方法2:会出现 ORA-01489: result of string concatenation is too long的错误
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
CLEAR COLUMNS
CLEAR BREAKS
SET TERMOUT OFF
SET AUTOPRINT OFF
SET VERIFY OFF
SET TRIMSPOOL ON
--perform extraction for table1
spool aa.csv;
select ID || ',"'|| SOURCE_NAME || '","'|| SOURCE_PRODUCT_ID || '","'|| URL || '","'|| SOURCE_ORG_ID || '","'|| DESCRIPTION || '","'|| PRODUCT_IMAGE_URL || '","'|| PRODUCT_IMAGE_NAME || '","'|| MODEL_NUM || '","'|| RECORD_STATUS || '","'|| SOURCE_CATEGORY || '","'|| KEY_SPECIFICATION || '","'|| CERTIFICATION || '","'|| PROCESS_DATE || '",'|| BATCH_NO from table1 where BATCH_NO=&1 and rownum <11;
spool off;
exit;
////////保存为aa.csv
cause :A concatenated string value cannot exceed 4000 characters. When you create a column by concatenating the columns, for some rows the length exceeds 4000 characters.
A concatenated string value cannot exceed 4000 characters. When you create a column by concatenating the columns, for some rows the length exceeds 4000 characters.
方法2:会出现 ORA-01489: result of string concatenation is too long的错误
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
CLEAR COLUMNS
CLEAR BREAKS
SET TERMOUT OFF
SET AUTOPRINT OFF
SET VERIFY OFF
SET TRIMSPOOL ON
--perform extraction for table1
spool aa.csv;
select ID || ',"'|| SOURCE_NAME || '","'|| SOURCE_PRODUCT_ID || '","'|| URL || '","'|| SOURCE_ORG_ID || '","'|| DESCRIPTION || '","'|| PRODUCT_IMAGE_URL || '","'|| PRODUCT_IMAGE_NAME || '","'|| MODEL_NUM || '","'|| RECORD_STATUS || '","'|| SOURCE_CATEGORY || '","'|| KEY_SPECIFICATION || '","'|| CERTIFICATION || '","'|| PROCESS_DATE || '",'|| BATCH_NO from table1 where BATCH_NO=&1 and rownum <11;
spool off;
exit;
////////保存为aa.csv