Re: How to get all of parent path (including itself) for a specified path on Linux or how to get all of substring (including itself) for a string on Oracle SQL?

From: Ghassan Salem <salem.ghassan_at_gmail.com>
Date: Mon, 13 Mar 2023 16:19:26 +0100
Message-ID: <CALEzESgNkzjk2dcSb3a9ud+dyhwZDZ3YV1HqanuBQ+542vGxPw_at_mail.gmail.com>



In sql
select nvl(substr(paths,1, instr(paths,'/',1,level+1)-1),paths) from (select '/oracle/base/product/19c/dbhome_1' paths from dual) connect by level<=regexp_count(paths,'/') ; (gives the same output)

On Mon, Mar 13, 2023 at 4:15 PM Maxim <mdemenko_at_gmail.com> wrote:

> variation of the bash fork bomb ;-)
>
> :() { [[ ! -z $1 ]] && echo $1 && : ${1%/*}; } ; :
> /oracle/base/product/19c/dbhome_1|sort
> /oracle
> /oracle/base
> /oracle/base/product
> /oracle/base/product/19c
> /oracle/base/product/19c/dbhome_1
>
> Regards
>
> Maxim
>
> On Mon, Mar 13, 2023 at 3:28 PM Mladen Gogala <gogala.mladen_at_gmail.com>
> wrote:
>
>> On 3/13/23 01:49, Quanwen Zhao wrote:
>>
>> Hello listeners :-),
>>
>> I've an requirement getting all of parent path (including itself) for a
>> specified path on Linux or getting all of substring (including itself) for
>> a string on Oracle SQL?
>>
>> such as, the path is "/home/oracle/arch", the desired output is:
>>
>> /home/oracle/arch
>>> /home/oracle
>>> /home
>>> /
>>
>>
>> or I've created a test table.
>>
>> TEST_at_orcl>create table test1 (arch_loc varchar2(50));
>>> Table created.
>>
>>
>> TEST_at_orcl>insert into test1 values ('/home/oracle/arch');
>>> 1 row created.
>>
>>
>> TEST_at_orcl>commit;
>>> Commit complete.
>>
>>
>> TEST_at_orcl>select * from test1;
>>> ARCH_LOC
>>> --------------------------------------------------
>>> /home/oracle/arch
>>
>>
>> Whatever, using the SHELL or Oracle SQL to get the same output. Please
>> help me finish it, thanks beforehand!
>>
>> Best Regards
>> Quanwen Zhao
>>
>>
>> I would use something like this:
>>
>> !/usr/bin/perl
>> my _at_MD=split ('/',$ARGV[0]);
>> my $output='';
>> foreach (_at_MD) {
>> $output .= "/$_";
>> $output=~s/\/\//\//;
>> print "$output\n";
>> }
>>
>> This works:
>>
>> [mgogala_at_umajor scripts]$ /tmp/ttt '/oracle/base/product/19c/dbhome_1'
>> /
>> /oracle
>> /oracle/base
>> /oracle/base/product
>> /oracle/base/product/19c
>> /oracle/base/product/19c/dbhome_1
>>
>> You can use PL/SQL regex functions to do the same in PL/SQL.
>>
>> --
>> Mladen Gogala
>> Database Consultant
>> Tel: (347) 321-1217https://dbwhisperer.wordpress.com
>>
>>

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Mar 13 2023 - 16:19:26 CET

Original text of this message