473,668 Members | 2,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PL/SQL Fix Record Length file

10 New Member
Does anyone know how to write data as a FIX RECORD LENGTH file in PL/SQL?
Feb 28 '07 #1
11 10242
Dave44
153 New Member
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_fi eld,<col_length as number>,' ')
from my_table

...
Feb 28 '07 #2
bebe
10 New Member
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_fi eld,<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 New Member
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 New Member
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 New Member
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 New Member
I dont have a specific length .... but here is the entire code:

PROCEDURE EXP_TABLE_TO_FR L(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_X ML_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 New Member
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_r eplication 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
rectoverso
16 New Member
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_r eplication 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 New Member
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_r eplication 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

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

Similar topics

17
4466
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 hyperlinked list. Thanks for any advice, Rick
6
44098
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 scott/tiger@common control=/full_path/test.ctl log=/full_path/adhoc/test.log SQL*Loader: Release 9.2.0.1.0 - Production on Tue Sep 2 10:49:27 2003 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
18
9384
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 follows (1 BYTE) then actual data
2
12184
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
2119
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." How can the record descriptor by composed for existing tables (not in the log file as new entry) or is mentioned somewhere? select colname, colno, rtrim(typename), length, scale,
11
8638
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 do a Load too, but not an Unload. I just want the only the data from the table in a record sequential file. Export seems only to give options to have a delimited line sequential file or a record sequential file where the data is preceeded by...
1
3722
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 database file throu GUI Save Record button? As i write the comand as foloow but it is not inserting the new record in to the Access Database. Public Function Open_Connection() As Boolean Try Select Case...
2
1689
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 x(10). write rec. I'm using FileIO.TextFieldParser
0
2145
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 file="../Connections/conn.jsp" %> <% // *** Edit Operations: declare variables // set the form action variable String MM_editAction = request.getRequestURI(); if (request.getQueryString() != null && request.getQueryString().length() > 0) {
1
4597
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 Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8371
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8572
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8652
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2782
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.