Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi there i an trying to load data

Status
Not open for further replies.

Finubar

Programmer
Jan 10, 2002
4
GB
Hi there
i an trying to load data from a text file into 3 different tables. This would be pretty staight forward except for that on the main table there is a Primary key. the Primary key is a sequence with a check character which is worked out using a modulus.

i can't get the call to the procedure that contains the function to work from the control file.

can anybody HELP me ???


this is the control file:

load data
infile practice_R2.TXT
APPEND
into table tdco_customers
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
trailing nullcols
(CUST_ID "select pkco_convert_to_code.FN_CUST_ID from dual"
,CUST_SEARCH_NAME
,CUST_SET_UP_DATE SYSDATE
,CUST_CHECK_CHAR CONSTANT ''
,CUST_PAYEE_NAME CONSTANT ''
,CUST_SUF_CODE CONSTANT ''
,CUST_CSTY_CODE CONSTANT ''
,CUST_CTYP_CODE CONSTANT ''
,CUST_CCAT_CODE CONSTANT ''
,CUST_FRST_CODE CONSTANT ''
,CUST_LANG_CODE CONSTANT ''
,CUST_GEN_CODE CONSTANT ''
,CUST_TTL_CODE CONSTANT ''
,CUST_CTRY_CODE_NAT CONSTANT ''
,CUST_TRADING_NAME
,CUST_CEASED_TRADING_DATE CONSTANT ''
,CUST_COMP_NAME
,CUST_CONTACT_NAME CONSTANT ''
,CUST_FORENAME CONSTANT ''
,CUST_MIDD_NAME CONSTANT ''
,CUST_SURNAME CONSTANT ''
,CUST_NAME_KNOWN_BY CONSTANT ''
,CUST_M_BTH_SURNAME CONSTANT ''
,CUST_BIRTH_DATE CONSTANT ''
,CUST_DEATH_DATE CONSTANT ''
,CUST_VERS_NUM CONSTANT ''
,CUST_AUDIT_USER CONSTANT ''
,CUST_AUDIT_DATE SYSDATE
,CUST_AUDIT_ACTION CONSTANT ''
,CUST_AUDIT_LOCATION CONSTANT '')


This the Package
Spec

CREATE OR REPLACE PACKAGE pkco_convert_to_code AS

-- ***********************************************************************************************
-- * *
-- * Author : Finbar Kelleher *
-- * Created: July '02 *
-- * Purpose: This package is for inserting data, using SQL Loader, *
-- * into the Dynamic tables. *
-- * It decodes the description from the text(.TXT) file holding the data *
-- * and inserts the code into the table. * *
-- * The packge HAS to be called from the Control(.CTR) file. * *
-- * *
-- ***********************************************************************************************



Function FN_CONVERT_TO_CNTY_CODE( p_cnty_desc VARCHAR2) RETURN NUMBER;
Function FN_CUST_ID RETURN TDCO_CUSTOMERS.cust_id%type;


end pkco_convert_to_code;



Body:

CREATE OR REPLACE PACKAGE BODY pkco_convert_to_code AS

-- ***********************************************************************************************
-- * *
-- * Author : Finbar Kelleher *
-- * Created: July '02 *
-- * Purpose: This package is for inserting data, using SQL Loader, *
-- * into the Dynamic tables. *
-- * It decodes the description from the .TXT file and inserts the *
-- * code into the table. *
-- * The packge HAS to be called from the .CTR file. *
-- * *
-- ***********************************************************************************************



-- ********************************************************************************
-- * *
-- * Procedure: FN_CUST_ID *
-- * *
-- * Purpose: To get the next Cust_id and add the check character *
-- * *
-- ********************************************************************************

FUNCTION FN_CUST_ID RETURN tdco_customers.cust_id%type AS

v_cust_id tdco_customers.cust_id%type;

BEGIN

SELECT Pkco_App_Tdco_Customers.FN_ADD_CHK_DIG(Pkco_App_Tdco_Customers.getNextSequence())
INTO v_cust_id
FROM DUAL;

RETURN v_cust_id;

END;

-- ********************************************************************************
-- * *
-- * Procedure: FN_CONVERT_TO_CNTY_CODE *
-- * *
-- * Purpose: Converts County Description to Cnty_code *
-- * *
-- ********************************************************************************

FUNCTION FN_CONVERT_TO_CNTY_CODE (p_cnty_desc VARCHAR2) RETURN NUMBER AS


v_cnty_code NUMBER(3);


BEGIN

select cnty_code
into v_cnty_code
from tsco_counties
where cnty_full_name = p_cnty_desc;

RETURN v_cnty_code;

END ;

end PKCO_CONVERT_TO_CODE;



 
The SQL operator that is applied to a column can be any valid expresssion that would work in the VALUES clause of an INSERT statement.

I would try using:

(CUST_ID "pkco_convert_to_code.FN_CUST_ID"
,...
"Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
 
You don't need to include a SELECT statement to use the function.

Syntax is

...
APPEND
INTO TABLE etc...
(
COL_NAME "package.function"
)

As an aside, this looks like you are getting a sequence to me. How about using a SQL*Loader sequence and save all that coding? If you load in conventional path, then use the following:-

...
APPEND
INTO TABLE etc...
(
COL_NAME SEQUENCE(MAX,1)
)

Where 1 is the increment and MAX is a keyword specifying that you want to start at the MAX + increment. Try it !!!

Regards

Adrian
 
ThomVF

when i tried your solution i got the following error

Record 1: Rejected - Error on table TDCO_CUSTOMERS.
ORA-01461: can bind a LONG value only for insert into a LONG column

Any other suggestions gratefully recieved !!!!
 
BilliaUK

unfortunately i can't use the
APPEND
INTO TABLE etc...
(
COL_NAME SEQUENCE(MAX,1)
)

The Cust_id gets the next sequence number which then has a modulus function run on it
e.g.
sequence number
6251

6*6 = 36
2*5 = 10
5*4 = 20
1*3 = 1 etc
then
36+10+20+1 = 67
then
67/13 = 5 with a remainder of 2

the number 2 is the concatenated to the end of the sequence number to give the unique cust_id - 62512.

if i tried the sequence it would probably be fine for 99% of records entered but every once in a while it would fall flat on its face due to hitting a duplicate number.

but thanks for the suggestions and keep them coming guys - 'cause this problem is wrecking my head !!


Finu



 
Finbar - I am not sure what the loading table data types are but have you tried using your function in an "INSERT INTO TDCO_CUSTOMERS" statement, to be sure it works ?

I suspect this error is not related to the SQL*loader but is a data error from the function.



ORA-01461 can bind a LONG value only for insert into a LONG column
Cause: An attempt was made to insert a value from a LONG datatype into another datatype. This is not allowed.

Action: Do not try to insert LONG datatypes into other types of columns.



"Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top