result of the hierarchical query in xml format
Pls find below the example script table and the desired output format. Output XML must keep the information of hierarchy that is the requirement. Also is it possible to do it in single sql.Thank you.
CREATE TABLE MAIN
(
IDENTIFICATION NUMBER,
NAME VARCHAR2 (20 BYTE)
);
INSERT INTO THE HAND (ID, NAME) VALUES)
1, "OS");
INSERT INTO THE HAND (ID, NAME) VALUES)
2, 'Windows');
INSERT INTO THE HAND (ID, NAME) VALUES)
3, 'BACK');
INSERT INTO THE HAND (ID, NAME) VALUES)
4, "1.x");
INSERT INTO THE HAND (ID, NAME) VALUES)
5, "1.1.x");
INSERT INTO THE HAND (ID, NAME) VALUES)
7, "1.1.1.1");
INSERT INTO THE HAND (ID, NAME) VALUES)
8, ' (1.2');
INSERT INTO THE HAND (ID, NAME) VALUES)
9, '2.x');
INSERT INTO THE HAND (ID, NAME) VALUES)
10, ' (2.1');
INSERT INTO THE HAND (ID, NAME) VALUES)
11, "2.2");
INSERT INTO THE HAND (ID, NAME) VALUES)
12, ' 2.2.1');
INSERT INTO THE HAND (ID, NAME) VALUES)
13, ' 2.2.2');
COMMIT;
CREATE TABLE RELA
(
NUMBER OF REL_ID
IDENTIFICATION NUMBER,
NUMBER OF PARENT_REL_ID
);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
1, 1, NULL);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
2, 2, 1);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
3, 4, 2);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
4, 5, 3);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
5, 7, 4);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
6, 8, 4);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
7, 9, 2);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
8, 10, 7);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
12, 7, 11);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
14, 9, 9);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
15, 10, 14);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
9, 3, 1);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
10, 4, 9);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
11, 5, 10);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
16, 11, 14);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
13, 8, 10);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
17, 12, 16);
INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
18, 13, 16);
COMMIT;
Example query
Select rel_id, level, lpad (' ', 5 * level) | name,
XmlElement ("rel_id", XMLAttributes (name as "name", rel_id as "rel_id")) as val
principal, rela
where main.id = rela.id
Start with parent_rel_id is null
Connect prior rel_id = parent_rel_id;
Required xml output
Required xml output
< 1 name = "OS" >
< name 2 = "Windows" >
< 3 name = "1.x" 3 > ""
< name 4 = "1.1.x" >
< name 5 = "1.1.1.1" > < / 5 >
< name 6 = "1.2" > < / 6 >
< / 4 >
< / 3 >
< name = "" 2.x 7 ">"
< name 8 = "2.1" > < / 8 >
< / 7 >
< / 2 >
< name 9 'BACK' = >
< name = "2.x 14" > "
< name 15 = "2.1" > < / 15 >
< name 16 = "2.2" >
< name 17 = '2.2.1' > < / 17 >
< name 18 = '2.2.2' > < / 18 >
< / 16 >
< / 14 >
< 10 name = "1.x" > "
< name 11 = "1.1.x" >
< name 12 = "1.1.1.1" > < / 12 >
< / 11 >
< name 13 = "1.2" >
< / 13 >
< / 10 >
< / 9 >
< 1 >
Published by: delights on September 18, 2009 16:47
Published by: delights Sep 19, 2009 09:53
No string function helps eliminate r because the xml output is great (in a real scenario) which gives "buffer too small" error.
Try sth like
SQL>select replace(x.column_value.getclobval(), 'XXX') xml
2 from xmltable ('.' passing dbms_xmlgen.getxmltype (dbms_xmlgen.
3 newcontextfromhierarchy (
4 'select level, xmlelement (evalname ''XXX'' || rel_id, xmlattributes(name "name")) name
5 from main, rela
6 where main.id = rela.id
7 start with parent_rel_id is null
8 connect by prior rel_id = parent_rel_id'
9 ))) x
10 /
XML
--------------------------------------------------------------------------------
<1 name="OS">
<2 name="Windows">
<3 name="1.x">
<4 name="1.1.x">
<5 name="1.1.1.1"/>
<6 name="1.2"/>
4>
3>
<7 name="2.x">
<8 name="2.1"/>
7>
2>
<9 name="DOS">
<10 name="1.x">
<11 name="1.1.x">
<12 name="1.1.1.1"/>
11>
<13 name="1.2"/>
10>
<14 name="2.x">
<15 name="2.1"/>
<16 name="2.2">
<17 name="2.2.1"/>
<18 name="2.2.2"/>
16>
14>
9>
1>
SQL>
Newcontextfromhierarchy is not a documented feature do not know if it will issue in releated support this in production code.
Oracle's recommeds to use newcontextfromhierarchy in Metalink Note 882887.1 ;)
Tags: Database
Similar Questions
-
Where is the result of the following query caching?
I run the following query statement:
Where is the result of the following query caching? Is cached in the PGA? What area of PGA?select * from hr.employees
By definition is not "cache". The blocks of data that are read to retrieve the results of the query are retrieved in the cache (DB_CACHE_SIZE or DB_BLOCK_BUFFERS component BMG) buffers so that they are accessible on several occasions by the same users or other users. However, because the buffer cache is limited in size, buffers are released when new blocks to be read. Buffers for a full table scan (as it would be for such a request) are released very probably earlier.
Please read the Oracle database documentation, starting with the Concepts manual for the version you are using. Starting at http://tahiti.oracle.com
Hemant K Collette
-
How to convert the hierarchical query of SQL Server (CTE) to Oracle?
How to convert the hierarchical query of SQL Server (CTE) to Oracle?
WITH cte (col1, col2) AS
(
SELECT col1, col2
FROM dbo. [tb1]
WHERE col1 = 12
UNION ALL
SELECT c.col1, c.col2
FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
)
DELETE one
FROM dbo. [tb1] AS an INNER JOIN b cte
ON a.col1 = b.col1Hello
Something like this maybe:DELETE FROM dbo.tb1 a WHERE EXISTS ( SELECT 1 FROM dbo.tb1 b WHERE a.co11 = b.col1 AND a.col2 = b.col2 START WITH b.col1 = 12 CONNECT BY b.col2 = PRIOR b.col1)
Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.
-
Result of the COIL query SELECT UNIX - tabular format
This request of mine is an extension of my previous thread that I've marked as 'Response' (where the new position).
I am now able to spool the output of the SELECT query in a file through unix shell script.
However, the output is not formatted. I tried to use options like
COLUMN column_name FORMAT A20, but this has not worked as planned.
I have 5 columns in the table and my output is to have these columns by dragging to the next line.
for example, I want something like
But I get:column1 column2 column3 column4 column5 ====================================================================== value1 value2 value3 value4 value5
That is to say columns are coming on a single line or header and the value are aligned.column1 column2 ====================== value1 value2 column3 column4 ====================== value3 value4 column5 =========== value5
any thoughts? what I'm missing here?
Published by: Caitanya November 2, 2009 07:39set line 12000; set page 500;
Before you run the query, and after you connect to SQLPLUS.
See you soon!
Bhushan Salgar -
Is it possible to generate the FDM export to .xml format file?
Hello world
We use the Hyperion financial management of the quality of the data (version 11.1.1.3.00).
Earlier today we are generating the export format .dat file, is it possible to generate the export to .xml format file?
What are the possible export available in MDF file formats?
Any suggestion would be greatly helpful.
Thanks in advance :)
Aly HassanThe file output and its formatting is defined/created in the Export Action of each adapter FDM script. You can modify this script to print the file exported in any format you want. However, I don't see why you want to do for the entire target specific adapters supplied with FDM, well if we talk about changing the default output of the adapter then PULL, this would be where you would bring changes. There is no magic switch that automatically does for you :-)
-
How to set the result of the dynamic query in a refcursor ON param.
Hello
I created the following package.
CREATE OR REPLACE package LGIS
Is
Type T_Cust_Acct_Arr is table of number;
Type Invc_Base_Rec_Type is (Record
Invoice_Control_No Customer_History.Invoice_Control_No%Type,
Billing_Cycle_Id Eb_Oor_Cust_Online.Billing_Cycle_Id%Type,
Bill_Cycl_Occr_No Eb_Oor_Cust_Online.Bill_Cycl_Occr_No%Type,
Invoice_Dt Bill_Cycl_Occr_Inf.Invoice_Date%Type,
Invc_Acct_Id Eb_Oor_Cust_Online.Customer_Acct_Id%Type,
Acct_Id Eb_Oor_Cust_Online.Customer_Acct_Id%Type
);
Type Invc_Base_Refcur_Type is Ref Cursor
Return Invc_Base_Rec_Type;
Procedure P_Get_Approved_Whole_Invcs)
In_From_Invc_Dt by Date,
In_To_Invc_Dt by Date,
In_Cust_Acct_List in T_Cust_Acct_Arr,
Out_Eb_Invcs on Invc_Base_Refcur_Type
On_Error_No number
);
End LGIS;
/
CREATE OR REPLACE PACKAGE BODY Lgis
IS
PROCEDURE P_Get_Approved_Whole_Invcs)
In_From_Invc_Dt BY DATE,
In_To_Invc_Dt BY DATE,
In_Cust_Acct_List IN T_Cust_Acct_Arr,
Out_Eb_Invcs on Invc_Base_Refcur_Type
On_Error_No NUMBER
)
IS
S_Query VARCHAR2 (4000);
Invalid_Exception EXCEPTION;
BEGIN
On_Error_No: = 0;
IF In_Cust_Acct_List.COUNT > 0 THEN
FORALL i IN 1.In_Cust_Acct_List.COUNT
INSERT INTO EB_CUST_ACCT_WHOLE_TMP (Cust_Acct_Val)
VALUES (In_Cust_Acct_List (i));
END IF;
BEGIN
S_Query: = 'Select Ch.Invoice_Control_No,';
S_Query: = S_Query | ' Eoco.Billing_Cycle_Id,';
S_Query: = S_Query | ' Eoco.Bill_Cycl_Occr_No,';
S_Query: = S_Query | ' Bcoi.Invoice_Date,';
S_Query: = S_Query | ' Eoco.Customer_Acct_Id as Invc_Acct_Id';
S_Query: = S_Query | ' Eoco.Customer_Acct_Id as Acct_Id ';
S_Query: = S_Query | "Of Eb_Oor_Cust_Online Eoco,';
S_Query: = S_Query | "Customer_History Ch';
S_Query: = S_Query | ' Bcoi Bill_Cycl_Occr_Inf,';
S_Query: = S_Query | "Audit_Var_Log Avl,';
S_Query: = S_Query | "Audit_Var_Def Avd,';
S_Query: = S_Query | "Eb_Cust_Acct_Whole_Tmp Tmp';
S_Query: = S_Query | "Where Avd.Audit_Var_Cd ="CYCLE_APPROVAL"';
S_Query: = S_Query | ' And Avl.Audit_Var_Sub_Grp_Val = 0';
S_Query: = S_Query | "And Avl.Audit_Var_Char_Val =" COMPLETE "';
S_Query: = S_Query | ' And Eoco.Customer_Acct_Id = Tmp.Cust_Acct_Val';
S_Query: = S_Query | ' And Eoco.Customer_Acct_Id = Ch.Customer_Acct_Id';
S_Query: = S_Query | ' And Eoco.Billing_Cycle_Id = Ch.Billing_Cycle_Id';
S_Query: = S_Query | ' And Eoco.Bill_Cycl_Occr_No = Ch.Bill_Cycl_Occr_No';
S_Query: = S_Query | ' And Eoco.Billing_Cycle_Id = Bcoi.Billing_Cycle_Id';
S_Query: = S_Query | ' And Eoco.Bill_Cycl_Occr_No = Bcoi.Bill_Cycl_Occr_No';
S_Query: = S_Query | ' And Avd.Audit_Var_Id = Avl.Audit_Var_Id';
S_Query: = S_Query | ' And Avl.Audit_Var_Grp_Id = Bcoi.Audit_Var_Grp_Id';
IF (In_From_Invc_Dt IS NULL AND In_To_Invc_Dt IS NOT NULL) THEN
S_Query: = S_Query | "And Bcoi.Invoice_Date < = In_To_Invc_Dt';
END IF;
IF (In_To_Invc_Dt IS NULL AND In_From_Invc_Dt IS NOT NULL) THEN
S_Query: = S_Query | ' And Bcoi.Invoice_Date > = In_From_Invc_Dt';
END IF;
IF (In_From_Invc_Dt IS NOT NULL AND In_To_Invc_Dt IS NOT NULL) THEN
S_Query: = S_Query | ' And Bcoi.Invoice_Date > = In_From_Invc_Dt';
S_Query: = S_Query | "And Bcoi.Invoice_Date < = In_To_Invc_Dt';
END IF;
RUN IMMEDIATELY S_Query IN Out_Eb_Invcs;
EXCEPTION
WHILE OTHERS THEN
On_Error_No: = - 1;
RAISE Invalid_Exception;
END;
Exception
When Invalid_Exception then
On_Error_No: = - 1;
Return;
While others then
On_Error_No: = - 1;
END P_Get_Approved_Whole_Invcs;
Lgis END;
/
It compiles without error. But at runtime, I get the following error:
ORA-06504: PL/SQL: return variables of the game results or the query types do not match
Please help solve this problem.
Thank you
OlivierMaybe it will work for you too->
CREATE OR REPLACE Package Body Lgis Is Procedure P_Get_Approved_Whole_Invcs ( In_From_Invc_Dt In Date, In_To_Invc_Dt In Date, In_Cust_Acct_List In T_Cust_Acct_Arr, Out_Eb_Invcs Out Invc_Base_Refcur_Type, On_Error_No Out Number ) Is S_Query Varchar2(4000); Invalid_Exception Exception; Begin On_Error_No := 0; If In_Cust_Acct_List.Count > 0 Then Forall I In 1..In_Cust_Acct_List.Count Insert Into Eb_Cust_Acct_Whole_Tmp (Cust_Acct_Val) Values (In_Cust_Acct_List (I)); End If; Begin S_Query := ' Select Ch.Invoice_Control_No Invoice_Control_No, ' ||' Eoco.Billing_Cycle_Id Billing_Cycle_Id, ' ||' Eoco.Bill_Cycl_Occr_No Bill_Cycl_Occr_No, ' ||' Bcoi.Invoice_Date Invoice_Dt, ' ||' Eoco.Customer_Acct_Id As Invc_Acct_Id,' ||' Eoco.Customer_Acct_Id As Acct_Id ' ||' From Eb_Oor_Cust_Online Eoco, ' ||' Customer_History Ch, ' ||' Bill_Cycl_Occr_Inf Bcoi, ' ||' Audit_Var_Log Avl, ' ||' Audit_Var_Def Avd, ' ||' Eb_Cust_Acct_Whole_Tmp Tmp ' ||' Where Avd.Audit_Var_Cd = '||chr(39)||'CYCLE_APPROVAL'||chr(39) ||' And Avl.Audit_Var_Sub_Grp_Val = 0 ' ||' And Avl.Audit_Var_Char_Val = '||chr(39)||'COMPLETE'||chr(39) ||' And Eoco.Customer_Acct_Id = Tmp.Cust_Acct_Val ' ||' And Eoco.Customer_Acct_Id = Ch.Customer_Acct_Id ' ||' And Eoco.Billing_Cycle_Id = Ch.Billing_Cycle_Id ' ||' And Eoco.Bill_Cycl_Occr_No = Ch.Bill_Cycl_Occr_No ' ||' And Eoco.Billing_Cycle_Id = Bcoi.Billing_Cycle_Id ' ||' And Eoco.Bill_Cycl_Occr_No = Bcoi.Bill_Cycl_Occr_No ' ||' And Avd.Audit_Var_Id = Avl.Audit_Var_Id ' ||' And Avl.Audit_Var_Grp_Id = Bcoi.Audit_Var_Grp_Id ' If (In_From_Invc_Dt Is Null And In_To_Invc_Dt Is Not Null) Then S_Query:=S_Query||' And Bcoi.Invoice_Date <= In_To_Invc_Dt '; End If; If (In_To_Invc_Dt Is Null And In_From_Invc_Dt Is Not Null) Then S_Query:=S_Query||' And Bcoi.Invoice_Date >= In_From_Invc_Dt '; End If; If (In_From_Invc_Dt Is Not Null And In_To_Invc_Dt Is Not Null) Then S_Query:=S_Query||' And Bcoi.Invoice_Date >= In_From_Invc_Dt ' ||' And Bcoi.Invoice_Date <= In_To_Invc_Dt '; End If; Dbms_Output.Put_Line ('Test'); Open Out_Eb_Invcs For S_Query; Dbms_Output.Put_Line ('Test1'); Loop Fetch Out_Eb_Invcs Into Ibrt_Type; Exit When Out_Eb_Invcs%notfound; Dbms_Output.Put_Line ('Invoice_Control_No: ' || Ibrt_Type.Invoice_Control_No); Dbms_Output.Put_Line ('Billing_Cycle_Id: ' || Ibrt_Type.Billing_Cycle_Id); Dbms_Output.Put_Line ('Bill_Cycl_Occr_No: ' || Ibrt_Type.Bill_Cycl_Occr_No); Dbms_Output.Put_Line ('Invoice_Dt: ' || Ibrt_Type.Invoice_Dt); Dbms_Output.Put_Line ('Invc_Acct_Id: ' || Ibrt_Type.Invc_Acct_Id); Dbms_Output.Put_Line ('Acct_Id: ' || Ibrt_Type.Acct_Id); End Loop; Dbms_Output.Put_Line ('Test2'); Close Out_Eb_Invcs; /* Exception When Others Then On_Error_No := -1; Raise Invalid_Exception; */ End; Exception When Invalid_Exception Then On_Error_No := -1; Return; /* When Others Then On_Error_No := -1; */ End P_Get_Approved_Whole_Invcs; End Lgis;
Your problem is now fixed.
Kind regards.
LOULOU.
-
How to store results of the select query in the tables.
I created a variable varray type and now want to assign some data of output of the select query in pl/SQL, as well as in reports 6i.You are in the wrong forum (this is for problems with the SQL Developer tool). You were the one where you have published first on the right, but not to reuse independent threads as you did.
Kind regards
K. -
Sequence step results in the report in Simple text format
I use Teststand 2012 and that you have installed the plugin from model simple text report.
My main test sequence called a number of subsequences that contain the test steps and contain also several subsequences. A number of the subsequences is only stocks. My test result file contains all the results of measures of test as expected, but it also contains a line of output for each call of sequences - makes it difficult to see the results that count. I would only record the test steps.
Looking at the code SimpleTextReport.dll in CVI I see it is stepping into the results and updated list in the form of each line (I changed some of the formatting). Is this the right place to filter the levels of appeal of sequence or can I stop the call sequence steps to be added to the list of results?
You can put it in the sequential model. Just use ProcessModelPostResultListEntry with the same code. If it's in the template, you won't need it in other files. In addition, he is probably already stuff in the model. You'll have to code around it. This is how they do it on the fly.
-
Access the results of the dynamic query database...
CF colleagues:
I need to execute a loop of 4 times, to access the four distinct values a data offline in a test results table (tbl_results), where all four are in line with the student (WHERE studentid = etc.).
It looks like this...
< cfset variables. TimeTotals = 0 >
< cfloop from '1' to step "4" = = = '1' index = "timrec" >
< cfquery datasource = "MyDSN" name = "rs_time" >
SELECT Btime #timrec #.
OF tbl_results
WHERE studentid = 'jack '.
< / cfquery >
< cfset variables. TimeTotals = variable. TimeTotals + (? rs_time.) BTime #timrec # value?) >
< / cfloop >
QUESTION: How should I address this #timrec # value Btime? Not that way, I know, but how?
Looking forward to your wisdom, with gratitude,
Hans
There are two ways to attack this, but you're close enough. One way is to simply include a column alias in the query, and then use it to make reference to results:
SELECT Btime #timrec # LIKE feeling
OF tbl_results
WHERE studentid = 'jack '.
-
Why the result of the SQL query is not displayed in the HTML text box?
Hello
Under query result appears in home > workshop SQL > SQL commands.
Select t.nom
of pm_task t
where: P5_Project_id = t.project_id
and: P5_task_id = t.id
But when the same code is run through EditRegion of HTML text box > region definition > sources > Source region, the result is not displayed.
Why is this so, and what is the solution?
Thank you
GuyYou need a report from the region for this ;) A region of HTML is to display a static text or page items.
Denes Kubicek
------------------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------------------ -
Identify the hierarchical query paths
Hi all
11 GR 2 DB
Thanks in advancecreate table test_h(parent varchar2(1),child varchar2(1)); insert into test_h values(null,'A'); insert into test_h values('A','B'); insert into test_h values('B','C'); insert into test_h values('C','D'); insert into test_h values('B','E'); insert into test_h values('E','F'); insert into test_h values('','1'); insert into test_h values('1','2'); insert into test_h values('2','3'); commit; SQL> select * 2 from test_h; P C - - A A B B C C D B E E F 1 1 2 2 3 9 rows selected. SQL> select connect_by_root child root_val,child,level lvl 2 from test_h 3 start with parent is null 4 connect by prior child = parent; R C LVL - - ---------- 1 1 1 1 2 2 1 3 3 A A 1 A B 2 A C 3 A D 4 A E 3 A F 4 9 rows selected. Expected output: An identifier for each different path R C LVL PATH - - ---------- ---- 1 1 1 PATH1 1 2 2 PATH1 1 3 3 PATH1 A A 1 PATH2 A B 2 PATH2 A C 3 PATH2 A D 4 PATH2 A E 3 PATH3 A F 4 PATH3
One-way ticket (not tested... Based on the fact that hierarchical queries will produce output orderly)
SQL> with relation as 2 ( 3 select connect_by_root child root_val,child,level lvl,rownum rn 4 from test_h 5 start with parent is null 6 connect by prior child = parent 7 ), 8 flag as 9 ( 10 select root_val,child,lvl,rn, 11 case when lvl = lag(lvl) over(order by rn)+1 12 then 0 13 else 1 14 end flg 15 from relation 16 ) 17 select root_val,child,lvl, 18 'PATH'||sum(flg) over(order by rn) path 19 from flag; R C LVL PATH - - ---------- -------------------------------------------------- 1 1 1 PATH1 1 2 2 PATH1 1 3 3 PATH1 A A 1 PATH2 A B 2 PATH2 A C 3 PATH2 A D 4 PATH2 A E 3 PATH3 A F 4 PATH3 9 rows selected.
-
To find the child sheet most to the hierarchical query
Hello
I need to findout the child sheet plus for parent to my request.
Expected resultscreate table test_Test1 ( ID , PRNT_ID ,CHLD_ID) as (select 1 , 10 ,20 from dual union all select 2 , 10 ,21 from dual union all select 3 , 20 ,30 from dual union all select 4 , 20 ,31 from dual union all select 5 , 30 ,40 from dual union all select 6 , 31 ,41 from dual union all select 7 , 100 ,200 from dual union all select 8 , 100 ,210 from dual union all select 9 , 200 ,300 from dual union all select 10 , 200 ,310 from dual union all select 11 , 300 ,400 from dual union all select 12 , 310 ,410 from dual )
Thank youPRNT_ID CHLD_ID ------ ------ 10 21 10 40 10 41 100 210 100 400 100 410
What:
SQL> select * from t; ID PRNT_ID CHLD_ID ---------- ---------- ---------- 1 10 20 2 10 21 3 20 30 4 20 31 5 30 40 6 31 41 7 100 200 8 100 210 9 200 300 10 200 310 11 300 400 12 310 410 12 rows selected. SQL> select min(isroot) 2 , chld_id 3 from ( select connect_by_root prnt_id isroot 4 , chld_id 5 , connect_by_isleaf isleaf 6 from t 7 connect by prnt_id = prior chld_id 8 ) 9 where isleaf = 1 10 group by chld_id; MIN(ISROOT) CHLD_ID ----------- ---------- 10 21 10 40 10 41 100 210 100 400 100 410 6 rows selected.
-
Is it possible to fill a table with the result of the active query?
I try to get the content of the cursor c in the ap variable and the code I use is as follows:
BEGIN
DECLARE
TYPE cur_typ IS REF CURSOR;
c cur_typ;
query_str VARCHAR2 (1000);
work VARCHAR2 (1000);
AP varchar2 (30000);
to the varchar2 (30000);
query varchar2 (30000);
BEGIN
query_str: = ' select ent_cod, ent_nom from grh_funcionarios where rownum < 10';
query: = 'CURSOR c IS' |' select ent_cod, ent_nom from grh_funcionarios where rownum < 10';
IMMEDIATE EXECUTION of the query;
C OPEN FOR query_str;
for ap loop query_str
LOOP
Fetch c ap;
EXIT WHEN c % NOTFOUND;
DBMS_OUTPUT. Put_line(àles);
END LOOP;
C CLOSE;
END;
END;I'll show you a basic approach to the dynamic approach refcursor. But you have to do a lot of work in order to customize it to your needs.
Here is a demonstration of basic->
satyaki> satyaki>select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod PL/SQL Release 10.2.0.3.0 - Production CORE 10.2.0.3.0 Production TNS for 32-bit Windows: Version 10.2.0.3.0 - Production NLSRTL Version 10.2.0.3.0 - Production Elapsed: 00:00:00.22 satyaki> satyaki> satyaki>DECLARE 2 str VARCHAR2 (30000); 3 4 cursor c1 5 is 6 select column_name 7 from all_tab_columns 8 where table_name = upper('&tab_nm') 9 and column_name = 'ENAME'; 10 11 r1 c1%rowtype; 12 BEGIN 13 str := ' declare '|| 14 ' TYPE cur_typ IS ref cursor; '|| 15 ' c cur_typ; '|| 16 ' query_str VARCHAR2 (1000); '|| 17 ' gen_rec '||upper('&tab_nam')||'%rowtype; '|| 18 ' begin '|| 19 ' query_str := '||chr(39)||'select * from emp where rownum < 10'||chr(39)||'; '|| 20 ' OPEN c FOR query_str; '|| 21 ' LOOP '|| 22 ' FETCH c INTO gen_rec; '|| 23 ' EXIT WHEN c%NOTFOUND; '; 24 for r1 in c1 25 loop 26 str := str||' DBMS_OUTPUT.put_line (gen_rec.'||r1.column_name||'); '; 27 end loop; 28 str := str||' END LOOP; '|| 29 ' CLOSE c; '|| 30 ' end; '; 31 32 execute immediate(str); 33 --dbms_output.put_line(str); 34 END; 35 / Enter value for tab_nm: emp old 8: where table_name = upper('&tab_nm') new 8: where table_name = upper('emp') Enter value for tab_nam: emp old 17: ' gen_rec '||upper('&tab_nam')||'%rowtype; '|| new 17: ' gen_rec '||upper('emp')||'%rowtype; '|| SATYAKI SOURAV WARD JONES MARTIN BLAKE CLARK SCOTT KING PL/SQL procedure successfully completed. Elapsed: 00:00:00.16
Hope this will give you a basic idea.
Kind regards.
LOULOU.
-
Reg: Hierarchical query (using connection by)
Hi all
I got the result with the hierarchical query in the form:
* / qxxh *.
* / qxxh/jxobcbg *.
* / qxxh/jxobcbg/n00wcp4 *.
* / qxxh/jxobcbg/n00wcp4 / 000263 x *.
* / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
* / qxxh/jxxocbg *.
* / qxxh/jxxocbg/n00voc1 *.
* / qxxh/jxxocbg/n00voc1 / x 000589 *.
* / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
* / qxxh/jxuwxxh *.
* / qxxh/jxuwxxh/n00xpxf *.
* / qxxh, jxuwxxh, n00xpxf, m00bxpl *.
* / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x *.
* / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.
Here, I want to select only the maximum path. Here I used "SYS_CONNECT_BY_PATH.
Please let meknow how to do this?
Thanks in advance.
Published by: udeffcv on December 9, 2009 22:03udeffcv wrote:
Hi all
I got the result with the hierarchical query in the form:
* / qxxh *.
* / qxxh/jxobcbg *.
* / qxxh/jxobcbg/n00wcp4 *.
* / qxxh/jxobcbg/n00wcp4 / 000263 x *.
* / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
* / qxxh/jxxocbg *.
* / qxxh/jxxocbg/n00voc1 *.
* / qxxh/jxxocbg/n00voc1 / x 000589 *.
* / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
* / qxxh/jxuwxxh *.
* / qxxh/jxuwxxh/n00xpxf *.
* / qxxh, jxuwxxh, n00xpxf, m00bxpl *.
* / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x *.
* / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.Here, I want to select only the maximum path. Here I used "SYS_CONNECT_BY_PATH.
Please let meknow how to do this?
Thanks in advance.Published by: udeffcv on December 9, 2009 22:03
What do you mean by maximum path? is this...
* / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
* / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
* / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.is it child nodes?
so, you would like to see
Column nickname... CONNECT_BY_ISLEAF example, you can find it in the link below
http://download.Oracle.com/docs/CD/B14117_01/server.101/b10759/pseudocolumns001.htm#sthref670Ravi Kumar
-
Format the results of the SQL query, currently, show as below.
Select license_type, correspondents of license_info where license_type in ('TEM', 'TDM') order by license_type;
TDM 1445140800000000000
TDM 1420952400000000000
TDM 1444363200000000000
TDM 1445054400000000000
TDM 1428724800000000000
TEM 1421125200000000000
TEM 1423890000000000000
TEM 1449637200000000000
TEM 1444968000000000000
TEM 1428724800000000000I need formatting like below
Expected result:
TDM 1445140800000000000 TEM 1421125200000000000
TDM 1420952400000000000 TEM 1423890000000000000
TDM 1444363200000000000 TEM 1449637200000000000
TDM 1445054400000000000 TEM 1444968000000000000
TDM 1428724800000000000 TEM 1428724800000000000I have sample data only, Blue said the change in your main table request
Try:
Select max (f1),
Max (F2),
Max (F3),
Max (F4)
de)
Select decode (license_type, 'TDM' license_type) f1,
Decode (license_type, 'TDM', expiration_date) f2,
Decode (license_type, 'TEM' license_type) f3,
Decode (license_type, 'TEM', expiration_date) f4,
ROW_NUMBER() over (partition by order correspondents license_type) r
Of
)
R group
----
Ramin Hashimzade
Maybe you are looking for
-
Scanner connected to the computer and the wall, but still not let me scan
I have a "printer, scanner and copier" HP all-in-one. The printer itself is out of ink and paper, but I can't get the scanner to work. The USB cable is plugged into the laptop and the other cord is plugged into a wall outlet, but it still won't let m
-
Q5 frozen touch screen BlackBerry
I bought a Q5 for my daughter for Christmas, and the touch screen no longer works. I have wiped the device, rebooted the OS - still no answer. Any suggestions?
-
I work for a major bank in South Africa and I am looking to buy the picture 750/month for my business plan unit, as our designer should be for the marketing of material. But that is part of a large company I can't buy it upfront with a credit card, i
-
I use Enterprise Manager and am willing to change some settings in some files. Can I please have the best way to stop the database, so that I may edit some files and then start the database to the top. Thank you
-
Interaction of the DB somehow is more a standard part of a Web site based on the data? Or are old so inelegant Server somehow behaviors that they have done something new and I am simply not see?I was about to pull the trigger on a subscription of the