External table - Function
Hi All,
How to use the oracle in-built functions in the external table. I am trying to transform the value like CONTRACT_RATE TO_NUMBER(REPLACE(:CONTRACT_RATE,'%','')) which I use in SQL*Loader.
I am using 11g
Thanks in advance,
Jagadish Kumar A.M
You can use them when you're SELECTing from the external table.
So, simply define the columns in your external table as strings.
And then just:
select TO_NUMBER(REPLACE(CONTRACT_RATE,'%','')) CONTRACT_RATE
from your_external_table
Similar Messages
-
Calling functions in External tables
I'm trying to create an External table and assigning a function return value to a column. But I'm getting error when trying to retrieve data from the table. Below are the scripts and error message. Can someone point me the correction.
create or replace
function v_sum ( v_num1 number, v_num2 number) return number as
v_res number;
begin
v_res := v_num1 + v_num2;
return v_res;
end;
create table tab_xyz
col1 varchar2(10),
col2 varchar2(10),
col3 number
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER DEFAULT DIRECTORY "MF_DIR" ACCESS PARAMETERS (
records delimited BY newline
load when (col1 != blanks)
badfile mf_dir:'xyz.csv.bad'
logfile mf_dir:'xzy.csv.log'
discardfile mf_dir:'xyz.csv.dsc'
fields terminated BY ',' optionally enclosed BY '"' MISSING FIELD VALUES ARE NULL
(col1,
col2,
col3 v_sum(3,4))
LOCATION ('xyz.csv' ))
REJECT LIMIT 100;
Error starting at line 4 in command:
select * from tab_xyz
Error report:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-00554: error encountered while parsing access parameters
KUP-01005: syntax error: found "identifier": expecting one of: "binary_double, binary_float, comma, char, date, defaultif, decimal, double, float, integer, (, nullif, oracle_date, oracle_number, position, raw, recnum, ), unsigned, varrawc, varchar, varraw, varcharc, zoned"
KUP-01008: the bad identifier was: v_sum
KUP-01007: at line 9 column 11
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.Thanksfields terminated BY ',' optionally enclosed BY '"' MISSING FIELD VALUES ARE NULL
(col1,
col2,
col3 EXPRESSION "v_sum(3,4)")
LOCATION ('xyz.csv' ))
REJECT LIMIT 100;
KUP-01005: syntax error: found "identifier": expecting one of: "binary_double, binary_float, comma, char, date, defaultif, decimal, double, float, integer, (, nullif, oracle_date, oracle_number, position, raw, recnum, ), unsigned, varrawc, varchar, varraw, varcharc, zoned"
KUP-01008: the bad identifier was: EXPRESSION -
UPPER function in external table definition ... ?
Greetings
Is there a way to specify a SQL function, like UPPER, in an external table column definition?
I know I can do it with SQL*Loader in the control file but I haven't found a way to do it in OWB?
I realize there are ways outside of the external table using a view, etc. but I'd like to reference the external table directly without having to create yet another object.
Thanks very much!!
-garyGreetings
Is there a way to specify a SQL function, like UPPER, in an external table column definition?
I know I can do it with SQL*Loader in the control file but I haven't found a way to do it in OWB?
I realize there are ways outside of the external table using a view, etc. but I'd like to reference the external table directly without having to create yet another object.
Thanks very much!!
-gary -
How to use lpad function in external table definition?
i need to modify one column of .csv file using lpad and want to insert it in external table.
lpad(AMT,3,'0')
Please send the codeHi,
Please read SQL and PL/SQL FAQ
Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
The information you posted are quite poor. You don't expect to have an answer with such few details.
Anyway external table are read only.
Regards.
Al -
DATE fields and LOG files in context with external tables
I am facing two problems when dealing with the external tables feature in Oracle 9i.
I created an External Table with some fileds with the DATE data type . There were no issues during the creation part. But when i query the table, the DATE fields are not properly selected though the data is there in the files. Is there any ideas to deal with this ?
My next question is regarding the log files. The contents in the log file seems to be growing when querying the external tables. Is there a way to control this behaviour?
Suggestions / Advices on the above two issues are welcome.
Thanks
LakshminarayananHi
If you have date datatypes than:
select
greatest(TABCASER1.CASERRECIEVEDDATE, EVCASERS.FINALEVDATES, EVCASERS.PUBLICATIONDATE, EVCASERS.PUBLICATIONDATE, TABCASER.COMPAREACCEPDATE)
from TABCASER, TABCASER1, EVCASERS
where ...-- join and other conditions
1. greatest is good enough
2. to_date creates date dataype from string with the format of format string ('mm/dd/yyyy')
3. decode(a, b, c, d) is a function: if a = b than return c else d. NULL means that there is no data in the cell of the table.
6. to format the date for display use to_char function with format modell as in the to_date function.
Ott Karesz
http://www.trendo-kft.hu -
How to ''give'' error for this case of an EXTERNAL TABLE?
Our external table routine works fine:
-- We have a csv file with 2 cols.
-- When we create the table referring the csv it works fine.
-- Even if the csv has more the 2 cols, the ET command only takes the 2 cols and it works fine.
-- Now, users are saying that if the csv has more than 2 cols, the ET command should give an error
I went through the command but cannot find any clause which will do this.
Is there any other way or workaround?
CREATE TABLE <table_name> (
<column_definitions>)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY <oracle_directory_object_name>
ACCESS PARAMETERS (
RECORDS DELIMITED BY newline
BADFILE <file_name>
DISCARDFILE <file_name>
LOGFILE <file_name>
[READSIZE <bytes>]
[SKIP <number_of_rows>
FIELDS TERMINATED BY '<terminator>'
REJECT ROWS WITH ALL NULL FIELDS
MISSING FIELD VALUES ARE NULL
(<column_name_list>))\
LOCATION ('<file_name>'))
[PARALLEL]
REJECT LIMIT <UNLIMITED | integer>;
Is it possible to use the READSIZE?
Edited by: Channa on Sep 23, 2010 2:28 AM-- Now, users are saying that if the csv has more than 2 cols, the ET command should give an error
I went through the command but cannot find any clause which will do this.
Is there any other way or workaround?I looked at Serverprocess' sql*loader script and did not see how that would answer your question - how to raise an error if the file has more than 2 columns. If I missed something can Serverprocess explain?
I can't think of a direct way to do this with your external table either, but there may be indirect ways. Some brainstorming ideas of perhaps dubious usefulness follow.
Placing a view over the external table can limit results to the first two columns but won't raise an error.
A pipelined function can read the external table, check for data where there shouldn't be any, and raise an exception when you find data in columns where there should not be any.
Similarly, you could ditch the external table and use utl_file to read the file, manually parsing and checking the data. LOTS more work but more control on your end. External tables are much easer to use :(
Or, first load the external table into a work table before the "real" select. Check the work table for the offending data programatically and raise an error if data is where it should not be. You could keep the existing external table and not have to do a lot of recoding.
Or, also load the data into an otherwise unneeded global temporary table first. Use a trigger on the load to look for the unwanted data and raise an error if offending data is there
These ideas are boiling down to variations on validating the data before you use it.
Good luck! -
Error in creating an external table referring to a XML file
I've got an XML file and I've tried to create an external table referring to it in this way:
CREATE TABLE mytable
XML_DATA_COLUMN XMLType
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER DEFAULT DIRECTORY TEST_DIR
ACCESS PARAMETERS ( records delimited BY newline
(XML_DATA_COLUMN LOB) ) LOCATION ( 'myfile.xml' )
where TEST_DIR is the directory where myfile.xml is stored,
but I get this message:
Error at Command Line:3 Column:4
Error report:
SQL Error: ORA-30656: column type not supported on external organized table
30656.0000 - "column type not supported on external organized table"
*Cause: Attempt to create an external organized table with a column
of type LONG, LOB, BFILE, ADT, or VARRAY.
*Action: These column types are not supported, change the DDL.
I want to have in the XML_DATA_COLUMN the content of myfile.xml so as to handle it by using extract and extractvalue functions.
My oracle version is 10gR2 Express Edition
Thanks!The examples in the following thread include an insert, but you could also use the select statement alone without the insert.
http://www.orafaq.com/forum/mv/msg/172162/511897/0/#msg_511897 -
Error while importing external table
Hello,
I am getting the following error message when trying to import an external table:
SQL Exception
SQL Exception
Repository Error:SQL Exception..
Class Name: CacheMediator.
Method Name: getDDEntryFromDB.
Repository Error Message: ORA-22992: cannot use LOB locators selected from remote tables
I am using the "import..."- function of "external tables" in warehouse target module. The external table is working correctly when accessing it via sqlplus.
We are using owb version 10.2.0.1.
Any help would be appreciated.
Best regards
AlexanderMy friends, this a documented BUG into Metalink, but there is no solution.
I used a simple workaround:
1. I created the external table into the database;
2. I created the external table into the OWB repository;
3. I DIDN'T DEPLOY THE EXTERNAL TABLE TO THE DATABASE;
4. I used the external table into my mappings with no problems;
5. Finishing, I deployed my mappings to the database without any errors.
Hope to help!,
Gustavo. -
Comparison of Data Loading techniques - Sql Loader & External Tables
Below are 2 techniques using which the data can be loaded from Flat files to oracle tables.
1) SQL Loader:
a. Place the flat file( .txt or .csv) on the desired Location.
b. Create a control file
Load Data
Infile "Mytextfile.txt" (-- file containing table data , specify paths correctly, it could be .csv as well)
Append or Truncate (-- based on requirement) into oracle tablename
Separated by "," (or the delimiter we use in input file) optionally enclosed by
(Field1, field2, field3 etc)
c. Now run sqlldr utility of oracle on sql command prompt as
sqlldr username/password .CTL filename
d. The data can be verified by selecting the data from the table.
Select * from oracle_table;
2) External Table:
a. Place the flat file (.txt or .csv) on the desired location.
abc.csv
1,one,first
2,two,second
3,three,third
4,four,fourth
b. Create a directory
create or replace directory ext_dir as '/home/rene/ext_dir'; -- path where the source file is kept
c. After granting appropriate permissions to the user, we can create external table like below.
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
location ('file.csv')
reject limit unlimited;
d. Verify data by selecting it from the external table now
select * from ext_table_csv;
External tables feature is a complement to existing SQL*Loader functionality.
It allows you to –
• Access data in external sources as if it were in a table in the database.
• Merge a flat file with an existing table in one statement.
• Sort a flat file on the way into a table you want compressed nicely
• Do a parallel direct path load -- without splitting up the input file, writing
Shortcomings:
• External tables are read-only.
• No data manipulation language (DML) operations or index creation is allowed on an external table.
Using Sql Loader You can –
• Load the data from a stored procedure or trigger (insert is not sqlldr)
• Do multi-table inserts
• Flow the data through a pipelined plsql function for cleansing/transformation
Comparison for data loading
To make the loading operation faster, the degree of parallelism can be set to any number, e.g 4
So, when you created the external table, the database will divide the file to be read by four processes running in parallel. This parallelism happens automatically, with no additional effort on your part, and is really quite convenient. To parallelize this load using SQL*Loader, you would have had to manually divide your input file into multiple smaller files.
Conclusion:
SQL*Loader may be the better choice in data loading situations that require additional indexing of the staging table. However, we can always copy the data from external tables to Oracle Tables using DB links.Please let me know your views on this.
-
Variable filename external table
I have written a script to import data from a .csv into a table in Apex:
CREATE TABLE APEX_USER_002.INK_KASSA_LOAD
KASS_DTM VARCHAR2(255),
KASS_ID VARCHAR2(255),
KASS_VKP_COD VARCHAR2(255),
KASS_VKP_OMS VARCHAR2(255),
KASS_COD VARCHAR2(255),
KASS_OMS VARCHAR2(255),
KASS_PRS_COD VARCHAR2(255),
KASS_PRS_OMS VARCHAR2(255)
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER
DEFAULT DIRECTORY AFM_KASSA_IN
ACCESS PARAMETERS
RECORDS DELIMITED BY NEWLINE CHARACTERSET WE8MSWIN1252
LOGFILE AFM_KASSA_LOG: 'log.log'
BADFILE AFM_KASSA_BAD: 'badfile.bad'
NODISCARDFILE
SKIP 1
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
LRTRIM
MISSING FIELD VALUES ARE NULL
KASS_DTM,
KASS_ID,
KASS_VKP_COD,
KASS_VKP_OMS,
KASS_COD,
KASS_OMS,
KASS_PRS_COD,
KASS_PRS_OMS
LOCATION ('variable_filename.csv')
It works fine when I put the name of the .csv hardcoded in the script. Like this: LOCATION ('Kassa_20130406130014.csv')
I have written a function which returns the filename, but when I use the function in LOCATION (function()) I get an error: ora-00905: missing keyword
How can I call a function in LOCATION ()?Hi,
I'm not sure but I think you need re-create external table.
Create procedure that drops and re-creates external table dynamically with new file name.
Or use e.g. DBMS_SCHEDULER to call OS script that renames file always to same name for external table.
Regards,
Jari -
Can we cleanse and transform data at flat file or external table level?
Hi,
I have some data that I want to cleanse and transform. I don't want to cleanse it after i populate the external table, I want to get done with it at flat file level or while populating the external table. Can we cleanse and transform data at flat file or external table level through Oracle or OWB 11.2? Is it possible to run a conditional load (i.e. having a where clause or if-else-then) for an external table? Can we call oracle functions for an external table at the time of creation?
Thanks in advance.
Regards,
Ann.Hi Oleg,
Thanks a lot for the clarification. :)
So is there a way that I can clease the data within the text file through Oracle or OWB? I have datatype mismatches in the data and most of my data is getting rejected because of that. The way I can think of, for solving this problem, is to create the external table with all fields with datatype varchar and then cleansing the data. But it doesn't seem very effecient plus it will get very complicated because I have almost 80-90 fields.
Any help?
Thanks and regards,
Ann. -
Remove Enter Sign in External Table
Dear Gurus,
I have external table with show 'enter sign'.
I thought it was blank space but not.
How to remove it?since function TRIM can't remove it.
Records delimited by newline -> is that any syntax to prevent enter sign appear?
Thank you
Regards
JOEThis seems to be a TOAD issue - pl ask in the TOAD forums - http://toadworld.com/Discussions/tabid/824/Default.aspx
HTH
Srini -
UPPER() in external table definition
Hi,
Is it possible to apply the UPPER() function to character columns within an external table definition using the ORACLE_LOADER driver?
I've tried myself and have looked through the documentation, and it seems like this is not possible ... just wanted to double-check before moving forward with a different solution.
Thanks.
- k r
Message was edited by:
kenny r.I've never seen an example of doing it nor do I see anywhere in the syntax that lends itself to such manipulation.
Consider creating a view. -
Problem with external PHP function
I am working on a registration page. This is the list of
statements I have that must be true for the registration to
succeed:
if(isset($_POST['register']))
if($_POST['username'] != ''
&&(strlen($_POST['username']) >= 4)
&&(strlen($_POST['username']) <= 20)
&& alpha_numeric($_POST['username']) == TRUE
&& $_POST['password'] != ''
&&(strlen($_POST['password']) >= 4)
&&(strlen($_POST['password']) <= 20)
&& alpha_numeric($_POST['password']) == TRUE
&& $_POST['password2'] == $_POST['password']
&& $_POST['email'] != ''
&& valid_email($_POST['email']) == TRUE
&& $_POST['email2'] == $_POST['email']
&& $_POST['agree'] == TRUE
&& checkUnique('user_data', 'username',
$_POST['username']) == TRUE
&& checkUnique('user_data', 'email',
$_POST['email']) == TRUE)
The external 'checkUnique' functions at the bottom simply
don't seem to work. I am easily able to sign up with a username or
email that already exists in the database.
This is the code for the external function:
function checkUnique($table, $field, $compared)
$query = mysql_query('SELECT
'.mysql_real_escape_string($field).' FROM
'.mysql_real_escape_string($table).' WHERE
"'.mysql_real_escape_string($field).'" =
"'.mysql_real_escape_string($compared).'"');
if(mysql_num_rows($query)==0)
return TRUE;
else
return FALSE;
}AngryCloud wrote:
> I just had to add
> 'get_' in front of 'magic_quotes_gpc'.
Oops, sorry about that.
> Is there a way to find out
> which of the statements (from my first post) came out
false and set the $error
> variable accordingly, without having to make a separate
if statement for each
> one?
No.
> Also, so more than one error can be displayed at once,
is it possible to add
> text to a variable? For example, if the username was
invalid, $error =
> 'Username is invalid'. But if the email addresses also
did not match, could
> '<br />Emails do not match' be added to the
variable?
Yes. There are two ways of doing it. One is to use the
combined
concatenation operator (.=) to add something to the end of an
existing
string. You use it like this:
$error = '';
if ($_POST['username'] == '') {
$error .= 'You must supply a username<br />';
if (strlen($_POST['username']) < 4 ||
strlen($_POST['username']) > 20 ||
!alpha_numeric($_POST['username'])) {
$error .= 'Username must be 4-20 characters and contain only
letters or numbers<br />';
A more elegant way of doing it is to create an array like
this:
$error = array();
if ($_POST['username'] == '') {
$error[] = 'You must supply a username';
if (strlen($_POST['username']) < 4 ||
strlen($_POST['username']) > 20 ||
!alpha_numeric($_POST['username'])) {
$error[] = 'Username must be 4-20 characters and contain
only
letters or numbers';
To display the array, use this:
if (isset($error) && !empty($error)) {
echo '<ul>';
foreach ($error as $item) {
echo "<li>$item</li>";
echo '</ul>';
This displays the array as a bulleted list.
Whichever method you use, you can test whether to insert the
details in
the database with this simple test:
if (!$error) {
// insert details in DB
PHP treats an empty string or empty array as false, so
!$error equates
to TRUE if no errors have been triggered.
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
Sql Loader Vs External table? Which one is preffered?
Hello guru,
We trying to load the data into about 160 tables. Here are the following things we are doing currently,
1. We get the flat file in .txt format
2. We are writing the control file for each flat file for thier respective tables
3.And we are using sql loader command to load this data into the table.
I was wondering if this process is cumbersome, and i m not sure if external table could be simple in loading the tables compared to what we are doing ?And i have not used external tables, so wanted to know which on eis better ? So any idea is greatly appriciated !
FYI.. Version :- Oracle 11g
Thank you so much!Thanks for you reply justin !
I found the below example for loading the data into external table...
CREATE OR REPLACE DIRECTORY dat_dir AS 'C:\Oradata\Data';
CREATE OR REPLACE DIRECTORY log_dir AS 'C:\Oradata\Log';
CREATE OR REPLACE DIRECTORY bad_dir AS 'C:\Oradata\Bad';
GRANT READ ON DIRECTORY dat_dir TO scott;
GRANT WRITE ON DIRECTORY log_dir TO scott;
GRANT WRITE ON DIRECTORY bad_dir TO scott;
CREATE TABLE revext (person VARCHAR2(20),
rev_jan NUMBER(4),
rev_feb NUMBER(4),
rev_mar NUMBER(4),
rev_apr NUMBER(4),
rev_mai NUMBER(4),
rev_jun NUMBER(4),
rev_jul NUMBER(4),
rev_aug NUMBER(4),
rev_sep NUMBER(4),
rev_oct NUMBER(4),
rev_nov NUMBER(4),
rev_dez NUMBER(4))
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER
DEFAULT DIRECTORY dat_dir
ACCESS PARAMETERS
records delimited by newline
badfile bad_dir:'revext%a_%p.bad'
logfile log_dir:'revext%a_%p.log'
fields terminated by ','
missing field values are null
( person,
rev_jan,
rev_feb,
rev_mar,
rev_apr,
rev_mai,
rev_jun,
rev_jul,
rev_aug,
rev_sep,
rev_oct,
rev_nov,
rev_dez
LOCATION ('revext.dat')
PARALLEL 4
REJECT LIMIT UNLIMITED;
CREATE TABLE revenue (
person VARCHAR2(20),
month VARCHAR2(3),
revenue NUMBER,
CONSTRAINT revenue_pk PRIMARY KEY (person,month));
INSERT INTO revenue (person,month,revenue)
SELECT person,'Jan',rev_jan
FROM revext--but currently we are using sql loader, our data looks like this
1119Smith 01/01/1982AXYZ corporation xyz corp
1111collen 01/01/1990AABC corporation abc corp
and control file is like this
INTO TABLE "XYZ_tbl"
ID POSITION(01:05) CHAR "DECODE(RTRIM(:ID), NULL, 'NA', :ID)" ,
Name POSITION(06:15) CHAR "DECODE(RTRIM(:NAME), NULL, 'NA', :Name)" ,
Act_dt POSITION(16:25) DATE "MM/DD/YYYY" NULLIF ACT_DT=BLANKS
My question is, can i use the options like NULLIF/ DECODE or changing datatypes when loading or functions like REPLACE / TO_DATE in External tables ? Any idea? Any example code or SQL will great
Thank you so much!
Maybe you are looking for
-
Can I use an iPhone from Verizon with a canceled contract on another Verizon line?
My mother recently canceled her with Verizon Wireless because she wanted to be on our family share plan. My older brother decided that he wanted to get his own contract and left the line for her to take. She doesn't like the phone that he had and she
-
Create .jspx page to add users using ADF security.
Hello, I'm using JDeveloper 11.1.1.3. I've created a login page (form based) with different users and roles using ADF Security. I'm able to successfully login/logout through the users and get redirected to the home page. However, i'm asked to create
-
I am building a module in which the user gives a particular date (date_param) and the module then queries in a particular block for all records where the date column equals to_char(date_param, 'WW'). I tried doing it with a pre_query trigger on the b
-
hi i can't get successful test after enable enterprise voice for users on lync server 2013 i put picture it's just busy tone not free
-
One question of the method have two chance to return the result.
Hello All, I get a problem at present.The code is following. package com.ricky.test; public class Test { public static void main(String args[]) { System.out.println(kkk()); public static int kkk() { int k = 0;