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: Quanwen Zhao <quanwenzhao_at_gmail.com>
Date: Tue, 14 Mar 2023 09:38:06 +0800
Message-ID: <CABpiuuQRfq7uaphS1Dxu_LwrdLdsKvRDB0U9nAnaaSs91ooN4A_at_mail.gmail.com>



Thanks to everyone for giving me the very nice solution. I'll try it later. 🙏🤘😊.

Ghassan Salem <salem.ghassan_at_gmail.com> 于2023年3月13日周一 23:20写道:

> 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 Tue Mar 14 2023 - 02:38:06 CET

Original text of this message