Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Java Question

Re: Java Question

From: Stefan Knecht <knecht.stefan_at_gmail.com>
Date: Fri, 20 Oct 2006 11:16:56 +0200
Message-ID: <486b2b610610200216k76b7c7d0w6e374c88082358e2@mail.gmail.com>


There's several ways to do this... If you're on 9i, you could use owa_pattern package (lets you match strings with regular expressions) - or in 10g, you have built-in regexp functionality with regexp_instr, regexp_substr etc. You could also just split the string (if you know a "record separator" that is always the same) and use something like asktom's str2tbl function to get the 4th entry.

Stefan

On 10/19/06, Richard J. Goulet <rgoulet_at_kanbay.com> wrote:
>
> Stephan,
>
> I realize that, and was tinkering with the code. I do have it
> returning a string now, but still how do you parse out the 4th value when
> your not sure where in the string it is or how long it is? I can do that in
> C easily, but that's not 21st century programming now is it.
>
>
>
> Dick Goulet, Senior Oracle DBA
>
> 45 Bartlett St Marlborough, Ma 01752, USA
> *Tel.:* 508.573.1978 |F*ax: * 508.229.2019 | Cell:508.742.5795
>
> RGoulet_at_kanbay.com
> : POWERING TRANSFORMATION
>
>
> ------------------------------
> *From:* Stefan Knecht [mailto:knecht.stefan_at_gmail.com]
> *Sent:* Thursday, October 19, 2006 1:26 PM
> *To:* Richard J. Goulet
> *Cc:* oracle-l
> *Subject:* Re: Java Question
>
> Well,
>
> "your" java code only returns the return code of the os command execution.
> If you want to return something else (like the output of the command) -
> you'll have to adjust your java code to do this. You're only seeing the
> output in the console because dbms_java.set_output has been called.
> Otherwise you'd find the output in a tracefile in user_dump_dest.
>
> PL/SQL can only "see" what the java code returns, it can't see what's
> printed to STDOUT or STDERR on unix.
>
> Stefan
>
> On 10/19/06, Richard J. Goulet <rgoulet_at_kanbay.com> wrote:
> >
> > First off, I'm pretty novice at Java so this could be a bit
> > rudimentary but please bear with me. I've found and adapted the Java
> > procedure on Ask Tom to run OS commands on Unix. Works rather well from
> > Sql*Plus, but I want to bury calls to the procedure into some procedural
> > code that needs to make decisions based on the output. The code I've got
> > looks like:
> >
> > create or replace and compile
> > java source named "Util" as
> > import java.io.*;
> > import java.lang.*;
> > public class Util extends Object
> > {
> > public static int RunThis(String args)
> > { Runtime rt = Runtime.getRuntime();
> > int rc = 0;
> > try
> > { Process p = rt.exec(args);
> > int bufSize = 4096;
> > BufferedInputStream bis = new BufferedInputStream(
> > p.getInputStream(), bufSize);
> > int len;
> > byte buffer[] = new byte[bufSize];
> > // Echo back what the program spit out
> > while ((len = bis.read(buffer, 0, bufSize)) != -1)
> > System.out.write(buffer, 0, len);
> > rc = p.waitFor();
> > }
> > catch (Exception e)
> > { e.printStackTrace();
> > rc = -1;
> > }
> > finally
> > { return rc;
> > }
> > }
> > }
> > /
> > In Sql*plus I get this displayed on the screen:
> >
> > Filesystem kbytes used avail capacity Mounted on
> > /dev/md/dsk/d2 12397228 3936915 8336341 33% /
> >
> > Now the procedure does return a 0, meaning that the Java executed
> > normally and I am passing a 'df -k <mount_point>' to the prodecure
> > (Solaris9). What I'd like the procedure to return is the available disk
> > space remaining or 8336341. Anybody got any ideas??
> >
> >
> >
> > Dick Goulet, Senior Oracle DBA
> >
> > 45 Bartlett St Marlborough, Ma 01752, USA
> > *Tel.:* 508.573.1978 |F*ax: * 508.229.2019 | Cell:508.742.5795
> >
> > RGoulet_at_kanbay.com
> > : POWERING TRANSFORMATION
> >
> >
>
>


--
http://www.freelists.org/webpage/oracle-l


klogo.gif klogo.gif
Received on Fri Oct 20 2006 - 04:16:56 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US