Fixed format file! to_char formatting!
I'm tryint to create a simple fixed with output file.
I am concatenating everything together but having problems when numeric values that are null. And SQL plus keeps
putting a 1 space between each field.
I'm using this SQL
select to_char(p.county,'b999')||to_char(p.permit,'b99999')||
nvl(o.suffix,' ')||NVL(to_char(o.cmp_month,'09'),' ')||
NVL(to_char(o.cmp_day,'09'),' ')||
NVL(to_char(o.cmp_year,'9999'),' ') from pay p,owncmp o
where (p.county,p.permit,p.bottom) =
any (select p.county,p.permit,max(p.bottom) from pay p group by
p.county,p.permit) and p.county=53 and p.episode=o.episode and p.county=o.county
and p.permit=o.permit;
results
53 414O 12 17 1986
53 415O 12 21 1986
53 415O 12 21 1986
53 416O 12 27 1986
53 416O 12 27 1986
53 30003O
53 30005O 08 1926
53 30006O 1926
53 30006O 1926
53 30007O 11 08 1929
note:some misalignment was introduced here when I cut and past it into the browser, but you get the idea.
It is a little difficult to read your post and tell how many spaces you have allowed. I believe the additional space is due to the sign, + or -, of the number. Even though they are all positive numbers and the + sign isn't displayed, Oracle still allows a space for it. So, if you add an extra space to each of your values when the number is null, it should line things up properly. For example, three spaces for a two-digit number:
NVL (TO_CHAR (o.cmp_month, '09'), ' ')
Similar Messages
-
Create a file in fixed format through procedure
Hi Gurus !!,
Your help is greatly appreciated .
I know to create a procedure to genrate the file in a .csv format
But ,I have to create a procedure to generate a file in fixed format , So each field will have the length as per the length defied in the tables and with the page headers, etc
please help me here
beloW is the table structure of statae .
state :
NAME Not null VARCHAR2 (40 Byte)
STATE_CODE Not null VARCHAR2 (2 Byte)
CONTINENTAL_US_FLAG null VARCHAR2 (1 Byte)
sample data :
STATE_CODE
NAME
CONTINENTAL_US_FLAG
AI
ANGUILLA
AG
ANTIGUA AND BARBUDA
AW
ARUBA
N
BQ
BONAIRE,ST.EUSASIUS AND SABA
CW
CURACAO
Y
Data for the log and out files in the PROCESS_REFERENCE table
PROCESS_ID
PROCESS_NAME
FILE_IDENTIFIER
PATH_NAME
PROCESS_FILE_NAME
DATE_FORMAT_FOR_FILE_NAME
DEBUG_FLAG
369
FILE_STATE
LOG
/home/devtest/log/
<DATE>.FILE_STATE.LOG
YYYYMMDD
Y
340
FILE_STATE
OUT
/home/devtest/rpts/
<DATE>.FILE_STATE.OUT
YYYYMMDD
Y
This is the proc i created to generate .csv fiel which needs to be modidfied with fixed length formate as said above.
CREATE OR REPLACE PROCEDURE SAMPLE_FILE
AS
fLOG_FILE UTL_FILE.FILE_TYPE;
fRPT_FILE UTL_FILE.FILE_TYPE;
vLOGFILE_PATH PROD.PROCESS_REFERENCE.PATH_NAME%TYPE := NULL;
vLOGFILE_NAME PROD.PROCESS_REFERENCE.PROCESS_FILE_NAME%TYPE := NULL;
nLOGFILE_PROCESS_ID PROD.PROCESS_REFERENCE.PROCESS_ID%TYPE := NULL;
vRPTFILE_PATH PROD.PROCESS_REFERENCE.PATH_NAME%TYPE := NULL;
vRPTFILE_NAME PROD.PROCESS_REFERENCE.PROCESS_FILE_NAME%TYPE := NULL;
nRPTFILE_PROCESS_ID PROD.PROCESS_REFERENCE.PROCESS_ID%TYPE := NULL;
vDEBUG_FLAG PROD.PROCESS_REFERENCE.DEBUG_FLAG%TYPE := NULL;
nWRITE_COUNT NUMBER :=0;
vSYS_TIME VARCHAR2 ( 30 ):= NULL;
bLOG BOOLEAN :=FALSE;
PROCEDURE PROC_LOG ( LINE_IN IN VARCHAR2 )
IS
BEGIN
IF bLOG
THEN
vSYS_TIME :=TO_CHAR(SYSDATE, 'YYYYMMDD - HH24:MI:SS' );
UTL_FILE.PUT_LINE ( fLOG_FILE, 'Process Started on ' ||vSys_Time || ' - ' || LINE_IN );
UTL_FILE.FFLUSH ( fLOG_FILE );
bLOG :=TRUE;
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR IN LOG : ' || SUBSTR(SQLERRM,1,225));
RAISE;
END PROC_LOG;
BEGIN
SELECT PROCESS_ID, PATH_NAME, REPLACE(PROCESS_FILE_NAME,'<DATE>',
TO_CHAR(SYSDATE,DATE_FORMAT_FOR_FILE_NAME)) FILE_NAME, NVL(DEBUG_FLAG,'N') DEBUG_FLAG
INTO nLOGFILE_PROCESS_ID, vLOGFILE_PATH , vLOGFILE_NAME, vDEBUG_FLAG
FROM PROD.PROCESS_REFERENCE
WHERE PROCESS_NAME = 'FILE_STATE'
AND FILE_IDENTIFIER ='LOG' ;
IF vDEBUG_FLAG = 'Y' THEN
BEGIN
fLOG_FILE :=UTL_FILE.FOPEN(vLOGFILE_PATH,vLOGFILE_NAME,'W',32767);
bLOG := TRUE;
EXCEPTION
WHEN OTHERS THEN
bLOG := FALSE;
RAISE;
END;
END IF;
BEGIN
SELECT PROCESS_ID,PATH_NAME,
REPLACE(PROCESS_FILE_NAME,'<DATE>', TO_CHAR(SYSDATE,DATE_FORMAT_FOR_FILE_NAME)) FILE_NAME
INTO nRPTFILE_PROCESS_ID, vRPTFILE_PATH, vRPTFILE_NAME
FROM PROD.PROCESS_REFERENCE
WHERE PROCESS_NAME = 'FILE_STATE'
AND FILE_IDENTIFIER ='OUT' ;
PROC_LOG ('Opening File : '||vRPTFILE_NAME);
fRPT_FILE := UTL_FILE.FOPEN(vRPTFILE_PATH, vRPTFILE_NAME, 'W');
UTL_FILE.PUT_LINE(fRPT_FILE,'STATE CODE' || ','
|| 'NAME' || ','
|| 'CONTINENTAL_US_FLAG' );
EXCEPTION
WHEN NO_DATA_FOUND THEN
UTL_FILE.PUT_LINE(fLog_File,'ERROR in FILE OPEN : ' || SUBSTR(SQLERRM,1,1000));
RAISE;
END;
FOR CUR IN ( select state_code ,name, CONTINENTAL_US_FLAG from state ,COUNTRY
WHERE ALPHA_CODE =STATE_CODE)
LOOP
UTL_FILE.PUT_LINE(fRPT_FILE ,CUR.state_code || ' ,'
|| '''' ||CUR.CONTINENTAL_US_FLAG||''','
||'"'||CUR.name||'"');
nWRITE_COUNT :=nWRITE_COUNT+1;
END LOOP;
IF UTL_FILE.is_open (fRPT_FILE)
THEN
UTL_FILE.fclose (fRPT_FILE);
END IF;
PROC_LOG('---- PROCESS COMPLETED ---> ');
PROC_LOG('---TOTAL RECORDS WRITTEN ARE ---- : '|| nWRITE_COUNT );
IF UTL_FILE.IS_OPEN (fLOG_FILE)
THEN
UTL_FILE.FCLOSE (fLOG_FILE);
bLOG := FALSE;
END IF;
EXCEPTION
WHEN OTHERS
THEN
IF UTL_FILE.is_open (fLOG_FILE) THEN
PROC_LOG('ERROR IN MAIN !!' || SUBSTR(SQLERRM,1,250));
UTL_FILE.fclose (fLOG_FILE);
bLOG := FALSE;
ELSE
DBMS_OUTPUT.PUT_LINE('ERROR IN MAIN !!' || SUBSTR(SQLERRM,1,250));
END IF;
END SAMPLE_FILE ;Hi,
You can use RPAD to add spaces to the VARCHAR2 columns, like this:
UTL_FILE.PUT_LINE ( fRPT_FILE
, RPAD (CUR.state_code, 2) || ' ,''' ||
CUR.CONTINENTAL_US_FLAG || ''',"' ||
RPAD (CUR.name, 40) || '"'
Can the columns be NULL? If so, you may need
UTL_FILE.PUT_LINE ( fRPT_FILE
, RPAD (NVL (CUR.state_code, ' '), 2) || ' ,''' ||
NVL (CUR.CONTINENTAL_US_FLAG, ' ') || ''',"' ||
RPAD (NVL (CUR.name, ' '), 40) || '"'
since RPAD (str, len) returns NULL if str is NULL.
Lose those EXCEPTION sections. All they are doing is making it harder to find and fix errors. -
Does anyone know how to generate fixed format text file? I have few fields in the select which are null and hence messes up the file format, as space does not take up same amount of character width than any alphabets.
Basically I want to generate fixed length data file which is scheduled through DBMS_JOBS. I am using UTL_FILE utility.
Every suggestion are welcome
Thanks in advance for help :)
email your response at [email protected]hello,
using spaces as filler is sufficient. a space takes up the same room (one character) as any other letter in the alphabet.
if you look at the output in any word-processing tool or editor, that uses fonts like times, helvetica, arial, etc. those fonts are rendering the space-character smaller. in fact they are rendering each letter different. if you want to see what your output looks like, choose a font like courier.
if you just generate the file and then process it further, you should be OK. don't let you be fooled by what you see in your editor.
regards,
philipp -
External table: How to load data from a fixed format UTF8 external file
Hi Experts,
I am trying to read data from a fixed format UTF8 external file in to a external table. The file has non-ascii characters, and the presence of the non-ascii characters causes the data to be positioned incorrectly in the external table.
The following is the content's of the file:
20100423094529000000I1 ABÄCDE 1 000004
20100423094529000000I2 OMS Crew 2 2 000004
20100423094529000000I3 OMS Crew 3 3 000004
20100423094529000000I4 OMS Crew 4 4 000004
20100423094529000000I5 OMS Crew 5 5 000004
20100423094529000000I6 OMS Crew 6 6 000004
20100423094529000000I7 Mobile Crew 7 7 000004
20100423094529000000I8 Mobile Crew 8 8 000004
The structure of the data is as follows:
Name Type Start End Length
UPDATE_DTTM CHAR 1 20 20
CHANGE_TYPE_CD CHAR 21 21 1
CREW_CD CHAR 22 37 16
CREW_DESCR CHAR 38 97 60
CREW_ID CHAR 98 113 16
UDF1_CD CHAR 114 143 30
UDF1_DESCR CHAR 144 203 60
UDF2_CD CHAR 204 233 30
DATA_SOURCE_IND CHAR 294 299 6
UDF2_DESCR CHAR 234 293 60
I create the external table as follows:
CREATE TABLE "D_CREW_EXT"
"UPDATE_DTTM" CHAR(20 BYTE),
"CHANGE_TYPE_CD" CHAR(1 BYTE),
"CREW_CD" CHAR(16 BYTE),
"CREW_DESCR" CHAR(60 BYTE),
"CREW_ID" CHAR(16 BYTE),
"UDF1_CD" CHAR(30 BYTE),
"UDF1_DESCR" CHAR(60 BYTE),
"UDF2_CD" CHAR(30 BYTE),
"DATA_SOURCE_IND" CHAR(6 BYTE),
"UDF2_DESCR" CHAR(60 BYTE)
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER DEFAULT DIRECTORY "TMP"
ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE
CHARACTERSET UTF8
STRING SIZES ARE IN BYTES
NOBADFILE NODISCARDFILE NOLOGFILE FIELDS NOTRIM
( "UPDATE_DTTM" POSITION (1:20) CHAR(20),
"CHANGE_TYPE_CD" POSITION (21:21) CHAR(1),
"CREW_CD" POSITION (22:37) CHAR(16),
"CREW_DESCR" POSITION (38:97) CHAR(60),
"CREW_ID" POSITION (98:113) CHAR(16),
"UDF1_CD" POSITION (114:143) CHAR(30),
"UDF1_DESCR" POSITION (144:203) CHAR(60),
"UDF2_CD" POSITION (204:233) CHAR(30),
"DATA_SOURCE_IND" POSITION (294:299) CHAR(6),
"UDF2_DESCR" POSITION (234:293) CHAR(60) )
) LOCATION ( 'D_CREW_EXT.DAT' )
REJECT LIMIT UNLIMITED;
Check the result in database:
select * from D_CREW_EXT;
I found the first row is incorrect. For each non-ascii character,the fields to the right of the non-ascii character are off by 1 character,meaning that the data is moved 1 character to the right.
Then I tried to use the option STRING SIZES ARE IN CHARACTERS instead of STRING SIZES ARE IN BYTES, it doesn't work either.
The database version is 11.1.0.6.
Edited by: yuan on May 21, 2010 2:43 AMHi,
I changed the BYTE in the create table part to CHAR, it still doesn't work. The result is the same. I think the problem is in ACCESS PARAMETERS.
Any other suggestion? -
How can I unload data to ASCII fixed-format or delimited files,
Hello,
SQL*Loader loads data from ASCII fixed-format or delimited files. Is there such utility to unload data from Oracle database ?
AgnieszkaNo. The Export utility will dump data out but not into an ascii file.
Do you need the whole database or just some table or result of a query set?
Check out the ULT_FILE package - this will allow you to write some SQL code which will do the job you want.
Cheers,
R -
Importing metada of a file(fixed format) in LINUX platform
Hi,
I am trying to import metadata of a fixed format file in linux,i am not able to do that.But i am able to import delimted format one.
I am able to browse the file directory and i can pick the file ,when i click reverse button an error message saying "file couldn't be found" is shown.
Plz help me.Hi,
Please make sure the below things,
1.Cross check whether the logical schema and context given in the data model is pointed to correct file path in Topology manager.
2.Please make sure that you have selected the correct context ( there is a drop down in the tool bar of the designer) which you gave in the Reverse tab of your data model.
3. Please check the file format are correctly given at the data store level.
Thanks,
Guru. -
FTP/File adapter with Fixed Position File Format
Hi All,
Can any one guide me how to deal with the fixed position files while using File or FTP adapters?
Thanks In advanceHi,
Have a luk at the below link it has gud examples:
http://download.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/nfb.htm#CCGIBHFH -
Hello,
I'm using the latest versions of AdobeCC and Indesign on the mac to generate fixed format ePub3 files.
I have an Indesign Book which is comprised of 9 documents (chapters). When I create a bookmark based Table Of Contents, I'm finding that I'm having trouble getting the 'parent' and 'child' hierarchy perfect. This is because some 'child' bookmarks need to be under the 'parent' of one document within my book, and yet I need to add the bookmark from a different document (or chapter).
In essence, I'm asking is there a way of having a 'child' bookmark in one document, nestled under a 'parent' on a different document within my InDesign book? All I seem to get are repeats of the 'parent' rather than it looking at all of the documents and synching them.
In the screenshot below (the larger circle), I have added sharks as a parent folder in one 'document/chapter', and then later on in the book (in a different document/chapter, another shark needs to be added to the list under the sharks parent, and yet it doesn't give me the option to add it as a Child to sharks. I created another sharks parent in this later document thinking I might be able to synch across all documents, but all it seems to do is create a duplicate.
Any help appreciated!
Thanks, JoeJust thought that a much better way of phrasing what I initially asked would be: Is there is a way to synchronize bookmarks across all documents in a book?
Thanks
Joe -
How to use SQL loader with DBF fixed format record
Hi everybody!
My situation is that: I want to use SQL loader with Foxpro DBF format, it similar to case 2 study (Fixed format record) but DBF file has header, how can I tell SQL loader skip header.
Thank you in advanceAnother option is to apply SQL operators to fields
LOAD DATA
INFILE *
APPEND
INTO TABLE emp
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' (
empno,
ename,
job,
mgr,
hiredate DATE(20) "DD-Month-YYYY",
sal,
comm,
deptno CHAR TERMINATED BY ':',
projno,
loadseq "my_seq.nextval")This is a modified control file of Case Study 3 which originally demonstrated the use of the Sequence parameter -
Hidden text at bottom of page, how can I fix formatting?
hidden text at bottom of page, how can I fix formatting?
You don't give much information so I'm going to guess you're using a text box, perhaps in a layout document. Click on the little empty blue box on the lower right side, then click where you want the text to continue.
Walt -
BIP report in plain text/fixed format.
Hi,
Is there an option for a BIP report to go out in plain text/fixed format. I dont see that option in the drop down where we select the format and view/send/schedule reports. Is this plain text/fixed format available in BIP at all? Also if I need to send/schedule a report with report name+date...can BIP do that? Please adivce. Thanks.There is no plain text format.
Fixed format means you can select the format you need from the Limited Output Format.If You select only PDF for example the user able to see only the PDF output.
While You schedule the Report under the Report parameter tab
you will get the Template and the Format option .There u can select the Format you want to send.
Thanks -
Can query output the result into excel with a fix format?
Hi Expert,
My user giving me a requirement for new reports. They do not want the standard SAP report format but they want the result to be populate into a excel template with their own fix format. Can BW generate the report like this? Or it is out of the functionality of BW. FYI, I'm using SAP BI 7.0.
Thanks!
Regards.Hi Ang,
You have a way to do through the Bex Analyzer.
Please get the excel template in that please use a analysis design item in the place of the query result display.
Then after adding the analysis item then please assign a DP (data provider) with the query you have created.
After that please save the work book in your roles or fav's.
Note: some important settings has to be changed for the workbook.
In workbook settings, tick mark the property "REFRESH upon open of work book"
With Regards,
Ravi -
Long OpenMP directives in FORTRAN fixed format
Hi,
I have to write (very)long OpenMP directives in FORTRAN fixed format but the compiler complains to any of the techniques used to split them on more than one line. Any suggestions?
I mention that I am using a Forte 7 compiler under Solaris 8(10).
Thanks,
Rak(The Forte 7 compiler is really old. But I'm sure you know that already.)
The compiler should accept continuations with directives.
Doesn't something like the following work for you:
!omp parallel do
!omp+shared(a,b,c) -
XSLT Mapping : XML to Fixed Length File
Hi,
I have to code a XSLT mapping which converts the XML into a Fixed Length File Format. I am getting the output but it has some garbage values (Some extra spaces in front of first record and also extra blank lines before the first record)
I am pasting my xsl sheet :
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" media-type="text/plain"/>
<xsl:template match="Employees">
<xsl:for-each select="Employee">
<xsl:value-of select="Name"/>
<xsl:value-of select="ID"/>
<xsl:value-of select="ADD"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
My input XML file is as follows:
<?xml version="1.0"?>
<p1:Test02 xmlns:p1="http://www.infosys.com/xi/training/hyd/66289">
<Employees>
<Employee>
<Name>Anurag</Name>
<ID>1121</ID>
<ADD>Hyderabad</ADD>
</Employee>
<Employee>
<Name>Divya</Name>
<ID>1122</ID>
<ADD>Hyderabad</ADD>
</Employee>
<Employee>
<Name>Rasmi</Name>
<ID>1123</ID>
<ADD>Bangalore</ADD>
</Employee>
</Employees>
</p1:Test02>
And the output i am receiving is as follows:
Anurag1121Hyderabad
Divya1122Hyderabad
Rasmi1123Bangalore
Please do help.....hi,
>>>>
<xsl:output method="text" indent="yes" media-type="text/plain"/>
you allow the spaces by using indent="yes"
try with indent="no"
Regards,
michal
<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a> -
External tables-Fixed length file
Hi All,
I have a fixed length file that i load daily using an External table. Recently, one of the field, IP length was changed and customer wants to send both old records with 8 byte length and new records with 11 byte length in the same data file, until complete migration takes place.
Will it be possible for External tables to handle this requirement?. Or Is there any other possibility to treat it.
The old file contains 104 fields with IP field position form 490 to 498. Total
The new file contains 104 fields with the IP position from 490 to 501.
Thanks,
Sri.If the two record types are mixed in the same file, then you will have problems loading them. I can see two possible solutions, in no particular order of preference (using your example data):
1. Redefine the external table something like:
Position (record_type (1:1)
version (2:5)
data (6:41))then parse the remaining fields based on the version number when you select from the external table.
2. Create two external tables over the same file, one for version 1.00 and one for version 1.01 using the LOAD WHEN clause to determine which set of data to load when you select. Something like:
CREATE TABLE version1 ...
ORGANIZATION EXTERNAL ...
ACCESS PARAMETERS
(RECORDS DELIMITED BY newline
LOAD WHEN (version = 1.00)
< definition for the old format >
and
CREATE TABLE version101 ...
ORGANIZATION EXTERNAL ...
ACCESS PARAMETERS
(RECORDS DELIMITED BY newline
LOAD WHEN (version = 1.01)
< definition for the new format >Then yor processing would use something like:
SELECT ip, last_name
FROM version1
UNION ALL
SELECT ip, last_name
FROM version101HTH
John -
Upload a Fixed Length file in terms of Bytes..
Hi,
Here is my query.
I have a fixed length file that I need to upload into my program from my presentation server.
The file is in a Shift-JIS Format.
The file is a fixed length format. But it is fixed interms of the number of bytes that each column occupies.
Eg. The 1st column takes 8 bytes, the second 15 bytes, so on and so forth. We do not know the no. of characters each column takes... just the numbe of bytes.
This is how I had approached the upload.
I created an internal table with just one field of type XSTRING.
I used GUI_UPLOAD FM with CODEPAGE = `8000`.
But i noticed during debugging that in each record, the moment a SPACE occured in the input file, it would stop reading and go to the next record in the file. Meaning, I loose all the data after the first occurance of SPACE.
Am I missing something here?? Why does the FM truncate after the first SPACE. ??
Do I need to declare the internal table in any other format..??" May be placing a carriage return end of each records
" will solve your problem
class cl_abap_char_utilities definition load.
data : begin of itab,
field1(1) type c,
field2(2) type c,
field3(3) type c,
field4(4) type c,
crlf(2) type c value cl_abap_char_utilities=>cr_lf. "<<<See this line<<<
data : end of itab.
Data : begin of itab1 occurs 0.
Field(20) type c.
Data : end of itab1.
Loop at itab.
Move itab to itab1.
Append itab1.
Endloop.
Open dataset ........
Loop at itab1.
Transfer itab1 TO dataset.
Endloop.
a®
Maybe you are looking for
-
How do you backup a large photo library?
My photos library hits 14,000 this month, what's the best way to backup? I have a 250GB Lacie D2 external drive and dvd for my routine backup. I don't want to back up the same old picture every month, know what I mean? Please share you idea..... than
-
Message Check Box, Unchecked Value
Hi, I want to set this message checkbox item to <null> so I didn't put any value in the Unchecked Value. However, when I returned to the self-service page, and unchecked the checkbox, I'm getting 'N' instead of <null>. How do I set the Unchecked valu
-
I just purchased Wittenberger Fraktur how do install this font into my photoshop cs6 for mac ?
I just purchased Wittenberger Fraktur how do install this font into my photoshop cs6 for mac ?
-
Setting the Font of Selected Tab in JTabbed Pane
Hi, i have A JTabbedPane , I want to set the font of the selected tab to be bold. Can anyone please tell me how can i do that... waiting for reply , Bye Sanjeev
-
Why is this one month behind?
I have this code: GregorianCalendar filesdate = new GregorianCalendar(); filesdate.setTime(new Date(new File(file_arr[x]).lastModified())); out.println("<h3>" + filesdate.get(Calendar.MONTH) + "/" + filesdate.get(Calendar.DATE) + "/" + filesdate.get(