473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PL/SQL Fix Record Length file

10
Does anyone know how to write data as a FIX RECORD LENGTH file in PL/SQL?
Feb 28 '07 #1
11 10217
Dave44
153 100+
Does anyone know how to write data as a FIX RECORD LENGTH file in PL/SQL?
One approach i have used is to figure out the length of each column and use the rpad or lpad functions to get each field the correct length.

select rpad(my_field,<col_length as number>,' '),
rpad(my_next_field,<col_length as number>,' ')
from my_table

...
Feb 28 '07 #2
bebe
10
One approach i have used is to figure out the length of each column and use the rpad or lpad functions to get each field the correct length.

select rpad(my_field,<col_length as number>,' '),
rpad(my_next_field,<col_length as number>,' ')
from my_table

...

Thank you, this diffinitely gives me a starting point. Basically I am reading data from a table which has Fname, LName, Salary, EmployeeID, Dept. I need a cursor to get all the columns example,
Select * from
COLS
where TABLE_NAME = "my_table"

basically I need to get the COL_NAME, SIZE, PRECISION, SCALE.


select rpad(COL,size-length(COL)),
rpad(next_COL, size-length(COL))
from my_table


do I have the right idea?
Mar 1 '07 #3
Dave44
153 100+
Thank you, this diffinitely gives me a starting point. Basically I am reading data from a table which has Fname, LName, Salary, EmployeeID, Dept. I need a cursor to get all the columns example,
Select * from
COLS
where TABLE_NAME = "my_table"

basically I need to get the COL_NAME, SIZE, PRECISION, SCALE.


select rpad(COL,size-length(COL)),
rpad(next_COL, size-length(COL))
from my_table


do I have the right idea?
Your initial post says that you are creating a fixed position string, correct? if so that FP string will have the lengths for each column in a spec somewhere.

so when you query your table you will use the rpad function to add the necessary length (where needed) to ensure that each column from the table is the correct number of characters long.

so if the first column in the fixed position string is 30 characters long and is supposed to be the Fname then you would :

select rpad(Fname,30,' '),
...
from my_table

the 3 parameters in RPAD are the field or string to pad, the number of spaces total for the length(so if the field in the table is 10 characters in row x it will pad 20 characters to it, and the last paramter is what to pad it with (most cases its a space ' ')
Mar 1 '07 #4
bebe
10
Your initial post says that you are creating a fixed position string, correct? if so that FP string will have the lengths for each column in a spec somewhere.

so when you query your table you will use the rpad function to add the necessary length (where needed) to ensure that each column from the table is the correct number of characters long.

so if the first column in the fixed position string is 30 characters long and is supposed to be the Fname then you would :

select rpad(Fname,30,' '),
...
from my_table

the 3 parameters in RPAD are the field or string to pad, the number of spaces total for the length(so if the field in the table is 10 characters in row x it will pad 20 characters to it, and the last paramter is what to pad it with (most cases its a space ' ')

hmmm I will try this thank you :)
Mar 1 '07 #5
bebe
10
the code is long but the bit before my RPAD statement is:

SELECT DATA_LENGTH, DATA_PRECISION, DATA_SCALE
INTO V_DATA_LEN, V_PRE, V_SCALE
FROM COLS
WHERE TABLE_NAME = P_TABLE
AND COLUMN_NAME = V_COL;

RPAD()....ETC
Mar 2 '07 #6
bebe
10
I dont have a specific length .... but here is the entire code:

PROCEDURE EXP_TABLE_TO_FRL(P_DIR IN VARCHAR2, P_TABLE IN VARCHAR2)
AS
V_FILE VARCHAR2(50);
V_SQL VARCHAR2(500) := 'SELECT ROWID FROM ' || P_TABLE;
C_CUR SYS_REFCURSOR;
V_ROWID VARCHAR2(30);
V_XML_SQL VARCHAR2(500);
V_XML CLOB;
V_COL VARCHAR2(30);
V_VAL CLOB;
V_LINE CLOB;
V_POS BINARY_INTEGER;
V_DATA_LEN NUMBER;
V_PRE NUMBER;
V_SCALE NUMBER;
BEGIN
OPEN C_CUR FOR V_SQL;
LOOP
FETCH C_CUR INTO V_ROWID;
EXIT WHEN C_CUR%NOTFOUND;
V_XML_SQL := 'SELECT * FROM ' || P_TABLE || ' WHERE ROWID =' ||''''|| V_ROWID||'''';
V_XML := XML.GET_XML(V_XML_SQL, P_TABLE);
V_XML := REPLACE(V_XML,'<?xml version="1.0"?>'||CHR(10)||'<'||P_TABLE||'>'||CHR( 10)||' <DATA>'||CHR(10)||' ');
V_XML := REPLACE(V_XML,'</DATA>'||'</'||P_TABLE||'>');
LOOP
IF LENGTH(V_XML)= 0 THEN
EXIT;
ELSE
-- find pos of first '>'
V_POS := INSTR(V_XML, '>',1,1);
-- Get attribute
V_COL := SUBSTR(V_XML, 1, V_POS);
V_XML := REPLACE(V_XML, V_COL, '');
V_POS := INSTR(V_XML, '<',1,1);
V_VAL := SUBSTR(V_XML,1, V_POS - 1);
-- Get rid of '<' and '>' to get column name
V_COL := SUBSTR(V_COL,2, LENGTH(V_COL)-2);
V_XML := REPLACE(V_XML, V_VAL||'</'||V_COL||'>');

SELECT DATA_LENGTH, DATA_PRECISION, DATA_SCALE
INTO V_DATA_LEN, V_PRE, V_SCALE
FROM COLS
WHERE TABLE_NAME = P_TABLE
AND COLUMN_NAME = V_COL;


-- Do the RPAD thing and then write the line to a file
I have no idea how to write the RPAD

END IF;
END LOOP;

END LOOP;
CLOSE C_CUR;
END;
Mar 2 '07 #7
bebe
10
I have a new project which involves triggers. Now let me state that I am completely new to PL/SQL. So everything is very confusing to me at the moment.

I am supposed to write triggers that replicate data from one table to another. I have a function I can call for replication but how do i write the trigger itself.

trigger should be in a schema called purple and it should be AFTER insert/update for each row at a statement level.

start with a table called color

trigger shall call the database palett.purple_replication procedure. the reason why this procedure is in a seperate database is because the data mappings are defined in palett.

HELP!
Mar 2 '07 #8
I have a new project which involves triggers. Now let me state that I am completely new to PL/SQL. So everything is very confusing to me at the moment.

I am supposed to write triggers that replicate data from one table to another. I have a function I can call for replication but how do i write the trigger itself.

trigger should be in a schema called purple and it should be AFTER insert/update for each row at a statement level.

start with a table called color

trigger shall call the database palett.purple_replication procedure. the reason why this procedure is in a seperate database is because the data mappings are defined in palett.

HELP!
You say that the table is in a separate database. So you must use a database link or create a synonym in your schema for the destination table.

Thank you
Mar 2 '07 #9
Dave44
153 100+
I have a new project which involves triggers. Now let me state that I am completely new to PL/SQL. So everything is very confusing to me at the moment.

I am supposed to write triggers that replicate data from one table to another. I have a function I can call for replication but how do i write the trigger itself.

trigger should be in a schema called purple and it should be AFTER insert/update for each row at a statement level.

start with a table called color

trigger shall call the database palett.purple_replication procedure. the reason why this procedure is in a seperate database is because the data mappings are defined in palett.

HELP!

Do you mean in a separate schema or separate database? the former inplies a different user within the same database and the latter implies a different database (requiring a database link).

Also is pallet a user name or a package name?
Mar 3 '07 #10
bebe
10
Do you mean in a separate schema or separate database? the former inplies a different user within the same database and the latter implies a different database (requiring a database link).

Also is pallet a user name or a package name?

No just a different schema.
The trigger is supposed to be against a schema called AC3DB and should fire AFTER INSERT/UPDATE AT STATEMENT LEVEL AND ROW LEVEL. The calls this procedure for data replication which is in another schema called MEX. here is the code:

PROCEDURE JON_REPLICATION(P_TABLE IN VARCHAR2, P_DATA_MAPPING IN VARCHAR2, P_TARGET_OWNER IN VARCHAR2)
AUTHID CURRENT_USER
AS
PRAGMA AUTONOMOUS_TRANSACTION;
-- -----------------------------------------------------------------------------
-- Description: Moves data received by the MEX inbound process
-- to the final data structures in AC3DB
-- --------- ------ -------------------------------------------
-- -----------------------------------------------------------------------------
MIGRATE_DATA MIGRATE_DATA_TY;
RESULT BOOLEAN;
-- Declare program variables as shown above
BEGIN
MIGRATE_DATA := MIGRATE_DATA_TY(P_TABLE, P_DATA_MAPPING, P_TARGET_OWNER);
RESULT := MIGRATE_DATA.MIGRATE;
END;
Mar 5 '07 #11
Dave44
153 100+
if the call to palett.purple_replication is the same then like this:

CREATE OR REPLACE TRIGGER my_trigger_name

AFTER INSERT OR UPDATE ON color
FOR EACH ROW
BEGIN

palett.purple_replication(my_parameters);
END;

else like this:

CREATE OR REPLACE TRIGGER my_trigger_name

AFTER INSERT OR UPDATE ON color
FOR EACH ROW
BEGIN

IF UPDATING THEN
palett.purple_replication(my_parameters);
ELSIF INSERTING THEN
palett.purple_replication(my_parameters);
END IF;
END;

each user will need to have execute privilege on paletts function though.

Did you figure out the rpad question earlier?
Mar 7 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Rick | last post by:
Hi all, Is there a MySQL function to get the first record through a query? I would like to open a page of client records with the first one shown. The other records can be accessed from a...
6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
18
by: Panchal V | last post by:
I want to access a variable length record in C, the format is as follows : +---+---+-----------+ | A | L | D A T A | +---+---+-----------+ A - Some Data (1 BYTE) L - Length the Data that...
2
by: Mel WEaver | last post by:
Hello, I have the following delphi structure for a binary file. I'm looking for idea how to read this file. Mel type TMenuDataStruct = packed record exename : string;
1
by: Bernard Dhooghe | last post by:
The documentation (Administrative API Reference, 8.2, PDF format) says page 520: "The rest of the record is dependent upon the record type and the table descriptor record defined for the table."...
11
by: Timofmars | last post by:
I'm try to Unload DB2 data from a table into a record sequential file on NT. I can an unload on Mainframe, but it doesn't seem to be an option in NT. In NT, all I can do is export/import. I can...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
2
by: Jim | last post by:
I need to write a text file that has fixed length fields resulting in a fixed length record. What I'd like to see is something like Cobol (gag) uses 01 rec. 02 field1 pic x(02. 02 field2 pic...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.