Issue while using sequence in sqlloader [message #538402] |
Thu, 05 January 2012 14:30 |
|
I have created table and sequence in a schema named SCH1.
CREATE TABLE TEST_LOAD (SEQ_NO NUMBER, ADDRESS VARCHAR2(500),CREATE_DATE DATE);
CREATE SEQUENCE LOAD_SEQ MINVALUE 1 MAXVALUE 99999 START WITH 1 INCREMENT BY 1;
Now i am loading data to this table from using SQL*Loader from a different schema named SCH2. My control file looks like this
LOAD DATA
INTO TABLE SCH1.TEST_LOAD APPEND
fields terminated by "~"
TRAILING NULLCOLS
(
SEQ_NO "SCH1.LOAD_SEQ.NEXTVAL",
ADDRESS,
CREATE_DATE "sysdate"
)
When i execute the sqlldr command from shell script, Load completed successfully but sysdate is the only value available in the table without sequence number and address(data from data file). Please help what i am doing wrong here.
Also i have to mention the schema name for referencing the table and sequence in the control file even after created synonym.
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538418 is a reply to message #538402] |
Thu, 05 January 2012 20:18 |
|
Barbara Boehmer
Messages: 9101 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
It would have helped if you had provided some sample data. Since you didn't I made some up, in order to provide a demonstration. In the control file, you need to list the columns in the data file first, then the sequence and sysdate. Sch1 needs to grant insert on the table and select on the sequence to sch2.
-- test.dat data file:
123 someplace, somewhere
456 anyplace, nowhere
-- test.ctl control file
-- with columns in data file first:
LOAD DATA
INTO TABLE SCH1.TEST_LOAD APPEND
fields terminated by "~"
TRAILING NULLCOLS
(
ADDRESS,
SEQ_NO "SCH1.LOAD_SEQ.NEXTVAL",
CREATE_DATE "sysdate"
)
-- sch1 creates table and sequence,
-- then grants insert on table and select on sequence to sch2:
SCH1@orcl_11gR2> CREATE TABLE TEST_LOAD (SEQ_NO NUMBER, ADDRESS VARCHAR2(500),CREATE_DATE DATE);
Table created.
SCH1@orcl_11gR2> CREATE SEQUENCE LOAD_SEQ MINVALUE 1 MAXVALUE 99999 START WITH 1 INCREMENT BY 1;
Sequence created.
SCH1@orcl_11gR2> grant insert on test_load to sch2
2 /
Grant succeeded.
SCH1@orcl_11gR2> grant select on load_seq to sch2
2 /
Grant succeeded.
-- sch2 loads data:
SCH2@orcl_11gR2> host sqlldr sch2/sch2 control=test.ctl data=test.dat log=test.log
-- results:
SCH1@orcl_11gR2> column address format a30
SCH1@orcl_11gR2> select * from test_load
2 /
SEQ_NO ADDRESS CREATE_DA
---------- ------------------------------ ---------
1 123 someplace, somewhere 05-JAN-12
2 456 anyplace, nowhere 05-JAN-12
2 rows selected.
|
|
|
Re: Issue while using sequence in sqlloader [message #538449 is a reply to message #538418] |
Fri, 06 January 2012 01:56 |
|
Thank you for helping me. I have modified my control as suggested and provided grant select on the sequence to SCH2. Records are getting inserted without the sequence number(with null).
What grant i should provide for the sch2 for accessing the sequence. Also is it possible to have the table name and sequence name alone in the control file without having the schema in front. If i remove the schema then it throws table not found error.
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538480 is a reply to message #538455] |
Fri, 06 January 2012 08:10 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
Show us.
You say what you did, but how do we know you actually did it.
Show ALL relevant pieces (I leave that for you to figure out).
The GRANT command has been shown to you.
Additionally, what does your logfile show?
|
|
|
Re: Issue while using sequence in sqlloader [message #538482 is a reply to message #538480] |
Fri, 06 January 2012 08:40 |
|
Please find the logs here
SQL*Loader: Release 10.2.0.4.0 - Production on Fri Jan 6 08:33:23 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Control File: /loc/test.ctl
Data File: /loc/Content.txt
Bad File: /loc/Content_BAD.txt
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 10000
Continuation: none specified
Path used: Direct
Table SCH1.TEST_LOAD, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ADDRESS FIRST * , CHARACTER
CREATE_DATE NEXT * , CHARACTER
SQL string for column : "sysdate"
SEQ_NO NEXT * , CHARACTER
SQL string for column : "SCH1.LOAD_SEQ.NEXTVAL"
Table SCH1.TEST_LOAD:
1 Row successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Control file
LOAD DATA
INTO TABLE SCH1.TEST_LOAD APPEND
fields terminated by "~"
TRAILING NULLCOLS
(
ADDRESS,
CREATE_DATE "sysdate",
SEQ_NO "SCH1.LOAD_SEQ.NEXTVAL"
)
|
|
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538507 is a reply to message #538493] |
Fri, 06 January 2012 10:47 |
|
Here is what i have used.
I am creating this table and sequence in a PL/SQL stored procedure using Dynamic SQL statement in schema SCH1
EXECUTE IMMEDIATE 'CREATE TABLE TEST_LOAD (SEQ_NO NUMBER, ADDRESS VARCHAR2(500),CREATE_DATE VARCHAR2(25))';
EXECUTE IMMEDIATE 'CREATE SEQUENCE LOAD_SEQ MINVALUE 1 MAXVALUE 99999 START WITH 1 INCREMENT BY 1';
Grants provided to the table and sequence
EXECUTE IMMEDIATE 'GRANT select on LOAD_SEQ to SCH2'
EXECUTE IMMEDIATE 'GRANT select on TEST_LOAD to SCH2';
EXECUTE IMMEDIATE 'GRANT INSERT, UPDATE, DELETE ON TEST_LOAD TO SCH2';
Control file
LOAD DATA
INTO TABLE SCH1.TEST_LOAD APPEND
fields terminated by ","
TRAILING NULLCOLS
(
ADDRESS,
CREATE_DATE "sysdate",
SEQ_NO "SCH1.LOAD_SEQ.NEXTVAL"
)
Data file(just a single line)
Command line running from shell script in unix environment
sqlldr $username/$password@$tnsname errors=10000 control="loc/test.ctl" data="loc/Content.txt" log="loc/test_load.log" bad="loc/Content_BAD.txt" direct=true
Please let me know if you need any info. I don't why can't be able to insert the sequence values.
Also please suggest how could i use the table and sequence name alone in the control without schema name.
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538516 is a reply to message #538511] |
Fri, 06 January 2012 11:27 |
|
No results were found for this query. But i have got the below output with a modified query
Query
select *
from all_tab_privs
where
table_name = 'LOAD_SEQ';
Output
GRANTOR GRANTEE TABLE_SCHEMA TABLE_NAME PRIVILEGE GRANTABLE HIERARCHY
------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------------------------------------- --------- ---------
SCH1 SCH1_SEL_ROL SCH1 LOAD_SEQ SELECT NO NO
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538532 is a reply to message #538517] |
Fri, 06 January 2012 12:58 |
|
Thanks for the clarification. I will try providing the grant as the same what you did.
But as per my requirement i will be creating this table and sequence when a job runs. I will insert some data from the existing tables and indeed i want the data from this text file as well. I am invoking this procedure for this table and sequence creation from a shell script. This table and sequence will be dropped once the job is over.
So I am planning to have a SQL file where i can provide the grant once sequence is created. Please suggest if this is good approach or i can follow some other approach.
Thanks again.
|
|
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538577 is a reply to message #538536] |
Sat, 07 January 2012 05:47 |
|
Thanks all for your valid explanation. Now i have moved my DDL statements out of the procedure. I am able to perform the bulk load using SQL *Loader sequence, it really works perfectly.
I have provided the grants through a separate SQL script file for SCH2. But still unable to use the LOAD_SEQ in the control file.
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538609 is a reply to message #538589] |
Sat, 07 January 2012 10:07 |
|
Please find the control file which is loading data without seq_no
LOAD DATA
INTO TABLE TEST_LOAD APPEND
fields terminated by ","
TRAILING NULLCOLS
(
ADDRESS,
CREATE_DATE "sysdate",
SEQ_NO "SCH1.LOAD_SEQ.NEXTVAL"
)
Control file with SQL *Loader sequence(Works perfectly)
LOAD DATA
INTO TABLE TEST_LOAD APPEND
fields terminated by ","
TRAILING NULLCOLS
(
ADDRESS,
CREATE_DATE "sysdate",
SEQ_NO SEQUENCE(MAX,1)
)
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538738 is a reply to message #538611] |
Mon, 09 January 2012 04:32 |
|
No rows found the above query for 'LOAD_SEQ'. I have given select grant on LOAD_SEQ using the below statement
GRANT select on LOAD_SEQ to SCH2;
Below is the only record available for LOAD_SEQ in table all_tab_privs
"GRANTOR" "GRANTEE" "TABLE_SCHEMA" "TABLE_NAME" "PRIVILEGE" "GRANTABLE" "HIERARCHY"
"SCH1" "SCH1_SEL_ROL" "SCH1" "LOAD_SEQ" "SELECT" "NO" "NO"
|
|
|
|
|
|
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538764 is a reply to message #538752] |
Mon, 09 January 2012 06:14 |
|
Query executed
[code]
select *
from all_tab_privs
where grantee = 'SCH2'
and table_name = 'LOAD_SEQ';
[code]
Results:
GRANTOR GRANTEE TABLE_SCHEMA TABLE_NAME PRIVILEGE GRANTABLE HIERARCHY
------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------------------------------------- --------- ---------
0 rows selected
|
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538783 is a reply to message #538780] |
Mon, 09 January 2012 07:15 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Here's the options I can think of.
1) You did the grant and select in different DBs.
2) Someone/something else immediately revoked the grant after you granted it.
3) SCH1 has view/table called all_tab_privs that isn't the real all_tab_privs. Run the following query to check:
select owner, object_type from all_objects where object_name = 'ALL_TAB_PRIVS';
Result should be:
OWNER OBJECT_TYPE
------------------------------ -------------------
SYS VIEW
PUBLIC SYNONYM
|
|
|
Re: Issue while using sequence in sqlloader [message #538789 is a reply to message #538783] |
Mon, 09 January 2012 07:46 |
|
1)I have done the grant and select in same DB
2)My job is one which uses this sequence, so there is no chance for this grant to be revoked
3)I ran the query and got the same output which you have shared.
I need help in another issue i am facing in SQL *Loader. I have a string in the text file which has a non-ASCII character "ümlat" and this string uploaded to DB as "�mlat". How can i upload the exact string (ümlat) which is there in the text file.
|
|
|
Re: Issue while using sequence in sqlloader [message #538792 is a reply to message #538789] |
Mon, 09 January 2012 08:53 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
vel4ever wrote on Mon, 09 January 2012 13:461)I have done the grant and select in same DB
2)My job is one which uses this sequence, so there is no chance for this grant to be revoked
3)I ran the query and got the same output which you have shared.
Well oracle is saying the grant is created, but if it exists all_Tab_privs should show it. So either:
1) Oracle is lying - in which case you need to raise a bug with oracle support
2) Somone/something is dropping it.
Have you got a DBA who can check what is happening?
|
|
|
|
|
Re: Issue while using sequence in sqlloader [message #538805 is a reply to message #538802] |
Mon, 09 January 2012 09:53 |
|
1) Yes, character is correct in the text file
2) No, character is not getting to DB correctly
Data in text file:
http://www.sample.com/ümlat.html&q=user
Data in DB after loading
[url]http://www.sample.com/?mlat.html&q=user[/url]
Result for query SELECT ASCIISTR(NON_ASCII_COL) FROM TABLE1; is
http://www.sample.com/\FFFDmlat.html&q=user
[Updated on: Mon, 09 January 2012 09:54] Report message to a moderator
|
|
|
|