Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Filtered hierarchical data - previous available ancestor?

paul zipJul 10 2013 — edited Jul 10 2013

I'm trying to come up with a solution to a problem relating to hierarchical data and the concept of nearest available ancestor - my platform is 10gR2 and 11gR2.  I am given some hierarchical data (in its simplest form it is in form ID, NAME, PARENT_ID, where PARENT_ID links back to ID).

For example:

with qryData as (

  select 1 as ID, 'Bert' as NAME, to_number(null) as PARENT_ID from dual union

  select 2 as ID, 'Mark' ,   1 from dual union

  select 3 as ID, 'Brenda' , 1 from dual union

  select 4 as ID, 'Mike' ,   3 from dual union

  select 5 as ID, 'Steve' ,  4 from dual union

  select 6 as ID, 'John' ,   2 from dual union

  select 7 as ID, 'Jo' ,     6 from dual union

  select 8 as ID, 'Jim' ,    2 from dual union

  select 9 as ID, 'Jane' ,   7 from dual           

)

select q.*, sys_connect_by_path(ID, '/') ID_PATH

from qryData q

start with parent_id is null

connect by prior ID = PARENT_ID

/

        ID NAME    PARENT_ID ID_PATH

---------- ------ ---------- ----------------

         1 Bert              /1

         2 Mark            1 /1/2

         6 John            2 /1/2/6

         7 Jo              6 /1/2/6/7

         9 Jane            7 /1/2/6/7/9

         8 Jim             2 /1/2/8

         3 Brenda          1 /1/3

         4 Mike            3 /1/3/4

         5 Steve           4 /1/3/4/5

In reality this dataset can be several thousand rows with tens of nesting levels, multiple start nodes with no parent but most importantly often filtered, so certain arbitrary rows are missing.  When this happens I need to find the nearest available ancestor that appears in the list. "Nearest available ancestor" is closest ancestor relation in your family tree that still exists in the filtered list found starting from parent, then contuniing upwards to grandparent, great-grandparent .... nth great grandparent until one ancestor is found.


For example:

        ID NAME    PARENT_ID ID_PATH       AVAIL_ANCESTOR_ID

---------- ------ ---------- ------------- -----------------

         1 Bert              /1             

         6 John            2 /1/2/6        1

         8 Jim             2 /1/2/8        1

         9 Jane            7 /1/2/6/7/9    6

         3 Brenda          1 /1/3          1

         5 Steve           4 /1/3/4/5      3

For example.  Who is Steve's nearest available ancestor in the filtered list?

Steve's family tree is : /Bert/Brenda/Mike/Steve

Mike (ID = 4) isn't in the filtered list, so we move onto Brenda, who is.  Brenda, ID = 3, So ANCESTOR_ID = 3

I do have access to the original table, so can join the filtered list back to the full table, I can also ask for other columns (such as ROWID, ROWNUM, LEVEL, SYS_CONNECT_ROOT) to be included in the filtered set.  I've tried various approaches to achieve this, but all seem to be quite poor in performance (ID and PARENT_ID columns are indexed where appropriate) or don't quite give the correct result, such as...

1. Parsing the ID_PATH and treewalking based on that and joining back to the list...

  select distinct CUSTOMER_ID, regexp_substr( ID_PATH, '[^/]+', 1, level) as ANCESTOR_ID

  from qryData

  connect by regexp_substr( ID_PATH, '[^/]+', 1, level)  is not null

2. Anti-joining back to full list to identify missing items , then treewalking for those.

3. Writing a function which treewalks back.

It's quite a challenging problem, so can anyone think of a solution which performs well?  Ideally I'm trying to find a SQL based solution?

This post has been answered by Frank Kulash on Jul 10 2013
Jump to Answer

Comments

Christian.Shay -Oracle

That error is very generic that just means "things are really messed up!"

If you do not see OracleServiceXE, then you have your answer - the install failed.

Did you set ORACLE_HOME? Don't set that on Windows. You shouldn't have to set any environment variable after install.

Possibly the PATH did not get set to the new Oracle home.

SullivanK

Thanks for your reply Christian,

Yeah I figured something went wrong :-) , but I don't even know where to start looking. I didn't set any environment variables, but I was expecting to see it already set, which was not the case.

So we have services missing and an incorrect path set? Mind giving me some debugging tips? i have no idea what to check and can't really find anything.

Christian.Shay -Oracle

If you do not see OracleServiceXE, there is no hope for it working in the current state. That is the Oracle database software.

When you installed it, did you use the user interface version of the install (as opposed to command line)? If so, did it show you a final screen with connection strings (similar to what is shown in chapter 5 of the documentation)?

Is there anything unusual about your Windows 10? Are the drives involved local drives? Is it an up to date version of windows 10?

If you are using a domain user, can you try creating a local administrator user and log in and install with that?

SullivanK

Do you mean this?

Capture.PNG

Then yes.

Local drive yes, I have only one, no partitions, if thats an issue too. Also up to date version of windows.

Tried with no differing results:

- creating another admin and installing with that one

- installing 11 xe, uninstalling that one and then reinstalling 18

- downloading 18xe again and installing that version.

Do you think installing from command line would make a difference?

Gaz in Oz

That screenshot suggests it did install.

What user did you use for the install, Adminsistrator?

What user are you looged in as when you try and view Services?

...when you say "I installed 18 XE on windows 10, but get this error when I try to login via cmd." show how you tried to login via cmd.

SullivanK

Thanks Gaz, I do realize that the screenshot suggests it did install... It's the first line on screen after all.

Yes I installed it as an administrator, even tried making another admin as Christian suggested. When i view Services, I tried logging in as the administrators (both of them, only two users on my laptop).

logging in via cmd is done via the usual:

"sqlplus /nolog" and then conn sys as sysdba

or "sqlplus / as sysdba"

or all other ways of logging in I could find on google, but I sure can reinstall it and paste a screenshot.

Christian.Shay -Oracle

Just to confirm again, you do NOT have OracleServiceXE in the services Window?

If not, the installation failed and we will need to find out why. I am talking to some of the engineers to see what the next step is.

SullivanK

yeah exactly, I do NOT have it.

Services.jpeg

Maybe this screenshot helps?

Christian.Shay -Oracle

Ok, thanks for your patience. Stand by.. we will probably have to look at your log files to figure out what is going wrong. I will get back soon.

SullivanK

Thanks Christan. It's for personal tinkering at home and I can't really get to my laptop right now so no absolute hurry. Asked my DBA friend to take a whack at it after work too, hopefully he will get it working. If so, I will post update and solution ofcourse.

SullivanK
Answer

Guess we found it.

My home laptop is Win Home edition.

https://docs.oracle.com/en/database/oracle/oracle-database/18/ntdbi/oracle-database-software-requirements.html#GUID-CEF2…  says that is not supported, only Pro, Enterprise, and Education editions so I'm out of luck.

Would be nice if the installer could check this as well.

Thanks for your help Christian.

Marked as Answer by SullivanK · Sep 27 2020
SBiedrzycki

I'm not entirely sure that the Windows edition is related.  I've actually spent the day wrestling with installing the XE with no luck.  I get the same error but I'm on Win 10 Pro.  Notable difference in my case is that I don't even have the recovery service even.  Only service running is the TNS listener. 

I also tried working around the problem by directly configuring a new DB with DBCA but have brickwalled at another issue with error [DBT-50000] Unable to check for available memory. 

Otherwise, my installation approach was the same.  Ran Setup as Administrator from my normal user account which is part of the Administrators group.  Installation completed successfully.  Same error when attempting to login through sqlplus.  I had no prior Oracle installations on the system.  Problem was reproducible through uninstall, reinstall with restarts in between to ensure cleanup.

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 7 2013
Added on Jul 10 2013
14 comments
2,551 views