Error loading with Oracle sql loader - oracle

I really dont see where is the problem. I hope you can help.
Here is data file :
01/04/2013$1.300
01/10/2015$0.100
01/12/2016$0.500
This file has to be loaded in TableA :
2 columns : thedate (type DATE) and therate (type NUMBER(5,3))
Here is the ctl file :
LOAD DATA
REPLACE
INTO TABLE TABLEA
FIELDS TERMINATED BY '$'
TRAILING NULLCOLS
(THEDATE,
THERATE "to_number(:THERATE, '99999D999', 'NLS_NUMERIC_CHARACTERS=''.,''')")
Loading, I have this error in the log on all records :
Column Name Position Len Term Encl Datatype
THEDATE FIRST * $ CHARACTER
THERATE NEXT * $ CHARACTER
SQL string for column : "to_number(:THERATE, '99999D999', 'NLS_NUMERIC_CHARACTERS=''.,''')"
Record 1: Rejected - Error on table TABLEA, column THERATE.
ORA-01438: value larger than specified precision allowed for this column

The same code(just few modification but not relevant to your error) works fine for me.
[oracle#localhost Desktop]$ cat data.txt
01/04/2013$1.300
01/10/2015$0.100
01/12/2016$0.500
[oracle#localhost Desktop]$ cat control.ctl
LOAD DATA
INFILE 'data.txt'
REPLACE
INTO TABLE TABLEA
FIELDS TERMINATED BY '$'
TRAILING NULLCOLS
(THEDATE "to_date(:THEDATE, 'MM-DD-YYYY')",
THERATE "to_number(:THERATE, '99999D999', 'NLS_NUMERIC_CHARACTERS=''.,''')")
[oracle#localhost Desktop]$ sqlldr jay/jay control file=control.ctl
SQL*Loader: Release 11.2.0.4.0 - Production on Fri Nov 25 16:04:50 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4
[oracle#localhost Desktop]$ sqlplus jay/jay
SQL*Plus: Release 11.2.0.4.0 Production on Fri Nov 25 16:04:56 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from tablea;
THEDATE THERATE
--------- ----------
04-JAN-13 1.3
10-JAN-15 .1
12-JAN-16 .5

Related

I am getting ORA-04043: object does not exist error in SQL loader. When command is being executed getting table does not exist error

CSV FILE CONTENT
portal,,
ex portal,,
,,
i_id,i_name,risk
1,a,aa
2,b,bb
3,c,cc
4,d,dd
5,e,ee
6,f,ff
7,g,gg
8,h,hh
9,i,ii
10,j,jj
CONTROL FILE CONTENT
options (
skip=4,
PARALLEL=true,
DIRECT=true
)
LOAD DATA
INFILE 'E:\sqlloader\testfile.csv'
APPEND
INTO TABLE LOADER_TAB
FIELDS TERMINATED BY ","
(
i_id,
i_name,
risk
)
I am getting object does not exist but table name does exist in the schema system
select tab.owner, tab.STATUS
from dba_tables tab
where tab.TABLE_NAME = 'LOADER_TAB';
Also tried by giving scema_name.table_name but no luck.
options (
skip=4,
PARALLEL=true,
DIRECT=true
)
LOAD DATA
INFILE 'E:\sqlloader\testfile.csv'
APPEND
INTO TABLE SYSTEM.LOADER_TAB
FIELDS TERMINATED BY ","
(
i_id,
i_name,
risk
)
Can someone help me on this I had searched for the answer and did all possible way but not getting the solution.
You're almost there - here's a top to bottom run of the code, the only change being I've created a schema to hold the table and the path names for the CSV file. So follow the demo below and if yours does not get the same result, edit the question with the full output similar to below. Also, if you still get issues, try it without DIRECT/PARALLEL which will help us dig deeper into the "why".
SQL> create user myuser identified by mypassword;
User created.
SQL> alter user myuser quota unlimited on users;
User altered.
SQL> grant connect, resource to myuser;
Grant succeeded.
SQL> create table myuser.LOADER_TAB(i_id number(10),i_name varchar2(30),risk varchar2(30));
Table created.
x:\tmp>sqlldr userid=myuser/mypassword#db19_pdb1 control=loader.ctl
SQL*Loader: Release 19.0.0.0.0 - Production on Tue Nov 2 11:38:58 2021
Version 19.12.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
Path used: Direct
Load completed - logical record count 10.
Table LOADER_TAB:
10 Rows successfully loaded.
Check the log file:
loader.log
for more information about the load.
x:\tmp>sqlplus myuser/mypassword#db19_pdb1
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 2 11:39:21 2021
Version 19.12.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Tue Nov 02 2021 11:38:58 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
SQL> select * from loader_tab;
I_ID I_NAME RISK
---------- ------------------------------ ------------------------------
1 a aa
2 b bb
3 c cc
4 d dd
5 e ee
6 f ff
7 g gg
8 h hh
9 i ii
10 j jj
10 rows selected.

How to store sql query output in variable in shell script

I am trying to store the value of sql query output in a variable using shell script.
size=`${PATH_TO_CLIENT}sqlplus $IMPUSER/$IMPPWD#$ENDPOINT<< EOF
select owner, sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'XXXX' group by owner;
exit;
EOF`
echo "Total data is ${size}"
The output I am getting is
**Total data is**
SQL*Plus: Release 21.0.0.0.0 - Production on Fri May 14 11:06:42 2021
Version 21.1.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Fri May 14 2021 11:01:02 -04:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
SQL>
OWNER
--------------------------------------------------------------------------------
SIZE_GB
----------
XXXXXXX
12.2345
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
Inside the variable full connection string and sql query output all are getting stored. I just want to get value like $size=12.2345 Please tell me how to get that
The size value might be assigned to the current variable through use of the following code block
size=$(sqlplus -S /nolog << EOF
conn $IMPUSER/$IMPPWD#$ENDPOINT
whenever sqlerror exit sql.sqlcode
SET PAGES 0
SELECT SUM(bytes)/1024/1024/1024 FROM dba_segments WHERE owner = 'XXXX';
EOF
)
echo "Total data is "$size
where
keeping owner column and group by clause are redundant as
returning only one column value for a single schema
no need to alias the calculated value as not needed for the returning result while hiding the column title through use of SET PAGES 0 command
using direct connection is not safe, but use sqlplus -S /nolog before
schema connection in order to hide the password while listed by
anbody through ps command.
You can use this:
size=`${PATH_TO_CLIENT}sqlplus -s $IMPUSER/$IMPPWD#$ENDPOINT <<EOF
set echo off
set feedback off
set heading off
set pages 0
select sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'SYS';
exit;
EOF`
echo "Total data is ${size}"
If the output is consistent with newlines, you could use:
size=`${PATH_TO_CLIENT}sqlplus $IMPUSER/$IMPPWD#$ENDPOINT<< EOF | sed -n '/^\s*SIZE_GB$/{n;n;n;p}'
select owner, sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'XXXX' group by owner;
exit;
EOF`
It will return the third line after line which contains 'SIZE_GB'.

topic is about sqlloader,table name is course and the filepath is mention

error:C:\Users\ARAVIND>SQLLDR login/password
control = D:\NEW\DATAA.CSV.txt
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Apr 15 22:02:44 2021
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL*Loader-350: Syntax error at line 1.
Expecting keyword LOAD, found "CID".
CID, CNAME
^
LOAD DATA
INFILE 'D:\NEW\DATAA.CSV.txt'
INTO TABLE COURSE
FIELDS TERMINATED BY ','
(CID,CNAME)
If you do it properly, it works OK.
Input file (dataa.csv.txt) contents:
1,Little
2,Foot
Control file (test36.ctl) (location is, of course, different; I don't have your filesystem):
load data
infile 'm:\dataa.csv.txt'
truncate into table course
fields terminated by ','
(cid, cname)
Target table (course) description:
SQL> desc course
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
CID NUMBER
CNAME VARCHAR2(20)
Loading session & the result:
SQL> $sqlldr scott/tiger#orcl control=test36.ctl log=test36.log
SQL*Loader: Release 11.2.0.1.0 - Production on Pet Tra 16 09:12:37 2021
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
Commit point reached - logical record count 2
SQL> select * from course;
CID CNAME
---------- --------------------
1 Little
2 Foot
SQL>

How to return just the values from sqlplus using set variables?

Can someone please help me here?
Looks like I setup the right values in the set variables, but it's returning lot of things. See below:
################################
# Main
################################
RETVAL=`sqlplus user/pass#DB <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT process_id, source, destination, type FROM table WHERE process_id IN ('12311','12322');
EXIT;
EOF`
if [ -z "$RETVAL" ]; then
echo "No rows returned from database"
exit 0
else
echo $RETVAL
fi
The output is:
SQL*Plus: Release 9.2.0.8.0 - Production on Thu Jun 27 19:37:39 2013 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> SQL> 12311 ,AAA BBB ,2 12322 ,AAA BBB ,5 SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
I just would like:
12311, AAA, BBB, 2,
12322, AAA, BBB, 5,
*the commas is also not right
Use -s option of sqlplus to supress:
sqlplus -s user/pass#DB

Oracle SQL*Loader timestamp is error

My control file is
ACCESS_TIME TERMINATED BY "" "TO_TIMESTAMP_TZ(:ACCESS_TIME,'YYYY/MM/DD HH24:MI:SS:FF TZR')"
Data file is
2012/11/12 15:18:00:765 CST
But when I run SQL*Loader to commit the data, in the database ACCESS_TIME does not match data file.
2012/11/13 05:18:00:765000000
if you're seeing that behaviour then the table column must be time stamp with local time zone and you are in Singapore etc (gmt +8) eg:
SQL> alter session set time_zone='+08:00';
Session altered.
SQL> create table test (access_time timestamp with local time zone);
Table created.
SQL> host sqlldr test/test control=/tmp/load.ctl log=/tmp/load.log
SQL*Loader: Release 11.2.0.1.0 - Production on Mon Nov 12 13:26:14 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
SQL> select * from test;
ACCESS_TIME
---------------------------------------------------------------------------
13-NOV-12 05.18.00.765000
SQL> alter session set time_zone='-06:00';
Session altered.
SQL> select * from test;
ACCESS_TIME
---------------------------------------------------------------------------
12-NOV-12 15.18.00.765000
SQL> host cat /tmp/load.ctl
load data
infile *
replace
into table test
( ACCESS_TIME terminated by "" "TO_TIMESTAMP_TZ(:ACCESS_TIME,'YYYY/MM/DD HH24:MI:SS:FF TZR')"
)
begindata
2012/11/12 15:18:00:765 CST
if you want to preserve the CST part and not convert it then define your table as TIMESTAMP WITH TIME ZONE.
SQL> create table test (access_time timestamp with time zone);
Table created.
SQL> host sqlldr test/test control=/tmp/load.ctl log=/tmp/load.log
SQL*Loader: Release 11.2.0.1.0 - Production on Mon Nov 12 13:27:56 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
SQL> select * from test;
ACCESS_TIME
---------------------------------------------------------------------------
12-NOV-12 15.18.00.765000 CST
Do a:
select SESSIONTIMEZONE from dual;
You insert your data in Central Standard Time. When you select the data it is probably displayed in your sessions (local) timezone.

Resources