Oracle SQL*Loader timestamp is error - oracle

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.

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 configure audit_trail='db,extended' at the time of oracle database creation?

Objective: to configure audit_trail='db,extended' at the time of oracle database creation
Environment:
CentOS7
Scenario:
Oracle11gXE (binaries installed but not database created)
init.ora:
db_name='xe'
memory_target='1024m'
processes='150'
sessions='20'
audit_file_dest='/u01/app/oracle/admin/xe/adump'
audit_trail='os'
#audit_trail='db,extended'
audit_sys_operations='true'
background_dump_dest='/u01/app/oracle/admin/xe/bdump'
core_dump_dest='/u01/app/oracle/admin/xe/cdump'
#data_pump_dir='/u01/app/oracle/admin/xe/dpdump'
user_dump_dest='/u01/app/oracle/admin/xe/udump'
db_block_size='8192'
db_domain=''
diagnostic_dest='/u01/app/oracle/product/11.2.0/xe/diag'
dispatchers='(protocol=tcp)(service=xe)'
shared_servers='4'
open_cursors='300'
remote_login_passwordfile='exclusive'
undo_management='auto'
undo_tablespace='xe_undo_tbs'
control_files=('/u01/app/oracle/oradata/11.2.0/xe/control_a/xe_a.ctl', '/u02/app/oracle/oradata/11.2.0/xe/control_b/xe_b.ctl', '/u03/app/oracle/oradata/11.2.0/xe/control_c/xe_c.ctl')
job_queue_processes='4'
db_recovery_file_dest_size='10g'
db_recovery_file_dest='/u01/app/oracle/oradata/11.2.0/xe/flash'
compatible='11.2.0'
log_archive_format='%r_%t_%s'
log_archive_dest_1='location=/u01/app/oracle/oradata/11.2.0/xe/archive1'
log_archive_dest_2='location=/u02/app/oracle/oradata/11.2.0/xe/archive2'
log_archive_dest_3='location=/u03/app/oracle/oradata/11.2.0/xe/archive3'
log_archive_dest_state_1='enable'
log_archive_dest_state_2='enable'
log_archive_dest_state_3='enable'
and dbcreate.sql
Prompt ****** SHUTTING DOWN....
SHUTDOWN IMMEDIATE;
Prompt ****** STARTING UP IN NOMOUNT MODE ....
STARTUP NOMOUNT pfile='/u01/app/oracle/oradata/11.2.0/xe/pfile/init_xe.ora';
Prompt ****** EXECUTING, CREATE DATABASE xe ....
CREATE DATABASE xe
USER sys IDENTIFIED BY xe2357
USER system IDENTIFIED BY xe2357
logfile group 1 ('/u01/app/oracle/oradata/11.2.0/xe/log_grp_a/xe_log1a.log', '/u02/app/oracle/oradata/11.2.0/xe/log_grp_b/xe_log1b.log', '/u03/app/oracle/oradata/11.2.0/xe/log_grp_c/xe_log1c.log') size 100m,
group 2 ('/u01/app/oracle/oradata/11.2.0/xe/log_grp_a/xe_log2a.log', '/u02/app/oracle/oradata/11.2.0/xe/log_grp_b/xe_log2b.log', '/u03/app/oracle/oradata/11.2.0/xe/log_grp_c/xe_log2c.log') size 100m,
group 3 ('/u01/app/oracle/oradata/11.2.0/xe/log_grp_a/xe_log3a.log', '/u02/app/oracle/oradata/11.2.0/xe/log_grp_b/xe_log3b.log', '/u03/app/oracle/oradata/11.2.0/xe/log_grp_c/xe_log3c.log') size 100m
maxlogfiles 32
maxlogmembers 4
maxloghistory 100
maxdatafiles 254
character set US7ASCII
national character set AL16UTF16
extent management local
datafile '/u01/app/oracle/oradata/11.2.0/xe/system/xe_system.dbf' size 325m reuse
sysaux datafile '/u01/app/oracle/oradata/11.2.0/xe/sysaux/xe_sys_aux.dbf' size 325m reuse
default tablespace xe_default_tbs
datafile '/u01/app/oracle/oradata/11.2.0/xe/default/xe_default.dbf'
SIZE 500M AUTOEXTEND ON MAXSIZE UNLIMITED
default temporary tablespace xe_temp_tbs
tempfile '/u01/app/oracle/oradata/11.2.0/xe/temp/xe_temp.dbf'
size 20m reuse
undo tablespace xe_undo_tbs
datafile '/u01/app/oracle/oradata/11.2.0/xe/undo/xe_undo.dbf'
size 200m reuse autoextend on maxsize unlimited;
Prompt ****** EXECUTING, SELECT INSTANCE_NAME, DATABASE_STATUS....
SELECT INSTANCE_NAME, DATABASE_STATUS, INSTANCE_ROLE FROM v$instance;
Prompt ****** SHUTTING DOWN....
SHUTDONW;
Prompt ****** EXITING SQLPLUS....
EXIT;
Prompt ****** CREATED DATABASE....
Script creates database properly, if set audit_trail='os' but it throws error if set audit_trail='db,extended'.
Error Log:
LRM-00121: 'db,extended' is not an allowable value for 'audit_trail'
ORA-01078: failure in processing system parameters
whether later it can be changed? will there be any issues, if doing so?
Please guide me in creating database through script with audit_trail='db,extended' in init.ora at the time of db creation.
Remove the quotes from around 'db,extended'
oracle:oklacity$ grep audit_trail initoklacity.ora
*.audit_trail='db,extended'
oracle:oklacity$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 21 16:39:23 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00121: 'db,extended' is not an allowable value for 'audit_trail'
SQL>
without quotes
oracle:oklacity$ grep audit_trail initoklacity.ora
*.audit_trail=db,extended
oracle:oklacity$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 21 16:41:06 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 726540288 bytes
Fixed Size 2216904 bytes
Variable Size 549456952 bytes
Database Buffers 167772160 bytes
Redo Buffers 7094272 bytes
Database mounted.
Database opened.

Error loading with Oracle sql loader

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

Resources