Hierahical Oracle query
Can you help me get crawl space resulting from the oracle table. Here especially, I want to get the Qty_above columns. It is calculated as
qty_above = the parent node qty_above * Qty value of the current node.
Name of the table: -.
project_product_structure_tab
. Table create statement given the bottom of the page.
create table PROJECT_PRODUCT_STRUCTURE_TAB
seq_no NUMBER not null,
parent_seq_no NUMBER ,
sorting_code NUMBER not null,
modified_structure VARCHAR2 (1) not null,
qty NUMBER not null,
rental VARCHAR2(30),
pos VARCHAR2(10) not null,
customer_part_no VARCHAR2 (80),
customer_part_desc VARCHAR2 (200),
information VARCHAR2 (2000),
site VARCHAR2(5),
mrp_code NUMBER ,
proj_work NUMBER ,
proj_level_work NUMBER ,
Calc_WORK NUMBER ,
dt_calc_work DATE ,
dt_calc_hour DATE ,
dt_cre DATE not null,
user_created VARCHAR2 (30) not null,
dt_chg DATE ,
user_sign VARCHAR2 (30),
operation_list_template VARCHAR2 (10),
calc_value NUMBER ,
dt_calc_value DATE ,
dt_designed DATE ,
dt_realized DATE ,
aquisition_code VARCHAR2 (1) not null,
part_no VARCHAR2 (25) not null,
part_rev VARCHAR2 (6) not null,
project VARCHAR2 (10) not null,
tag_no VARCHAR2 (20),
activity_seq NUMBER ,
part_responsible VARCHAR2 (20),
serial_no VARCHAR2 (50),
dt_received DATE ,
dt_issued DATE ,
qty_above NUMBER ,
qty_received NUMBER ,
qty_issued NUMBER ,
rowversion DATE not null,
RowState VARCHAR2 (20) not null,
part_ownership VARCHAR2 (20) not null,
supply_option VARCHAR2 (20),
net NUMBER ,
qty_assigned NUMBER ,
reservation_type VARCHAR2 (10),
reserve_at_receipt NUMBER not null,
text_id$ VARCHAR2 (50) default SYS_GUID() not null,
provide VARCHAR2 (7),
RowKey VARCHAR2 (50) default sys_guid() not null,
supply_created VARCHAR2 (20) not null,
configuration_id VARCHAR2 (50) not null,
use_project_operations VARCHAR2 (20) not null,
build_structure_date DATE ,
config_modified_date DATE ,
ADDRESS_ID VARCHAR2 (50)
Like this:
WITH PROJECT_PRODUCT_STRUCTURE_TAB (seq_no, parent_seq_no, quantity)
(SELECT 11, NULL, 2 FROM dual UNION ALL)
SELECT 22,11,3 FROM dual UNION ALL
SELECT 33,22,4 FROM dual UNION ALL
SELECT 44,33,5 FROM dual UNION ALL
SELECT 55,22,6 FROM dual UNION ALL
SELECT double 66,11,7)
my_hierarchy (parent_seq_no, seq_no, parent_qty, quantity)
Did YOU (SELECT seq_no, parent_seq_no, qty, quantity
OF project_product_structure_tab
WHERE parent_seq_no IS NULL
UNION ALL
SELECT child.seq_no, child.parent_seq_no, child.qty, parent.parent_qty * child.qty
OF project_product_structure_tab CHILD
INNER JOIN my_hierarchy ON PARENT (PARENT.seq_no = CHILD.parent_seq_no))
Select *.
of my_hierarchy
/
HTH
Tags: Database
Similar Questions
-
Question the use of Oracle query Variables
Hello
I am new to Oracle, I tried to extract the data from the Oracle database by using the following query which includes 1 variable SYSDATE_UTS, but when I try to execute the query I get an error. Please let me know what I am doing wrong and how I can fix.
Error message
-----
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause in this SELECT statement
-----
Oracle query
DECLARE SYSDATE_UTS NUMBER: = (sysdate-to_date('19700101','yyyymmdd')) * 86400;
BEGIN
SELECT
INCIDENT_NUMBER,
TO_DATE (to_char ((1/86400 * REPORTED_DATE) + to_date ('19700101', 'YYYYMMDD'), "jj/mm/aaaa hh24:mi:ss"), 'hh24:mi:ss dd/mm/yyyy') as REPORTED_DATE_TIME,
GROUP_TRANSFERS
LAST_MODIFIED_BY
, to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * LAST_MODIFIED_DATE, "mm/dd/yyyy hh24:mi:ss"), 'hh24:mi:ss dd/mm/yyyy') as LAST_MODIFIED_DATE
, (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) age
CASE
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 0 AND 1, THEN ' 0 - 1 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 2 AND 4 and THEN 2-4 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 5 AND 9, THEN 5-9 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 10 AND 19, THEN 10-19 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) > 20 THEN ' Days 20 + ".
ANOTHER "UNKNOWN".
END AS AGE_GROUP
OF IncidentDataBase
and the STATE not in (4,5,6)
and rownum < 10;
END;If you run this query in sql * plus you can declare a sql * more variable, assign a numeric value according to 'now' and use in your application, i.e.
SQL > variable NUMBER of SYSDATE_UTS;
SQL > exec SYSDATE_UTS: = (sysdate-to_date('19700101','yyyymmdd')) * 86400;You would then call your request, referring to sql * more variable with a colon as SYSDATE_UTS prior to it (i.e.: SYSDATE_UTS)
SELECT
INCIDENT_NUMBER,
TO_DATE (to_char ((1/86400 * REPORTED_DATE) + to_date ('19700101', 'YYYYMMDD'), "jj/mm/aaaa hh24:mi:ss"), 'hh24:mi:ss dd/mm/yyyy') as REPORTED_DATE_TIME,
GROUP_TRANSFERS
LAST_MODIFIED_BY
, to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 * LAST_MODIFIED_DATE, "mm/dd/yyyy hh24:mi:ss"), 'hh24:mi:ss dd/mm/yyyy') as LAST_MODIFIED_DATE
, (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) age
CASE
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 0 AND 1, THEN ' 0 - 1 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 2 AND 4 and THEN 2-4 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 5 AND 9, THEN 5-9 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) BETWEEN 10 AND 19, THEN 10-19 days
WHEN (to_date (to_char (to_date ('01011970 ', 'ddmmyyyy') + 1/24/60/60 *: SYSDATE_UTS, ' mm/dd/yyyy'), ' mm/dd/yyyy'))-(to_date (to_char (+ to_date('19700101','yyyymmdd') + 1/86400 * REPORTED_DATE, ' mm/dd/yyyy'), ' mm/dd/yyyy')) > 20 THEN ' Days 20 + ".
ANOTHER "UNKNOWN".
END AS AGE_GROUP
OF IncidentDataBase
and the STATE not in (4,5,6)
and rownum<>Table stores IncidentDataBase the "dates" in the number of seconds since the epoch unix?
-
Hello World ^^
I just downloaded Oracle XE and migrated my database from MySQL to Oracle successfully.
And I'm doing/reviewing my application now especially the query syntax.
I am facing a problem, I have a request in the form below in MySQL and it works fine but when I tried it at the Oracle XE database, it cannot run :( So I'm asking for help here, I have already searched on the internet but had no luck.
SELECT A.INVOICEDATE,
*@Step1:=cast (adddate (A.INVOICEDATE, A.TERMOFPAYMENT) as date) AS STEP1, *.
*@Step2:=if (@step1 > CURDATE (), A.TOTALAMOUNT, 0) AS STEP2, *.
*@step3:=if (@step2 <>0,0,IF(DATEDIFF(CURDATE(),@step1) < = 30, A.TOTALAMOUNT, 0)) AS step 3,
T_invoice FROM has
WHERE A.STATUS = 'Open'
I can conclude the problem is based on the variable declaration in Oracle, but I still can't understand.
What I do in MySQL, it's that I want to fill the variable with the expression/logic so I can use 'than' variable more later in the other part of the query output syntax.
I used variables to be filled by value due to I can't use / select ALIAS later in the other party.
So please help to convert to Oracle query syntax. Thank you.Oracle and MySql are two different animals. You need to learn SQL and Oracle's PL/SQL.
Your SQL
SELECT A.INVOICEDATE, @step1:=cast(ADDDATE(A.INVOICEDATE,A.TERMOFPAYMENT) as date) AS STEP1, @step2:=IF(@step1>CURDATE(),A.TOTALAMOUNT,0) AS STEP2, @step3:=IF(@step20,0,IF(DATEDIFF(CURDATE(),@step1)<=30,A.TOTALAMOUNT,0)) AS STEP3, FROM t_invoice A WHERE A.STATUS='Open'
Can be writern as
select invoicedate, step1, step2, case when step2 = 0 then case when sysdate-step1 <=30 then A.TOTALAMOUNT else 0 end end AS step3 from ( select A.invoicedate, A.invoicedate+A.termofpayment step1, case when (A.invoicedate+A.termofpayment) > sysdate then A.totalamount else 0 end as step2, from t_invoice A where A.status = 'Open' )
-
How Oracle query space on versions
Hey Geeks,
I'm doing a spatial query to find the intersection of polygons.
But the scenario is, for the new user there will be a new version under his name, then he creates features in bentley map and post in Oracle Server.
Then I need to make the query to find those who intersect but only entities newly created version.
SELECT c.RECORD_ID FROM VW_LYR_STES c, T_LYR_LND p WHERE c.case_id = 'ABCD019034. '
AND SDO_RELATE (c.GEOM, p.GEOM, 'mask = anyinteract') = 'TRUE '.
Any ideas on how to achieve this, queries on the particular version.
Thanks in advance,
Ken
With Workspace Manager you shouldn't really be query the table LT - you should go through the view of high - T_LYR_STES in your case. You can query the underlying table for the LT, but it's a bit nebulous art. I use Workspace Manager for years and I've never asked the LT table directly if trying to debug some weird data scenarios. In the normal course of events, you always pass by the view.
If the user has not yet merged to the workspace, then you should go to this area of work and request here. For example
execute dbms_wm.goToWorkspace('
); SELECT c.RECORD_ID FROM VW_LYR_STES c, T_LYR_LND p WHERE c.case_id = 'ABCD019034' AND SDO_RELATE(c.GEOM,p.GEOM,'mask=anyinteract') = 'TRUE'; -
Oracle query performance.
In one of my oracle procedure, I make the following query.
Select plate in amountA from Table1 where Bill_id = billId and CATEGORY = 'A ';
Select plate in amountB from Table1 where Bill_id = billId and CATEGORY = 'B ';.
Select plate in amountC from Table1 where Bill_id = billId and CATEGORY = 'C ';
I want to improve this code block. I want to make a single request and get the result.
SELECT
(Select sum(amount) into amountA from Table1 Where Bill_id=billId and CATEGORY='A') AS x1,
(Select sum(amount) into amountB from Table1 Where Bill_id=billId and CATEGORY='B') AS x2,
(Select sum(amount) into amountC from Table1 Where Bill_id=billId and CATEGORY='C') AS x3Can be a solution, but I not wish on it.
Is there a better approach?
Select sum (decode (category 'A', amount, 0))
sum (decode(category,'B',amount,0))
sum (decode(category,'C',amount,0))
in amountA
amountB
amountC
FROM table1
where bill_id = billid
and the category ('A', 'B', 'C');
-
Behavior inconsistent performance Oracle query
Consider the following query:
SELECT * FROM ( SELECT ARRM.*, ROWNUM FROM CRS_ARRANGEMENTS ARRM WHERE CONCAT(ARRM.NBR_ARRANGEMENT, ARRM.TYP_PRODUCT_ARRANGEMENT) > CONCAT('0000000000000000', '0000') ORDER BY ARRM.NBR_ARRANGEMENT, ARRM.TYP_PRODUCT_ARRANGEMENT, ARRM.COD_CURRENCY) WHERE ROWNUM < 1000;
This query is performed on a table that has 10 000 000 entries. While running the query Oracle SQL Developer or my application it takes 4 minutes to run! Unfortunately, it's also the behaviour within the application I am writing. Change the value of 1000 to 10 has no impact, which suggests that he made a full table scan.
However when the squirrel running the query returns within a few milliseconds. How is that possible? Explain plan generated in squirrel gives:
But a plan different explain is generated in Oracle SQL Developer, for the same query:
No idea how this difference in behavior is possible? I can't understand it. I tried with JPA and raw JDBC. In the application, I need to parse through 10 000 000 records and this query is used for pagination, so 4 minutes of waiting is not an option (which would take 27 days).
Note: I use the same Oracle jdbc driver into a squirrel and my application so it's not the source of the problem.
I also posted this to other web sites, for example
http://StackOverflow.com/questions/28896564/Oracle-inconsistent-performance-behaviour-of-query
OK - I created a test (below) case and got the same exact results you did 'test' - a FFS using SQL index * more. I then tested with SQL Developer and got the same results. You are 100 billion sure that you did not have two databases somewhere with the same name?
SQL> create table crs_arrangements 2 (nbr_arrangement varchar2(16) not null, 3 product_arrangement varchar2(4) not null, 4 cod_currency varchar2(3) not null, 5 filler1 number, 6 filler2 number); Table created. SQL> alter table crs_arrangements add constraint crs_pk primary key 2 (nbr_arrangement, product_arrangement, cod_currency); Table altered. REM generate some data SQL> select count(*) from crs_arrangements; COUNT(*) ---------- 10000000 SQL> exec dbms_stats.gather_table_stats('HR', 'CRS_ARRANGEMENTS', cascade=>true); SQL> ed Wrote file afiedt.buf 1 explain plan for 2 SELECT * FROM 3 ( SELECT ARRM.*, ROWNUM FROM CRS_ARRANGEMENTS ARRM 4 WHERE CONCAT(ARRM.NBR_ARRANGEMENT, ARRM.PRODUCT_ARRANGEMENT) > CONCAT(' 0000000000000000', '0000') 5* ORDER BY ARRM.NBR_ARRANGEMENT, ARRM.PRODUCT_ARRANGEMENT, ARRM.COD_CURRENCY) WHERE ROWNUM < 1000 SQL> / ------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- ------------------- | 0 | SELECT STATEMENT | | 999 | 55944 | 112 7 (0)| 00:00:14 | |* 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1000 | 56000 | 112 7 (0)| 00:00:14 | | 3 | COUNT | | | | | | | 4 | TABLE ACCESS BY INDEX ROWID| CRS_ARRANGEMENTS | 500K| 17M| 112 7 (0)| 00:00:14 | |* 5 | INDEX FULL SCAN | CRS_PK | 1000 | | 13 0 (0)| 00:00:02 |
However, as noted earlier in this thread:
alter session set NLS_SORT = FRENCH; | 0 | SELECT STATEMENT | | 999 | 55944 | | 202 85 (1)| 00:04:04 | |* 1 | COUNT STOPKEY | | | | | | | | 2 | VIEW | | 500K| 26M| | 202 85 (1)| 00:04:04 | |* 3 | SORT ORDER BY STOPKEY| | 500K| 17M| 24M| 202 85 (1)| 00:04:04 | | 4 | COUNT | | | | | | | |* 5 | TABLE ACCESS FULL | CRS_ARRANGEMENTS | 500K| 17M| | 155 48 (1)| 00:03:07 |
Can you check your preferences of SQL Developer under database-> NLS and ensure that sorting is set to BINARY? I wonder if either he is on something else in SQL Developer or maybe your by default, the database is not BINARY and squirrel is assigning BINARY when connecting.
-
Hello
We are generating SSRS reports based on Oracle DB as backend. We are using oracle 11.2.0.3. We have a request in oracle that is created on the view and lots of conditions. It takes more than 8 minutes to generate a report. What are the steps I should follow to refine the query to generate report in very less time. Can someone suggest me please.
Thank you
VI
Good to hear! The appearance to explain what now?
How long does it take?
[edit] Cartesian join are not always bad, however, they are usually a good candidate to look at on a long running (in my experience anyway) query [/ edit]
If the answer to the question, the brand is so
-
Oracle query sort by case-sensitivity
Hi all
I use the oracle 11g database.
My use case is that I have a table with the following values
Name table - test
product id productsortdescription H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE 043994 Alloy .MM.INTHICK
My query is
select * from test order by productsortdescription;
This query gives the result as it is like
product id productsortdescription
H58098 ACETA
product id productsortdescription
H58098 ACETA
produit id productsortdescription
H58098 ACETA
product id productsortdescription
H58098 ACETA
product id productsortdescription H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE 043994 Alloy .MM.INTHICK
MIDOHYDROXYPHENYLTHIAZOLE
043994 alloy. MR. INTHICK
but early output/outcome should be as below:
product id productsortdescription
043994 Alloy. MR. INTHICK H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE
like all and ACE in productsortdescription
l is in a small suitcase to C.
The NLS Session parameters are as follows
SELECT * from NLS_SESSION_PARAMETERS;
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS.,.
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI. SSXFF AM
NLS_TIMESTAMP_FORMAT-DD-MON-RR HH.MI. SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI. SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI. SSXFF AM TZR
NLS_DUAL_CURRENCY $
BINARY NLS_COMP
NLS_LENGTH_SEMANTICS BYTES
NLS_NCHAR_CONV_EXCP FAKE
Please, help me in this scenario.
One option is to use the NLSSORT function. Most of the ASCII character set defines the sort lowercase before uppercase but EBCDIC kinds of lowercase before uppercase. So you can use
with t as)
Select the id "H58098", "ACETAMIDOHYDROXYPHENYLTHIAZOLE" union str double all the
SELECT id, ' 043994 ',' alloy. Mr. INTHICK' double str
)
SELECT id, str
t
NLSSORT order (str, 'NLS_SORT = EBCDIC')
;ID STR
------ ------------------------------
043994 alloy. MR. INTHICK
H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE
Of course, if your strings can contain non-alphanumeric characters, you should check that the sort of EBCDIC order is acceptable for them as well. To check this, you can use something like
with t (str, ascii) as long as)
Select chr(level+32), level + 32 double connect by level<=>=>
)
Select str, ascii from t by NLSSORT (str, 'NLS_SORT = EBCDIC')
;
or simply do a search of the internet on EBCDIC. You can also substitute other kinds of language for EBCDIC and see if any of them meet your needs. See Appendix A of the Guide to support globalization for the list of valid values for NLS_SORT.
You say that you are on 11g - if you want to say 11.2.x, then you can use the listagg function to get a more compact view of the sort order:
with t (str, ascii) as long as)
Select chr(level+32), level + 32 double connect by level<=>=>
)
Select listagg (str) in the Group (order by NLSSORT (str, 'NLS_SORT = EBCDIC')) as EBCDIC_order
t
;
EBCDIC_order
----------------------------------------------------------------------------------------------. <(+|&!$*);- %_="">?': #@'="abcdefghijklmnopqr~stuvwxyz[^]{ABCDEFGHI}JKLMNOPQR\STUVWXYZ0123456789
Kind regards
Bob
(+|&!$*);-> -
Hierarchical Oracle query help needed - path between the crux of two brothers and sisters
I want to find the path between two nodes of oracle hierarchical Table.
Consider the following case-
NodeId - ParentId
=============
1 > > > > > > 0
2 > > > > > > 1
3 > > > > > > 2
4 > > > > > > 3
5 > > > > > > 0
6 > > > > > > 5
Here I want to query the database table that if there is a path between nodes 3 and 5?
The previous query you provided work upwards to the root node.
Here is my expected result, 3-> 2-> 1-> 0-> 5
Yet once if I have a query in the table to get the path between 1 and 3, I want to get out of the way - next
1-> 2-> 3
Therefore, the query works in both cases. Where ADI root can act as an intermediate or no node.
Can you please guide me how I can get it?
Thank you.Hello
user13276471 wrote:
I want to find the path between two nodes of oracle hierarchical Table.Consider the following case-
NodeId - ParentId
=============
1 >>>>>> 0
2 >>>>>> 1
3 >>>>>> 2
4 >>>>>> 3
5 >>>>>> 0
6 >>>>>> 5
Here I want to query the database table that if there is a path between nodes 3 and 5?
The previous queryWhat application is this? If you're referering to another thread, then post a link, such as {message identifier: = 10769125}
you provided work upwards to the root node.
Here is my expected result, 3--> 2--> 1--> 0--> 5
Yet once if I have a query in the table to get the path between 1 and 3, I want to get out of the way - next
1--> 2--> 3Therefore, the query works in both cases. Where ADI root can act as an intermediate or no node.
Can you please guide me how I can get it?
I think you want something like this:
WITH bottom_up_from_src AS ( SELECT nodeid , parentid FROM table_x START WITH nodeid = :src_nodeid CONNECT BY nodeid = PRIOR parentid ) , bottom_up_from_dst AS ( SELECT * FROM bottom_up_from_src UNION ALL SELECT parentid AS nodeid , nodeid AS parentid FROM table_x WHERE nodeid NOT IN ( SELECT nodeid FROM bottom_up_from_src ) START WITH nodeid = :dst_nodeid CONNECT BY nodeid = PRIOR parentid ) SELECT :src_nodeid || SYS_CONNECT_BY_PATH (parentid, '-->') AS display_path FROM bottom_up_from_dst WHERE parentid = :dst_nodeid START WITH nodeid = :src_nodeid CONNECT BY nodeid = PRIOR parentid ;
This will show how you can get it from: src_nodeid at dst_nodeid, moving to the top or to the bottom of a hierarchy at a time step. This will work regardless of the fact that
- : src_nodeid is the ancestor of the: dst_nodeid, or
- : src_nodeid is a descendant of: dst_nodeid, or
- both: src_nodeid and: dst_nodeid are the descendants of another node (e.g. 0).
- : src_nodeid is the ancestor of the: dst_nodeid, or
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0). It is always important, but particularly so with CONNECT BY queries, because each version since Oracle 7 had significant improvements in this area.
See the FAQ forum {message identifier: = 9360002}
some doubts in the conversion of oracle query
I have to convert the following query in ms access to oracle.INSERT INTO the Bill (Reffacture, InvoiceDesc)
Select a_Invoices! [Ref provider] & "-" & Trim (a_Invoices! [invoice No.]) & "Q" & DatePart ("q", [invDate]) & "-" & DatePart("yyyy",[invDate]) & "SB" as Reffacture.
Trim (a_Invoice_Desc! [Invoice line Description]) AS a Expr4
Of a_Invoices a_Invoice_Desc INNER JOIN
WE (a_Invoices. [Ref provider] is a_Invoice_Desc. [Ref provider])
AND (a_Invoices. [Invoice No.] is a_Invoice_Desc. [Invoice No.)]
WHERE (((a_Invoices. [<>ACK GL account]) »--- »)) ;
for the quarter, I tried with select to_char (to_date ("PRVBTOT", "dd/mm/yy '"), 'Q') as quarterdate of "a_Invoices" - it worked, but how to combine all the
Hello
882431 wrote:
Thanks for the input... I have another doubt based on the dateI have a date stored in a field of type varchar, n'm copy in the date field
For example: ' 18/4/2011 0:0:0.0' varchar field is, I tried with "' 2011/4/18 as yyyy/mm/dd ', I can add hh: mm: for the moment (I wasn't looking this), but there is one.0, can someone please tell me how shud convert it..." Sorry if asking a basic question, I already searched but to no avail.
DATEs do not include fractions of a second. If you don't mind losing fractions of a second, you can simply remove them before pass the string to TO_DATE, like this
TO_DATE ( REGEXP_REPLACE ( varchar2_column
, '\.[0-9]*$'
)
, 'YYYY/MM/DD HH24:MI:SS'
)
REGEXP_REPLACE will remove the decimal point and any numbers after him. If the string does not contain a decimial, it is correct: REGEXP_REPLACE returns the immutable string in this case.
If the fraction of a second is important, use a TIMESTAMP instead of a DATE column (and use the TO_TIMESTAMP instead of TO_DATE function).
simple oracle query does not not in cf9
When running in oracle 10 g, this query returns correctly a line:
WITH myResults AS
(
SELECT 1 AS MonNiveau, "someString" AS myData
OF the double
)
SELECT *.
OF myResults;
Returns:
MONNIVEAU | MYDATA |
1 | someString |
When put inside a cfquery in a cf9 page, returns nothing.
< cfset qryRan = "false" >
< isDefined ('myQry.recordCount') cfif >
< cfset qryRan = "true" >
< / cfif >
Qry: < cfoutput > #qryRan # < / cfoutput >
Returns:
Qry: false
Yes, the query always had the name the value attribute
It was certainly the oracle driver, I install v10.1 in parallel with 8.1, recreated my datasources and everything works fine now
Thanks for the reply
Need to improve the performance of oracle query
HelloCurrently I wrote the request to get the maximun of XYZ company like this salary
Select the salary of)
Select the salary of the employee
where the company = "XYZ".
salary desc order)
where rownum < 2;
I thought to replace the same with the following query
Select max (salary)
the employee
where the company = "XYZ";
That one will be faster? can you provide some statistical data. It will be good if you share an oracle for this documentation.
Thank you
Khaldi
Well, that's your requests, your data contained in your database, on your hardware... Anything that can have an impact. So who better to check if there is no difference in performance than yourself?
Enable SQL tracing, run the statements, then analyze trace (with the help of tkprof or similar) files and look at the differences.
Oracle query to generate date and calculate fees
Hi, please help me to create a query to get the end result of both tables as below
CREATE TABLE detention_charge_slot (slot_no NUMBER(5), from_days NUMBER(10), to_days NUMBER(10), charge_amount NUMBER(10,2)); INSERT INTO detention_charge_slot VALUES (1,1,4,0); INSERT INTO detention_charge_slot VALUES (2,5,9,10); INSERT INTO detention_charge_slot VALUES (3,10,14,20); INSERT INTO detention_charge_slot VALUES (4,15,999,25); CREATE TABLE detention_invoice (invoice_no NUMBER(10), invoice_dt DATE, delivery_dt DATE); INSERT INTO detention_invoice VALUES(1,'10-JAN-2015','25-JAN-2015');
Where expected result 1 = Invoice_no:
Start_date | End_date | Days | Charge_Amount |
---|---|---|---|
JANUARY 10, 2015 | JANUARY 13, 2015 | 4 | 0 |
JANUARY 14, 2015 | 18 JANUARY 2015 | 5 | 10 |
19 JANUARY 2015 | JANUARY 23, 2015 | 5 | 20 |
JANUARY 24, 2015 | 25 JANUARY 2015 | 2 | 25 |
If you expect more than one line in DETENTION_INVOICE, use the following query
WITH DATES
AS
(SELECT DI. INVOICE_DT + FROM_DAYS - 1 START_DATE,
LEAST (DI. INVOICE_DT + TO_DAYS - 1, DELIVERY_DT) END_DATE.
CHARGE_AMOUNT
OF DCS, DETENTION_INVOICE DI DETENTION_CHARGE_SLOT
where di.invoice_no = 1)
SELECT start_date, end_date - + 1 days START_DATE, end_date, charge_amount
OF DATES
Hi all
I was reading about architecture oracle docs and
I was confused that if oracle database receives a Sql statement, then he gets first in what part of the LMS? Area DBBC or SQL shared (in the Shared pool).
Thanks in advance
If you want to understand the process, you need to actually READ this doc of Concepts - not just look at the pictures.
1. even the output of select statements gets written in Database Buffer and Redo Log Buffer, respectively.
NO! -Read this doc and learn the purpose of the buffer cache and the redo logs. Why a select statement would cause data is written in the REDO logs if there was no change to the data?
2 and when a DDL / DML statements is executed, first exit-East block written to redo log buffer and then he gets to the data buffer.
NO! -Read this doc and learn the purpose of the buffer cache and the redo logs. If the data did not change why it would be written to the REDO log?
http://docs.Oracle.com/CD/E11882_01/server.112/e40540/physical.htm#sthref1447
Structure of the online Redo Log
Online redo logs contain records of roll forward. A redo record is composed of a group of agents of change, which describes a change to a data block. For example, an update to a salary in the
employees
table generates a redo record that describes the changes on the block of the data segment of the table, the data of the undo segment block and the table transactions undo segments.
Do you think ANY reference to a select in there?
Read the section above.
Hello
I have a customer as requirement below
We have the table header and contains data such as
ID, custname, socket
101, raju, 514
102, ratna, 12
103, rakesh, 16
104, joseph, 129
and we mappingtable like below as
sampval, socket
244094,512
244095,2
244096,4
244097,8
244098,16
244102,128
244103,1
If header.mapvalue is 514 analysis then it out on the mappingtable basis to be exported for a value of 244094. 244095.
Header.mapvalue is 12 parsing it out based on mappingtable to be exported for a value of 244096. 244097 and so on...
Could you please help me how to get the functionality in a database query.
Thanks in advance
Try to query below and let me know
SELECT id,
custName,
HT.mapvalue,
req_val
From ht header_tbl,
(SELECT SAMPVAL,
socket,
CITY,
SUMVAL,
REQ_VAL
Of
(SELECT SAMPVAL,
socket,
CITY,
SUMVAL,
REQ_VAL,
ROW_NUMBER() over (ORDER BY lvl SUMVAL PARTITION) rn
Of
(SELECT sampval,
socket,
City,
LEVEL lvl,
CASE
WHEN ((= LEVEL 2)
AND (socket = socket connect_by_root))
THEN socket
ANOTHER socket + connect_by_root socket
END as sumval,
CASE
WHEN ((= LEVEL 2)
AND (socket = socket connect_by_root))
THEN TO_CHAR (sampval)
Of OTHER TO_CHAR (CONNECT_BY_ROOT sampval
||'|'
|| sampval)
END AS req_val
A mapping
CONNECT BY LEVEL<=>=>
)
WHERE the lvl = 2
)
WHERE rn = 1
) qry_rslt
WHERE ht.mapvalue = qry_rslt.sumval;
An alternative with xmlagg, you can use this query to achieve your requirement
SELECT id, custname, RTRIM (xmlagg (xmlelement(e,mp.sampval||'|')). Extract ('//Text ()'),'| ') req_val
From header_tbl, mapping mp ht
WHERE mp.mapvalue = BITAND (mp.mapvalue, ht.mapvalue)
GROUP BY id, custname;
Maybe you are looking for
-
Why some websites list stores near Richardson, TX - when I live in Modesto, CA?
On some sites, when a company offers stores near me, they list stores near Richardson, TX. They are businesses that do not require a zip code or the name of the city. Is this info stored somewhere in/by Firefox? How can I change the name of default (
-
Hello I enclose a VI that measures and displays capacity depending on the tension swept to a "keithley 590" meter. In the llb file fix, I use the vi called "590-CV Measurement.vi. I get the error 'error Code 6 in reading GPIB in 590-CV Meaurement.vi
-
Modbus Library for serial comm.
I downloaded version 8.2 of labview libray and tried to use the serial port to test the provided example of master/slave... For some reason any null-modem solution does not work for me (I tested with success of communication RS-232 example) P.S. I ge
-
I think buying a 3634 hp printer. I noticed that it says it prints standard #10 envelopes. Print on #6 3 / 4 envelopes?
-
Looking for a Windows Update updates forever
Hello! I have problems with Windows Update on my old laptop with Windows Vista Home Basic installed. Basically what is happening is not able to complete the search for updates. I tried Microsoft FixIt (it reveals an error 0 x 80070003 in the end and