Recursive queries with external table anchor
Hi, I had the tables A and B. In table B, reviews are a tree structure. For each record in A, I want to get the respective records in B, in the following way:SELECT
a.x, b.y
Of
one
CROSS JOIN
(
SELECT * FROM b
START WITH id = a.x
CONNECTION BY b.id = b.parentid PRIOR
) b
And I get the error indicating that the column a.x is not known. Is it possible to use columns of the external table as anchor points for a recursive queries? Or y at - it another way to form such a query?
Thank you.
Published by: David Hoksza on 13.11.2008 17:07
Hello
If all lines in b "inherits" the help of all its descendants.
In this case, do a subquery on b which associates each line with all its descendants (and itself).
WITH bt AS
(
SELECT DISTINCT aid
, CONNECT_BY_ROOT id AS root_id
FROM b
CONNECT BY parentid = PRIOR id
)
SELECT a.id AS "a.id"
, bt.root_id AS "b.id"
FROM a
JOIN bt ON a.id = bt.aid
;
Note that there is no START WITH clause. We want each row of b is considered to be the root of its own subtree.
Sorry, I don't have Express Edition to test this. It works in Oracle Enterprise Edition 10.
If CONNECT_BY_ROOT does not work (it was not available in Oracle 9), you can get the same information from SYS_CONNECT_BY_PATH.
Tags: Database
Similar Questions
-
The Oracle 12 c memory option works with external tables?
Hello
Does anyone know if the external tables are also candidates for the benefit of the Oracle 12 c option in memory? I have read the documentation and white papers, and can't find any reference to external tables. If it is possible, we are very interested to know all about her, especially any limitation.
Thank you.
This is not the right forum for this question; This forum is for the memory of TimesTen database not Oracle database in memory option. These are completely different things.
But it happens that I can tell you that no, external tables are not candidates for use with the In-Memory Option.
Chris
-
problem of counting of returns to the clob line with external tables
Hello
I want to count the number of lines (x0A) in a clob loaded from an external table.
This is the data of the file
That's how the loaded hex of the clob looks like:d 2010-06-21 13:25:23 2 1073807679 0 4 1 1 0 415 348 mtp 16387 ALIGN TIMER 2 EXPIRED iacSt=8 (Lnk 1) xx 2010-06-21 13:25:23 2 1073807679 0 4 1 1 0 415 348 mtp 16387 Sent SIOS (Lnk 1) (AlignNP in InitialAlign)
You can see that there is a total of 6 '0 a' or 6 new lines. However, I get the following results:64 09 09 09 32 30 31 30 2D 30 36 2D 32 31 20 31 33 3A 32 35 3A 32 33 09 09 09 32 09 09 09 31 30 37 33 38 30 37 36 37 39 09 09 09 30 09 09 09 34 09 09 09 31 09 09 09 31 09 09 09 30 09 09 09 34 31 35 09 09 09 33 34 38 09 09 09 20 6D 74 70 20 20 20 20 20 20 20 31 36 33 38 37 20 41 4C 49 47 4E 20 54 49 4D 45 52 20 32 20 45 58 50 49 52 45 44 20 69 61 63 53 74 3D 38 20 28 4C 6E 6B 20 31 29 0A 0A 0A 78 78 09 09 09 32 30 31 30 2D 30 36 2D 32 31 20 31 33 3A 32 35 3A 32 33 09 09 09 32 09 09 09 31 30 37 33 38 30 37 36 37 39 09 09 09 30 09 09 09 34 09 09 09 31 09 09 09 31 09 09 09 30 09 09 09 34 31 35 09 09 09 33 34 38 09 09 09 20 6D 74 70 20 20 20 20 20 20 20 31 36 33 38 37 20 53 65 6E 74 20 53 49 4F 53 20 28 4C 6E 6B 20 31 29 20 28 41 6C 69 67 6E 4E 50 20 69 6E 20 49 6E 69 74 69 61 6C 41 6C 69 67 6E 29 0A 0A 0A
what I am doing wrong?select regexp_count(outputrow,'[[:cntrl:]]') control,regexp_count(outputrow,'[[:space:]]') space, regexp_count(outputrow,'[\n]') backslash_n, regexp_count(outputrow,'[\x0A]') x0A from BULK_BAD_FILE_EXTERNAL b; CONTROL SPACE BACKSLASH_N X0A ---------- ---------- ----------- ---------- 72 104 9 22
11g is not yet I'd
select length(outputrow) - length(replace(outputrow,chr(10))) num_of_rows from bulk_bad_file_external
Concerning
Etbin
-
recursive query with two tables
Hello
Im having problems of recursive query construction and add to select the list to see the result in hierarchical mode, so I want to your advice.
I have two tables:
And I want to see the result like this:TABLE: t1 c_id parent_id c_level 1 - 1 2 1 2 3 1 2 4 - 1 5 4 2 6 5 3 TABLE: t2 c_id c_name 1 name1 2 name2 3 name3 4 name4 5 name5 6 name6
-Name1
-name2
-Name3
-Name4
-Name5
-name6
Could you please help me with this?
Or maybe can you provide good links where I can find solution how to SELECT LIST looks like the hierarchical tree?Here is my test scenario:
CREATE TABLE t1( c_id NUMBER, parent_id NUMBER, c_level NUMBER); CREATE TABLE t2( c_id NUMBER, c_name VARCHAR2(10)); INSERT INTO t1 VALUEs(1,NULL,1); INSERT INTO t1 VALUEs(2,1, 2); INSERT INTO t1 VALUEs(3,1, 2); INSERT INTO t1 VALUEs(4,NULL,1); INSERT INTO t1 VALUEs(5,4, 2); INSERT INTO t1 VALUEs(6,5, 3); INSERT INTO t2 VALUEs(1,'name1'); INSERT INTO t2 VALUEs(2,'name2'); INSERT INTO t2 VALUEs(3,'name3'); INSERT INTO t2 VALUEs(4,'name4'); INSERT INTO t2 VALUEs(5,'name5'); INSERT INTO t2 VALUEs(6,'name6'); SELECT LPAD('-',2 * a.c_level,'-') || b.c_name the_tree FROM t1 a, t2 b WHERE b.c_id = a.c_id CONNECT BY a.parent_id = PRIOR a.c_id START WITH a.parent_id IS NULL;
and the result:
THE_TREE ---------- --name1 ----name2 ----name3 --name4 ----name5 ------name6
I took the example you gave then perhaps your largest data set has the flaw?
Published by: SunDogCa on August 13, 2010 14:19
-
Recursive information, how to create a recursive query with a table?
Hello
I have some data from a table and is stored in the following way:
Building blocks
4040 x 1, x 3, x 4
4040 c3, c7, c9
4040 j5, j7,
4040 s8
4041 f4
4041 x 1, x 2, x 3
I need to record in another table component and all of its units in one line, like this
Component Total_units
4040 x 1, x 3, x 4, c3, c7, c9j5, j7, s8
4041 f4, x 1, x 2, x 3
I tried with subqueries, combination, and I can't get in a data record.
I really appreciate your help!
NicolasThe solution with xmlagg
Note: remove the end (en) this record 4040 j5, j7, manually
You can use the TRIM function to remove this as a GARNISH (end ',' units)WITH dat as (select 4040 Component, 'x1,x3,x4' Units from dual union all select 4040, 'c3,c7,c9' from dual union all select 4040, 'j5,j7' from dual union all select 4040, 's8' from dual union all select 4041, 'f4' from dual union all select 4041, 'x1,x2,x3' from dual ) SELECT Component ,TRIM (leading ',' from XMLAGG(XMLELEMENT(a,','||units).extract('//text()'))) col_name FROM dat GROUP BY component / COMPONENT COL_NAME ---------- ------------------------------------- 4040 x1,x3,x4,c3,c7,c9,j5,j7,s8 4041 f4,x1,x2,x3
SS
-
In the external table files forming themselves!
Hi all
I am facing a weird situation.
Few days back, DB has been improved to 11g 10g R2 and we are facing the situation of the training of logfiles, throw files have joined with external tables in the directory of the OS!
Without job is calling them and the only procedure in which these paintings have been used in the SELECT statement, are not running, even while these files form themselves and fill space in the BONE.
Here is the version information:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production."
AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Please help in this regard.
Thank you.
Hi all
Problem has been identified.
11 g, dbms_stats.gather_stats_job runs all day until 22:00 and after every 4 hours on weekends.
He also tried gathering statistics for external tables given through the GATHER_TABLE_STATS procedure.
In the process, he joint/written in the log files.
Now, I think of locking statistics from this table, so that no stats will be gathered for what is just an EXTERNAL table which is used/populated only once a month.
Suggestions or comments?
Thank you.
-
Number of the external table... probably simple
Hi guys,.
just mucking around with external tables for the first time after meeting a couple of discussions on the subject recently.
I'm in Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - Production
in SYS, I did the following:
now as HR, I do the following:create or replace directory test_dir as '\home\oracle'; grant read, write on directory test_dir to hr;
and get the following:create table ext_test (id number, empname varchar2(100),rate number) organisation external (type ORACLE_LOADER default directory TEST_DIR access parameters (records delimited by NEWLINE fields terminated by ',' optionally enclosed by '"' missing field values are null reject rows with all null fields (id, empname, rate) ) location ('test_file.csv'));
What'm screwing?SQL> @createexttab organisation external (type ORACLE_LOADER * ERROR at line 2: ORA-00922: missing or invalid option
Samir says:
Hi guys,.
What'm screwing?spelling
EXTERNAL ORGANIZATION
-
HII All,
Currently, we use sqlloader. But now we are stuck to the top with a question. The problem is that in our production environment that they have installed customer sqlldr in the application server and the feed file in place in the Oracle server machine.
We tried everything to stay with sqlloader but nothing works very well. I tried with ftp to transfer the file from Oracle server to the client machine, but we use the secure port it did not work.
But this was easily accomplished using external table that the file is located in the server. But now I need to satisfy my clients by proving the external tables are relatively better.
I have google for Sqlloader vs. external this debate.
But I found no strong points supporting external tables.
I had also gone through the following links
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6611962171229
http://www.orafaq.com/Usenet/comp.databases.Oracle.misc/2007/02/13/0222.htm
So please help me by providing some plus points and other links.
Concerning
Rambeau792353 wrote:
Yes, it's really a good point, but can be achieved once the data has been pumped into staging tables.Who would take more space on the database, while the external tables you can do anything as the data is read. External tables would seem better in this regard.
And now, we are not concerned with all the functions for use in DEC.
People argue with me if we use external tables, we need create objects 2 db (1 external and more temporary table) which is just 1 intermediate table if sqlloader.
You only need the external table definition. If you create a temporary table with this depends on your needs and the need to have such a table "staged." Even if you did in SQL * Loader you would always create a staging table, if there is really no difference...
External table = 1 table definition and no data loaded in the database
SQL * Loader = 1 table and the data loaded into the databaseAlso read that when the feed file is huge its better to opt for sqlloader as it can circumvent sql analysis by choosing a DIRECT approach. Isisnt it?
External tables using SQL * Loader under the hood engine, so there is no real difference except where you want to keep your data (in the file, or load a copy first on the database). You can use the parallel with external tables to load using multiple threads, you can use the indicator append to load the data as in the direct approach of sql * loader.
So, kindly suggest me which is the best approach in a long-term process.
In the long term, the external tables are the best approach. They were introduced after SQL * Loader to provide an improved mechanism. If they were not better, Oracle would not have taken the trouble with them. They also have the advantage that the control of their use is on the database, i.e. no need to control files, no need to run a command-line utility, not two floors (loading then treatment) treatment.
There is no real reason for the use of SQL * Loader everything but more, the strange unique circumstance where you need to download data from a client computer (which will raise the question why a client machine has data on it in the first place!)
-
Can take us backup of external table using expdp
Can take us backup of the external table using expdp, please suggest any doc.
Thanks in advance.Yes, this works, see this example:
http://www.Oracle.databasecorner.com/resource, 3950,data-movement-with-external-table-and-datapump.aspx
Werner
-
External table for the file delimmited by commas
Im trying to create a table of externla for the comma-delimited file
but it also has a scenario where the fields can have a comma between "" e.g.
example of record
Example of table1,one,first 2,two,second 3,three,third 4,four,"4,fourth"
So when I question this record 4 table of Externla will be read ascreate 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;
M/2
i n m 4 four "4 {code} Above Ext table is just an example, Im adding bad file and log file in real table. Please help me if there is a way this can be resolved with external table.
Change the definition of:
FIELDS TERMINATED BY ', '.
TO:
FIELDS ENDED BY ',' POSSIBLY FRAMED BY "" "
-
With the help of external Tables
HELO - I have a few questions regarding the use of external tables, as I have not worked with them before.
From what I read, looks like they are more intended instead of SQL Loader, to simply load the data. But I was wondering if they are also used for queries. I ask because we usually create temporary tables to load the data provided by the company and we then attach this information to our main tables. The file that we just received is more 3 million lines, so I was wondering if it might be appropriate to use an external table and also, I can query this external table directly or will it still my temporary table as well.
In addition, it's the syntax that I found to create an external table and I was wondering if something escapes me.
I appreciate all the comments...SQL> create table xtern_empl_rpt 2 ( empl_id varchar2(3), 3 last_name varchar2(50), 4 first_name varchar2(50), 5 ssn varchar2(9), 6 email_addr varchar2(100), 7 years_of_service number(2,0) 8 ) 9 organization external 10 ( default directory xtern_data_dir 11 access parameters 12 ( records delimited by newline 13 fields terminated by ',' 14 ) 15 location ('employee_report.csv') 16 );
Thank you!
ChristineHello
Based on what I read
It would be good to know what you have read sofar and where...
I can query this external table directly
Yes, once you have created.
An external table allows to process a file as if it were a table.
Don't forget that you can query only, you can not the update/delete/insert in an external table.You can find many examples by searching on this forum,
or http://asktom.oracle.com
(for example: http://asktom.oracle.com/pls/asktom/f?p=100:11:0:::P11_QUESTION_ID:6611962171229))
or http://www.oracle-base.com/articles/9i/ExternalTables9i.php
or the Oracle Documentation @ http://tahiti.oracle.com -
External table with mixed columns
Hello everyone. We use Oracle 11R1. We have an external table pointing to a CSV with 7 columns inside. The file has always column 7 but the column order differs from time to time. Each column has a header that remains consistent. Is there a way to map the column names to the column header, s so that we did not change the definition of the external table every time a new file is available in?
Thank you.
Hello
As John said, you must assign names of columns when the table is created. I guess you could have a dynamic SQL solution that reads the header you mentioned, uses this information to write a CREATE table, drop the table, and then recreated with the new order of the columns.
You may have a view that maps the 7 columns in your table of 7 columns in the view. Which column gets the mapping to that may depend on the header.
-
Loading external Table with quotes
I have a file with fields in the file are as TAB delimiter ~ TAB.
Example as below:
QM ~ CD ~ Exzm ~ BMW
DM ~ BD ~ Exzm ~ BMW
CREATE TABLE test
(
Col_1 VARCHAR2 (100),
Col_2 VARCHAR2 (100),
Col_3 VARCHAR2 (100),
Col_4 VARCHAR2 (100)
)
EXTERNAL ORGANIZATION
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY 'Test_Report '.
ACCESS SETTINGS
(records delimited by '\n'
CHARACTERSET 'UTF8 '.
fields terminated by '\t~\t '.
missing field values are null
)
LOCATION ("test.asc")
)
REJECT LIMIT UNLIMITED;
OUTPUT:
----------------
Data loaded in DB, but col_4 data comes from the quotation as below
col_4
-------
"BMW".
"BMW".
Note: Col1 - col3 data arrives correctly.
2807064 wrote:
A finding on my side.
I found that the values of Col_4 after inserting into DB with "transport return character" (CHR (13)) at the end of each value as shown below when I copy paste the value in notepad ++ "»
Example:
----------
"BMW".
"
But if I see the file I saw that BMW.
My question is, in this case the external table loading must fail right? Why is this it is to load data in DB?
Do you have this file begin life on windows, and then are transferred to * nix to serve an external table? If so, which explains a lot. Windows is the standard record delimiter x '0d0a' (Chr (13) 10) On * nix, it's just x '0A' (10. When the process of loader is scanning for record delimiter he's just looking for the '0A' x and x'd 0' gets included in the data.
Two solutions-
1 - Make sure that the data file is transferred so that the Records delimiters are converted. It's supposed to to happen with ascii ftp mode, but this week I saw several examples in the House of it does not.
2. attach your table definition external to seek the delimiter of actual recording instead of the default value of the operating system. == RECORDS DELIMITED BY X '0D0A '.
-
External table with the preprocessor file to display the list of files
Hello
in my db 11.2.0.2 I would create an external table with script preprocessor to show me the list of files in a directory.
Preprocessor banally:
#! / bin/bash
CD/MyDir
/ bin/ls-l *.txt 2 >/dev/null
The problem is the file name that contains white space (style windows in a Linux env), for ex:
-rw - r - r - 1 oracle oinstall 920 9 Jun 17:37 File1.txt
-rw - r - r - 1 oracle oinstall 72316 Jun 10 10:37 file GC output1.txt
-rw - r - r - 1 oracle oinstall 72316 Jun 10 10:40 GC file output2.txt
So I can't use FIELDS DELIMITED BY "". ""
FIXED size? No, because the file size change the length of the lines.
I tried to use awk in my preprocessos script, but I have the same problem:
/ bin/ls-l *.txt 2 >/dev/null | / bin/awk ' {printf "%s %.2d %s %s\n", $6, $ 7, $ 8, $9} '.
Any ideas?
Hello
I used java to retrieve information about the files.
-
External table with the field tab delimiter
With the help of Oracle 11 g Release 2
Here is my table create statement external:
CREATE TABLE global.ext_a_attrib_cmt ( tag VARCHAR2(255) , from$ VARCHAR2(255) , to$ VARCHAR2(255) ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY EXT_DATA_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE SKIP 1 BADFILE EXT_BAD_DIR:'a_attrib_cmt.bad' LOGFILE EXT_LOG_DIR:'a_attrib_cmt.log' -- FIELDS TERMINATED BY 0X'09' -- TAB delimited FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY "'" MISSING FIELD VALUES ARE NULL REJECT ROWS WITH ALL NULL FIELDS ) LOCATION ('a_attrib_cmt.txt') ) REJECT LIMIT UNLIMITED NOMONITORING /
Here is the text file, a_attrib_cmt.txt:
tag Of TO FrontSpringType_id Coil w/FRONT COIL SPRINGS FrontSpringType_id Sheet the FRONT/w suspension SPRINGS Aspiration_id Naturally aspirated w/o TURBO Aspiration_id Turbocharged w/TURBO Aspiration_id Supercharged w/COMPRESSOR SteeringType_id Grid w/RACK and PINION STEERING SteeringType_id Gear w/GEAR STEERING FuelDeliveryType_id CARB w/o FUEL INJ FuelDeliveryType_id FI w/FUEL INJ BedLength_id ?" BED BodyNumDoors_id ? DR BrakeSystem_id w / ? BRAKES FrontBrakeType_id w/FRONT? BRAKES PUBLIC has privileges to write to the directory EXT_DATA_DIR.
Here is the error I get:
Globall@ORA1 > select count (*) in the ext_a_attrib_cmt;
Select count (*) in ext_a_attrib_cmt
*
ERROR on line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN legend
ORA-29400: data cartridge error
KUP-00554: error occurred when parsing the access settings
KUP-01005: syntax error: found 'minussign': expected an a: "badfile, bigEndian, characterset, column, data, delimited, discardfile,
disable_directory_link_check, fields, fixed, charge, logfile, language, nodiscardfile, nobadfile, nologfile, date_cache, preprocessor, TailleLue, String, jump,
territory, variable.
KUP-01007: line 5, column 8
Just get rid of the comment line. You cannot cave comments to create external table statement. SY.
Maybe you are looking for
-
K1 - problem to set the hong Kong traditional Chinese language
Dear lenovo, My k1 is by default with the traditional Chinese (Taiwan), and in this case the market that comes with the software with Taiwan. Since I am located in Hong Kong, could you tell how to change the language of traditional Chinese Hong Kong.
-
Why the transition from the server causes error?
I reported the error to the it Department, they respond as indicated below: "These errors are the result of a transition from server we are currently experiencing. As soon as the server transition is complete errors should stop. » «The transition of
-
How can I remove daved games in a Vista program
I have by mistake 'saved' a game being played, and there is now an annoying pop-up that asks if I want to continue with the saved game. How can I delete the saved game?
-
Conversion drive term, results in gibberish, suggestions?
Someone at - it el; had this problem and can suggest you a way to create a readable document? Thanks in anticipation, Tim
-
You know how some tools have a drop-down menu if you click and hold. I'm going between several tools on an ongoing basis and recently, I have noticed a shift. This little thing is a huge nuisance that interferes with my workflow. Help, please! I've j