Connect by Prior in Oracle 8i question
Need help with building tree-structured query in Oracle 8i (Forms 6i front end if it matters).
Sample structure and data:
CREATE TABLE table_list
my_code NUMBER,
my_level NUMBER,
my_description VARCHAR2(60)
CREATE TABLE table_content
my_code NUMBER,
term_code NUMBER,
term_category VARCHAR2(5)
INSERT into table_list values (101, 1, 'building');
INSERT into table_list values (102, 2, 'flat');
INSERT into table_list values (103, 3, 'living room');
INSERT into table_list values (104, 3, 'bedroom');
INSERT into table_list values (105, 3, 'bathroom');
commit;
INSERT into table_content values (101, 102, 'Sub');
INSERT into table_content values (102, 103, 'Sub');
INSERT into table_content values (102, 104, 'Sub');
INSERT into table_content values (102, 105, 'Sub');
commit;
Need to display data in the following order:
101 'building' --level one
102 'flat' --level two
105 'bathroom' --level three
104 'bedroom' --level three
103 'living room' --level three
*(note alphabetical order in level three)*
Looks like Oracle 8i does not support table joins for CONNECT BY PRIOR. Please advise!
And you are correct, it does not display level 1. Do
you think this is this a database structure problem
or it could be corrected via query modification?No and yes. It's not a "structure" problem, its a data problem (as I explained above). You always fix data problems by making queries overly complex (hint, hint, I don't suggest doing it this way).
select tl.my_level, tl.my_description , LPAD(' ',3*(my_level-1)) || substr(tl.my_description, 1, 30) description
from table_list tl,
(select term_Code from table_content
start with my_code in (select my_code from table_list where my_level=1)
connect by prior term_code = my_code
) x
where x.term_code = tl.my_code
union all
select my_level, my_description
from table_list
where my_level = 1
order by 1, 2
better to add a row to table_content with my_code=null, term_code=101.
otherwise you'll be pulling stupid nonsense like above with every query from here on out.
Similar Messages
-
Connect by prior in Oracle 11g
I am upgrading an application from 9i to 11g and I've been told that the connect by prior sql is broken. While I am waiting for the example and the error message, is 11g pickier about looping than 9i was? Can someone point me to some documentation on 10 or 11 changes to hierarchical queries?
Thanks in advance.
JimHi, Jim,
user509659 wrote:
I am upgrading an application from 9i to 11g and I've been told that the connect by prior sql is broken. What do you mean? Post a link, or at least a more complete description of the problem.
While I am waiting for the example and the error message, is 11g pickier about looping than 9i was? Can someone point me to some documentation on 10 or 11 changes to hierarchical queries?There were a lot of improvements to CONNECT BY in Oracle 10, including CONNECT BY NOCYCLE (for working with loops), the CONNECT_BY_ROOT operator, and pseudo-columns CONNECT_BY_ISCYCLE and CONNECT_BY_ISLEAF. Look them up in the SQL Language manual for your version.
I don't know of any improvements or changes to CONNECT BY in Oracle 11.
Oracle 11.2 has recursive WITH clauses, that can do everything that CONNECT BY does, and more. Some things in 11.2 are simpler and more efficient using CONNECT BY, others are better done using recursive WITH clauses.
Everything that CONNECT BY did in earlier versions, it does in Oracle 11, as well. If you have a CONNECT BY query that works in Oracle 9, it should work in Oracle 11, without any changes, though there might be better ways to get the same results in Oracle 11.
Whenever you have a question, post youir code, and whatever is necessary to run it, including CREATE TABLE and INSERT statments for a little sample data. Post the results you want from that sample data, and an explanation of how you get those results from that data.
Always say which version of Oracle you're using, e.g. 11.2.0.2.0. The difference between 11.1 and 11.2 may be very significant in this case.
See the forum FAQ {message:id=9360002} -
Understanding multiple conditions in connect by prior clause Oracle
Hi ,
Can some one please explain me how to comprehend/understand multiple conditions in connect by prior conditions with some example data.
I am creating a table like this
CREATE TABLE FAMiLY_TREE
GRAND_FATHERID number,
FATHER_ID number,
SON_ID number,
person_name varchar(20)
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(NULL, NULL , 5 , 'Mr X ' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(null, 5 , 6 , 'Dave' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 7 , 'Vinny' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 16 , 'Omy' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 17 , 'Vijjy' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(6, 7 , 8 , 'Vicky' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(6, 7 , 9 , 'Varis' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 8 , 10 , 'Vshnu' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 8 , 11 , 'dyna' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(8, 10 , 14 , 'Marry' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(8, 10 , 15 , 'Mac' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 9 , 12 , 'Garry' );
INSERT INTO FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 9 , 13 , 'Ganny' );
SELECT
LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
START WITH SON_ID= 6
CONNECT BY PRIOR SON_ID = FATHER_ID
AND PRIOR FATHER_ID = GRAND_FATHERID ;
SELECT
LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
START WITH SON_ID= 6
CONNECT BY PRIOR SON_ID = FATHER_ID ;
Both These query return the same o/p
Dave
Vinny
Vicky
Vshnu
Marry
Mac
dyna
Varis
Garry
Ganny
Omy
Vijjy
Can some one please explain me comprehension of both these query or give me a example where i can understand multiple connect by prior conditions
ThanksMaybe (something to play with)
with
family_tree as
(select 'Green' family,null ancestor,1 person,'Mr X' person_name,1900 born from dual union all
select 'Green',1,2,'Dave',1920 from dual union all
select 'Green',2,3,'Vinny',1940 from dual union all
select 'Green',2,4,'Omy',1945 from dual union all
select 'Green',2,5,'Vijjy',1950 from dual union all
select 'Green',3,6,'Vicky',1960 from dual union all
select 'Green',3,7,'Varis',1965 from dual union all
select 'Green',6,8,'Vshnu',1980 from dual union all
select 'Green',6,9,'Dyna',1985 from dual union all
select 'Green',8,10,'Mary',2000 from dual union all
select 'Green',8,11,'Mac',2005 from dual union all
select 'Green',7,12,'Garry',1985 from dual union all
select 'Green',7,13,'Ganny',1990 from dual union all
select 'Brown',null,14,'Joe',1950 from dual union all
select 'Brown',14,15,'Jim',1970 from dual union all
select 'Brown',14,16,'Joy',1975 from dual union all
select 'Brown',14,17,'Jay',1980 from dual union all
select 'Brown',16,18,'Jack',1995 from dual union all
select 'Brown',18,19,'Jake',2010 from dual union all
select 'Brown',18,20,'Jess',2012 from dual
select family,
root_name||' ('||to_char(root_born)||')' "(FA/MO)THER",
children
from (select family,
root_born,
root_name,
ltrim(sys_connect_by_path(person_name||' ('||to_char(born)||')',', '),', ') children
from (select family,
connect_by_root(person_name) root_name,
connect_by_root(born) root_born,
person_name,
born,
row_number() over (partition by family,connect_by_root(person_name) order by born) rn
from family_tree
where level = 2
connect by prior person = ancestor
where connect_by_isleaf = 1
start with rn = 1
connect by prior root_name = root_name
and prior family = family
and prior rn + 1 = rn
order by family desc,root_born
Regards
Etbin -
Is it mandatory to use PRIOR in CONNECT BY NOCYCLE in Oracle 10.2.0.4
Hi,
Is it mandatory to use PRIOR in CONNECT BY NOCYCLE in Oracle 10.2.0.4.
While I am executing a query in 10.2.0.2 which is having CONNECT BY NOCYCLE and PRIOR is not included, it was executing fine.
But in 10.2.0.4 If i run the same query without using PRIOR in CONNECT BY NOCYCLE, it is running indefinitely.
If I add PRIOR in CONNECT BY NOCYCLE then it is executing successfully.
So I want to know is it mandatory to add PRIOR in CONNECT BY NOCYCLE from 10.2.0.4 onwards.
If Yes, can you please provide any support documents for that.
Thanks,
MahipalHi,
I was not using PRIOR with CONNECT BY NOCYCLE in 10.2.0.2, but the query ran perfectly in fraction of seconds without any issues.
But in 10.2.0.4 while I was running the same query, it has been running for longertimes.
Below is the Query:
SELECT 1 type_num, r.NAME root_name, r.DATA_GROUP root_data_group,
NULL child_name, NULL child_data_group, NULL child_type,
NULL facility_type
FROM DATA_GROUP r
WHERE r.DATA_GROUP = (SELECT MIN (DATA_GROUP)
FROM DATA_GROUP
WHERE node_type = 'R' AND tree_type = 'C'
GROUP BY tree_type)
UNION ALL
SELECT DISTINCT 2 type_num, NULL root_name, NULL root_data_group,
dg_child.NAME AS child_name,
dgl.DATA_GROUP AS child_data_group,
dg_child.node_type AS child_type, f.TYPE AS facility_type
FROM DATA_GROUP_LINK dgl, DATA_GROUP dg_child, FACILITY f
WHERE dgl.DATA_GROUP = dg_child.DATA_GROUP
AND dg_child.node_type = 'F'
AND f.facility_num = dg_child.DATA_GROUP
START WITH dgl.parent_data_group IN (
(SELECT DATA_GROUP
FROM DATA_GROUP_SYSTEM_USER
WHERE system_user_num = 1000088400 AND is_active = 'Y'
UNION
SELECT 1016189 AS DATA_GROUP
FROM DUAL))
CONNECT BY NOCYCLE dgl.parent_data_group = dgl.DATA_GROUP
We don't want to do any code changes in the query.
Please let me know is there in solution in 10.2.0.4 to run this query with out any code changes.
Thanks,
Mahi -
Oracle Virtual Machine Connect by Prior Problem
Hi Friends ,
In my company we have virtualization. this is new in our organization.
oracle image have been taken and put in to virtual machine.(vmware).
after that, procedure which has "connect by prior" start to create wrong output.
please help us on what to do to correct problem given above.
(my oracle version 10g)JAVAMAN2 wrote:
simple sample:
SELECT ROWNUM+2000-1 AS YIL FROM DUAL CONNECT BY ROWNUM <= 2010-2005 ORDER BY ROWNUM+2000-1 DESC;output on virtual machine
2009,2008,2007,2006,2005
output on real world
2010,2009,2008,2007,2006,2005If that is really the output from that query, then both your virtual machine and your "real world" are broken. On all 4 versions of Oracle I have available, I get:
SQL> SELECT ROWNUM + 2000 - 1 AS YIL
2 FROM DUAL
3 CONNECT BY ROWNUM <= 2010 - 2005
4 ORDER BY ROWNUM + 2000 - 1 DESC;
YIL
2004
2003
2002
2001
2000Which is what I would expect given that 2010 - 2005 = 5.
Perhaps if you showed an actual cut and paste from a sqlplus session on each machine someone might be able to help, however, I'm inclined to agree with sb92075 that it is a data issue in your real query.
John -
Hi,
Is there any way in toplink where i can use the connect by prior to select a hierarchy of values??As of version 9.0.4 the TopLink query/expression framework support the specification of hierarchical queries. The documentation is available at:
http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10313/queries.htm#1131259
Doug -
Connecting to an oracle database questions
<p>Our current solution to connecting to our oracle database uses the following code:</p><p> ReportClientDocument clientDoc = new ReportClientDocument;</p><p> java.sql.ResultSet rs = fetchResultSet(driverName, connectStr, userName, password, <u>query</u>);</p><p> clientDoc.getDatabaseController().setDataSource(rs, <u>tableName</u>,tableName+"_ResultSet"); </p><p>The code for subreports is very similar, but isn't necessary for my question. The problem w/ this approach is we have to define the SQL query and the table name in the JSP, which we shouldn't have to do considering both of these are stored in the report. Any changes to the reports' sql would then require someone to edit the jsp, which is just bad. </p><p>I have been reading up on the ConnectionInfo and ConnectionInfos classes (nice naming convention btw) and the CrystalReportViewer.setDataBaseLogonInfos() method, and I believe a solution may lie here. The problem is the tutorials on using the ConnectionInfo class assume the database name is stored in the report, and we do not want to assume this. We are developing our reports to be used by our customers, who may name their database whatever they want so long as the tables inside it are what we specify. Because of this assumption, I have yet to find a good explanation of how to use the setAttributes(PropertyBag) method which is the only I have seen to specify the database name (within a connection string). I have examples of it, but nothing that defines the key/value pairs required in the PropertyBag to create a connection to an oracle database. </p><p>Is there some documentation on the key/value pairs needed by the PropertyBag? Also, if there is another (easier) solution I am overlooking then please let me know, thanks.</p><p>-Sam Morehouse</p><p>HBF Group, Inc </p><p> </p>
<p>got it working, here's some sample code. </p><p> </p><p><%<br /> try{<br /> ReportClientDocument clientDoc = new ReportClientDocument();<br /> clientDoc.open(reportName, 0);<br /> <br /> ConnectionInfos connInfos = new ConnectionInfos();<br /> IConnectionInfo iConnInfo = new ConnectionInfo();<br /><br /> PropertyBag bag = new PropertyBag();<br /> bag.put("Database Class Name",driverName); // "oracle.jdbc.driver.OracleDriver"<br /> bag.put("Connection URL",connectStr); // "jdbc:oracle:thin:@dbName:1521:sid"<br /> <br /> PropertyBag pb = new PropertyBag();<br /> pb.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES ,bag);<br /> pb.put(PropertyBagHelper.CONNINFO_DATABASE_DLL ,"crdb_jdbc.dll");<br /> iConnInfo.setAttributes(bag);<br /> <br /> iConnInfo.setUserName(userName);<br /> iConnInfo.setPassword(password); <br /> <br /> iConnInfo.setAttributes(pb);<br /> <br /> connInfos.add(iConnInfo);<br /> session.setAttribute(reportName, clientDoc);<br /> session.setAttribute("reportSource", clientDoc.getReportSource());<br /><br /> //Setup viewer. Only going to include the relevant line, the rest can be found</p><p> //elsewhere.<br /></p><p> CrystalReportViewer oCrystalReportViewer = new CrystalReportViewer(); oCrystalReportViewer.setDatabaseLogonInfos(connInfos); } </p><p>catch(ReportSDKExceptionBase exc)%></p>
-
Clarification regarding understanding of ORACLE CONNECT BY PRIOR Clause
Dear All,
I am trying to understand ORACLE CONNECT BY CLAUSE and I wrote a query to verify my understanding.
I wrote the below two queries.
select level, lpad('*',2*(level -1),'*') ||ename t_ename, sys_connect_by_path(ename,'/') enames, empno, mgr from emp
--where empno =empno
start with empno=7654
--start with mgr is null
connect by prior empno = mgr;
LEVEL T_ENAME ENAMES EMPNO MGR
1 MARTIN /MARTIN 7654 7698
Explanation: Here Start with EMPNO=7654 Means, the root node is 7654. Connect BY PRIOR EMPNO=MGR Means--> For the empno=7654 are there any persons under him. IE. Mgr with 7654.
select level, lpad('*',2*(level -1),'*') ||ename t_ename, sys_connect_by_path(ename,'/') enames, empno, mgr from emp
--where empno =empno
start with empno=7698
--start with mgr is null
connect by prior empno = mgr
LEVEL T_ENAME ENAMES EMPNO MGR
1 BLAKE /BLAKE 7698 7839
2 **ALLEN /BLAKE/ALLEN 7499 7698
2 **WARD /BLAKE/WARD 7521 7698
2 **MARTIN /BLAKE/MARTIN 7654 7698
2 **TURNER /BLAKE/TURNER 7844 7698
2 **JAMES /BLAKE/JAMES 7900 7698
Explanation: Here Start with EMPNO=7698 Means, the root node is 7698. Connect BY PRIOR EMPNO=MGR Means--> For the empno=7698 are there any persons under him. IE. Mgr with 7698.
IS MY UNDERSTANDING OF CONNECT BY PRIOR IS CORRECT?
Please correct me if I am wrong.
Thanks,
MK.Yes, you're right
Regards,
Sayan M. -
PHP connection to Oracle basic question.
Forgive me if I am missing a very basic piece of knowledge here.
I have a small local web server I run with Apache 2.2.3 and PHP 5.1.6.
I am working on a project that uses Oracle tables located on the corporate network servers.
These tables are normally maintained by the IT department using TOAD. I'd like for the business process 'owners' to be able to maintain the tables themselves - but the company has limited TOAD licensing and some of the dependencies between tables are not readily apparent (especially to a non-IT person).
Therefore I am trying to develop a simple web app to allow table updates, using PHP to connect to the Oracle tables. The idea is I'll put the app and web server on a USB stick for the designated business person to use. (yeah, I know - seems crazy, but the paperwork to get this all into a true 'production' system is impossible, and I really don't want to have to maintain these tables myself for the rest of my working life)
I've got the basics of the app working through some MySQL tables, now I just need to know how to connect to the 'real' Oracle tables.
Here's what I've gathered from my reading:
I need to download Instant Client and install to my 'server' (on my USB stick)
I need to change PHP.ini to enable the extension for php_oci8.dll
I need to set some environment variables....and here is where I am lost.
Are these environment variables on my web server?
I am running my USB web server on a Windows XP system (as will the business users). But it doesn't make sense to me to set my PC's environment variables, because then I'd need to worry about ever PC the USB stick got used on.
Could someone clear this up for me? I am sure I am just missing something very basic.
Oh, and is there anything else I'm missing?
Thanks for any help!
maryGet it working on a full machine first, and then move to using the USB stick. Refer to Underground PHP and Oracle Manual for standard installation information.
PHP/Apache will need to be able to find the Oracle Instant Client libraries. Normally on WIndows this is done with the PATH environment variable on the machine running the web server.
-- cj
PS your IT department might like the free SQL Developer tool from Oracle instead of TOAD. -
Solaris 10,oracle 10g question- can't connect with non-dba user
Hi
I've installed the Oracle10g suite, enterprise edition ( 10.2.0.1). I've created a database called qa10g, which I can connect to as user 'oracle' once I export the ORACLE_SID and the ORACLE_HOME
export ORACLE_HOME=/oracle/10g2
export ORACLE_SID=qa10g
then I type in the following at it puts me into sqlplus:
$ORACLE_HOME/bin/sqlplus system/system
so that works fine..now whan I try to log in as another user that isn't a member of the dba group, and I export the ORACLE_HOME and ORACLE_SID variables, I can't get in to the database using $ORACLE_HOME/bin/sqlplus system/system, I get the following errors:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
SVR4 Error: 2: No such file or directory
Enter user-name:
BUT, when I put the connector string at the end, I can get in:
$ORACLE_HOME/bin/sqlplus system/system@qa10g
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engin
e options
SQL>
so obviously, it is an enviromnet variable that isn't getting set properly, perhaps even ORACLE_SID=qa10g isn't working properly for the non-dba user ( in this case, the user is called ctronsys)
for the work I need to do on this databse, I need to have the user I select to be able to log into the database with sqlplus commands like the ones listed above, without the connector string added at the end..the SID gets exported first..
any help would be greatly appreciated, I'm a newbie to Oracle!
thanks!
RobThere is a possibility that you could be hitting bug 4516865....
Bug 4516865 "WRONG PERMISSIONS AFTER INSTALLATION IN OH AND SUBSEQUENT DIRECTORIES".
Described in <Note.4516865.8> Bug 4516865 - Wrong permissions after install of 10gR2 (10.2.0.1)
-Ramesh -
Hi, I have following problem
Table TMP contains following data
ID PID
1
2 1
3 2
select t.id
from tmp t
where level=(select max(level)
from tmp t2
connect by prior t2.pid=t2.id
start with t2.id=&ID)
connect by prior t.pid=t.id
start with t.id=&ID
Select returns 1 when ID=3
Is there a way to write select so that it returns value for first node
and value of ID used in select?
Something like
select value_of_ID
,t.id
from tmp t
start with t.id=&ID
so I could use group by on first column (group by value_of_ID)
Following select would not satisfy:
select &ID
,t.id
from tmp t
start with t.id=&IDI would suggest something more straightforward:
select :startnode, id
from tmp
where pid is null
start with id = :startnode
connect by prior pid = id;The WHERE clause will limit the result to just the top level - no need for a subquery or aggregate functions. -
How to use simple SQL instead of Connect By Prior
Currently, I am using "connect by prior" query in the application, but for reason I don�t want to use this connect by query so can any one please tell how does I get the same result by using SQL, I tried this by using procedure but unable to get the same result, specially LEVEL of the tree.
So please tell, how would I get the correct data.
Thanks in advance,
AMIT.Hi,
Whenever you have a question, it helps to post:
(1) The version of Oracle (and any other relevant software) you're using
(2) A little sample data (just enough to show what the problem is) from all the relevant tables
(3) The results you want from that data
(4) Your best attempt so far (formatted) I don't believe the unformated code you posted is what you're really running, since it has a syntax error ("... WHERE START WITH ..."). Please post code that really works with the sample data you posrted.
(5) The full error message (if any), including line number
Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
If you can present your problem using commonly available tables (for example, scott.emp, which contains a hierarchy), then you can omit (2).
Formatted tabular output is okay for (3). Type these 6 characters
{code}
(small letters only, inside curly brackets) before and after the tabular text, to preserve spacing.
As Alex said, why don't you want to use CONNECT BY?
Are you getting the correct results now, but just looking for a different way of getting them?
Depending on your exact requirements, you could write a PLSQL function that mimics LEVEL. Don't expect it to be fast.
Nested Sets is a completely different way of modeling trees.
Some things are much easier with Nested Sets than they are using the Adjacency Model (the parent-child model that uses CONNECT BY).
But some things are much harder with Nested Sets, and LEVEL is one of them. -
Connect by prior (hierarchical query)
Hi All,
Some1 asked me a question which goes like this:
Source
emp_no dep_no
110 10
110 20
110 30
110 40
120 10
130 10
130 20
write a query to achieve the following output from the above source
emp_no dept_no
110 10203040
120 10
130 1020
Now I have come across solutions with 'connect by prior' clauses but I am nt able to understand how oracle is producing that result , Could someone point me to a good article or text that can explain this concept very thoroughly( I have searched on google and got to see many articles but I couldnt able to understand it since these articles were not explaining everything)
Regards
RahulYou can try this:
SQL> ed
Wrote file afiedt.buf
1 SELECT deptno,MAX(TRIM(SUBSTR(SYS_CONNECT_BY_PATH(empid,','),2)))
2 KEEP(DENSE_RANK LAST ORDER BY deptno) FROM
3 (SELECT deptno,empid,ROW_NUMBER() OVER(PARTITION BY deptno ORDER BY deptno) curr,
4 ROW_NUMBER() OVER(PARTITION BY deptno ORDER BY deptno) - 1 prev
5 FROM emp)
6 CONNECT BY PRIOR curr = prev
7 AND deptno = PRIOR deptno
8 START WITH curr = 1
9* group by deptno
SQL> /
DEPTNO MAX(TRIM(SUBSTR(SYS_CONNECT_BY_PATH(EMPID,','),2)))KEEP(DENSE_RANKLASTORDERBYDEPTNO)
10 1,2,3,4
20 5,6,7
SQL> select deptno,empid from emp;
DEPTNO EMPID
10 1
10 2
10 3
10 4
20 5
20 6
20 7
7 rows selected.
SQL> -
Multiple Oracle Configuration Question
We have a typical environment setup. I will explain it below:
Our application works in Online and Offline Mode. For Online mode we connect to Oracle 10g enterprise server and a Local instance of Access and In offline application totally works in Access.
Now we want to move away from Access and have Oracle PE instead just because we want to use stored procedure and same set of code for offline and online processing.
So a typical user machine will have a PE instance and a Oracle Client. Currently we use LDAP.ora for Configuring connections. Now i have few questions
1. How do we ensure that Oracle PE will work when we don't have network connection. Can we have like PE setup with Tnsnames.ORA
2. What can be the smallest possible package for PE.
3. Can I use one client to access both PE and Server databases.
Any help will be highly appreciated.
Thanks in advance.Assuming the "Xcopy installation" refers to using the Windows xcopy command, can you clarify what, exactly, you are installing via xcopy? Are you just using xcopy to copy the ODP.Net bits? Or are you trying to install the Oracle client via that approach?
If you are concerned about support, you would generally want to install everything via the Oracle Universal Installer (barring those very occasional components that don't use the OUI). Oracle generally only supports software installed via the installer because particularly on Windows, there are a number of registry entries that need to get created.
You can certainly do a custom install of the personal edition on the end user machines. There are a few required components that I believe have to be installed (that the installer will take care of). I assume your customization will take the form of a response file to the OUI in order to do a silent install?
Justin -
SQL with connect by prior running for a long time
Hi,
We are using Oracle 10g. Below is a cursor sql which is having performance issues. The pAccountid is being passed from the output of a different cursor. But this cursor sql is running for a long time. Could you please help me in tuning this sql. I believe the subquery with connect by prior is causing the trouble.
The TRXNS is a huge table which is not partitioned. The query is forced to use the index on the accountid of the TRXNS table.
The accountlink table has 20,000 records and the TRXNStrack table has 10,000 records in total.
This sql executes for 200,000 pAccountids and runs for more than 8 hours.
SELECT /*+ INDEX(T TRXNS_ACCOUNTID_NIDX) */ AL.FROMACCOUNTID oldaccountid ,
A.ACCOUNTNUM oldaccountnum,
T.TRXNSID,
T.TRXNSTYPEID,
T.DESCRIPTION ,
T.postdt,
T.TRXNSAMT
FROM
ACCOUNTLINK AL,
TRXNS T,
ACCOUNT A
WHERE AL.TOACCOUNTID IN
(SELECT TOACCOUNTID FROM ACCOUNTLINK START WITH TOACCOUNTID = pAccountid
CONNECT BY PRIOR FROMACCOUNTID = TOACCOUNTID)
AND AL.FROMACCOUNTID = T.ACCOUNTID
AND A.ACCOUNTID = AL.FROMACCOUNTID
AND NOT EXISTS (select 1 from TRXNStrack trck where trck.TRXNSid = t.TRXNSid AND TRXNSTrackReasonid = 1)
AND T.postdt > A.CLOSEDATE
AND T.postdt >= sysdate-2
AND T.postdt <= sysdate;
Create script for trxn table:
CREATE TABLE SP.TRXNS
TRXNSID NUMBER(15) CONSTRAINT "BIN$rpIQEeyLDfbgRAAUT4DEnQ==$0" NOT NULL,
ACCOUNTID NUMBER(15) CONSTRAINT "BIN$rpIQEeyMDfbgRAAUT4DEnQ==$0" NOT NULL,
STATEMENTID NUMBER(15),
TRXNSTYPEID NUMBER(15),
DESCRIPTION VARCHAR2(80 BYTE),
postdt DATE,
TRXNSAMT NUMBER(12,2),
TRXNSREQID NUMBER(15),
LASTUPDATE DATE,
SOURCEID NUMBER(15),
HIDE VARCHAR2(1 BYTE)
TABLESPACE SO_TRXN_DATA
RESULT_CACHE (MODE DEFAULT)
PCTUSED 40
PCTFREE 10
INITRXNS 2
MAXTRXNS 255
STORAGE (
INITIAL 50M
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
FREELISTS 8
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE INDEX SP.TRXNS_ACCOUNTID_NIDX ON SP.TRXNS
(ACCOUNTID, postdt)
LOGGING
TABLESPACE SO_TRXN_INDEX
PCTFREE 10
INITRXNS 2
MAXTRXNS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
NOPARALLEL;
below is the executing plan for this sql taken from toad :
PLAN_ID
TIMESTAMP
OPERATION
OPTIONS
OBJECT_OWNER
OBJECT_NAME
OBJECT_ALIAS
OBJECT_INSTANCE
OBJECT_TYPE
OPTIMIZER
SEARCH_COLUMNS
ID
PARENT_ID
DEPTH
POSITION
COST
CARDINALITY
BYTES
CPU_COST
IO_COST
TEMP_SPACE
ACCESS_PREDICATES
FILTER_PREDICATES
PROJECTION
TIME
QBLOCK_NAME
1121
9/10/2013 3:30
FILTER
1
0
1
1
NOT EXISTS (SELECT 0 FROM "TRXNSTRACK" "TRCK" WHERE "TRXNSTRACKREASONID"=1 AND "TRCK"."TRXNSID"=:B1)
AL."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
SEL$5DA710D3
1121
9/10/2013 3:30
FILTER
2
1
2
1
SYSDATE@!-2<=SYSDATE@!
AL."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
1121
9/10/2013 3:30
NESTED LOOPS
3
2
3
1
(#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
1121
9/10/2013 3:30
NESTED LOOPS
4
3
4
1
5
1
119
3989858
4
(#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A".ROWID[ROWID,10]
1
1121
9/10/2013 3:30
NESTED LOOPS
5
4
5
1
4
1
90
3989690
3
(#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22]
1
1121
9/10/2013 3:30
HASH JOIN
SEMI
6
5
6
1
3
2
54
3989094
2
AL."TOACCOUNTID"="TOACCOUNTID"
(#keys=1) "AL"."FROMACCOUNTID"[NUMBER,22]
1
1121
9/10/2013 3:30
INDEX
FULL SCAN
SP
ACCOUNTLINK_AK1
AL@SEL$1
INDEX (UNIQUE)
ANALYZED
7
6
7
1
1
18
252
107
1
AL."FROMACCOUNTID"[NUMBER,22], "AL"."TOACCOUNTID"[NUMBER,22]
1
SEL$5DA710D3
1121
9/10/2013 3:30
VIEW
SYS
VW_NSO_1
VW_NSO_1@SEL$5DA710D3
11
VIEW
8
6
7
2
2
18
234
107
1
TOACCOUNTID[NUMBER,22]
1
SEL$683B0107
1121
9/10/2013 3:30
CONNECT BY
NO FILTERING WITH START-WITH
9
8
8
1
TOACCOUNTID=PRIOR "FROMACCOUNTID"
TOACCOUNTID=56354162
TOACCOUNTID[NUMBER,22], "FROMACCOUNTID"[NUMBER,22], PRIOR NULL[22], LEVEL[4]
SEL$683B0107
1121
9/10/2013 3:30
INDEX
FULL SCAN
SP
ACCOUNTLINK_AK1
ACCOUNTLINK@SEL$3
INDEX (UNIQUE)
ANALYZED
10
9
9
1
1
18
252
107
1
ACCOUNTLINK.ROWID[ROWID,10], "FROMACCOUNTID"[NUMBER,22], "TOACCOUNTID"[NUMBER,22]
1
SEL$3
1121
9/10/2013 3:30
TABLE ACCESS
BY INDEX ROWID
SP
TRXNS
T@SEL$1
2
TABLE
ANALYZED
11
5
6
2
1
1
63
298
1
T."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22]
1
SEL$5DA710D3
1121
9/10/2013 3:30
INDEX
RANGE SCAN
SP
TRXNS_ACCOUNTID_NIDX
T@SEL$1
INDEX
ANALYZED
2
12
11
7
1
1
1
224
1
AL."FROMACCOUNTID"="T"."ACCOUNTID" AND "T"."POSTDT">=SYSDATE@!-2 AND "T"."POSTDT"<=SYSDATE@!
T.ROWID[ROWID,10], "T"."POSTDT"[DATE,7]
1
SEL$5DA710D3
1121
9/10/2013 3:30
INDEX
UNIQUE SCAN
SP
ACCOUNT_PK
A@SEL$1
INDEX (UNIQUE)
ANALYZED
1
13
4
5
2
1
1
90
1
A."ACCOUNTID"="AL"."FROMACCOUNTID"
A.ROWID[ROWID,10]
1
SEL$5DA710D3
1121
9/10/2013 3:30
TABLE ACCESS
BY INDEX ROWID
SP
ACCOUNT
A@SEL$1
3
TABLE
ANALYZED
14
3
4
2
1
1
29
168
1
A."CLOSEDATE"<SYSDATE@! AND "T"."POSTDT">"A"."CLOSEDATE"
A."ACCOUNTNUM"[VARCHAR2,19]
1
SEL$5DA710D3
1121
9/10/2013 3:30
INDEX
RANGE SCAN
SP
TRXNSTRACK_TRXNSID_NIDX
TRCK@SEL$6
INDEX
ANALYZED
2
15
1
2
2
1
1
10
73
1
TRCK."TRXNSID"=:B1 AND "TRXNSTRACKREASONID"=1
TRCK."TRXNSID"[NUMBER,22], "TRXNSTRACKREASONID"[NUMBER,22]
1
SEL$6
Please help me in debugging this thanks!Hi,
Thanks for your thought on this subject. Below is the trace info that I got from the DBA
SQL ID: d0x879qx2zgtz Plan Hash: 4036333519
SELECT /*+ INDEX(T TRXNS_ACCOUNTID_NIDX) */ AL.FROMACCOUNTID OLDACCOUNTID ,
A.ACCOUNTNUM OLDACCOUNTNUM, T.TRXNSID, T.TRXNSTYPEID, T.DESCRIPTION ,
T.POSTDT, T.TRXNSAMT
FROM
ACCOUNTLINK AL, TRXNS T, ACCOUNT A WHERE AL.TOACCOUNTID IN (SELECT
TOACCOUNTID FROM ACCOUNTLINK START WITH TOACCOUNTID = :B3 CONNECT BY PRIOR
FROMACCOUNTID = TOACCOUNTID) AND AL.FROMACCOUNTID = T.ACCOUNTID AND
A.ACCOUNTID = AL.FROMACCOUNTID AND NOT EXISTS (SELECT 1 FROM TRXNSTRACK
TRCK WHERE TRCK.TRXNSID = T.TRXNSID AND TRXNSTRACKREASONID = :B4 ) AND
T.POSTDT > A.CLOSEDATE AND T.POSTDT >= :B2 AND T.POSTDT <= :B1
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 17160 2.10 1.87 0 0 0 0
Fetch 17160 7354.61 7390.86 169408 5569856 883366791 0
total 34320 7356.71 7392.74 169408 5569856 883366791 0
Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: 38 (recursive depth: 1)
SQL ID: gs89hpavb4cts Plan Hash: 3415795327
SELECT A.ACCOUNTID, C.MEMBERID, A.PROGRAMID, A.ACCOUNTNUM
FROM
CUSTOMER C, CUSTOMERACCOUNT CA, ACCOUNT A, PROGRAMPARAMVALUE PPV,
BATCHPROCESSPROGRAM BP WHERE A.PROGRAMID = BP.PROGRAMID AND A.PROGRAMID =
PPV.PROGRAMID AND A.ACCOUNTID = CA.ACCOUNTID AND CA.PERSONID = C.PERSONID
AND PPV.PARAMID = :B2 AND PPV.VALUE = 'Y' AND BP.PROCESSID = :B1 AND BP.RUN
= 'Y' AND A.ACCOUNTTYPEID = 4 AND A.ACCOUNTSTATUSID = 1 AND C.MEMBERID IS
NOT NULL
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 172 13.14 115.34 80826 278650 0 17200
total 172 13.14 115.34 80826 278650 0 17200
Misses in library cache during parse: 0
Parsing user id: 38 (recursive depth: 1)
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 0 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 17160 2.10 1.87 0 0 0 0
Fetch 17332 7367.75 7506.21 250234 5848506 883366791 17200
total 34492 7369.85 7508.09 250234 5848506 883366791 17200
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
Trace file: svoprod_ora_12346.trc
Trace file compatibility: 11.1.0.7
Sort options: default
1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
66499 lines in trace file.
7516 elapsed seconds in trace file.
Maybe you are looking for
-
Cannot print pdf files after downloading version 8.1.2
windows xp pro hp photsmart all in one printer 512 ram
-
these songs were bought using my old iPhone/on an old computer so it isn't possible for me to copy the files to another device. how do i find them?
-
Low clock speed with amd 3400+
hi all, i have an amd 3400+ 64bit and i have downloaded multiple hardware information programs which state that my CPU clock should be between 2.8ghz - 3 ghz with this type of processor, however i only have 2.1 ghz.I have searched the bios and have
-
Convert complex PDF file into Excel
I'm trying to convert a PDF file ( 510 pages), consisting of horizontal and vertical charts into excel. The first few pages were fine but the rest were messed up. Every number was displayed in the wrong collumn. Could anyone help? I'm happy to send i
-
How to redefine function keys in forms 10g
i want to redefine function keys, for example i want to open LOV by pressing F9 not Ctl + L in forms 10g. can any one help me. zulfiqar