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
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@xxxxxxxxxx : POWERING TRANSFORMATION
------------------------------ *From:* Stefan Knecht [mailto:knecht.stefan@xxxxxxxxx] *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@xxxxxxxxxx> 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@xxxxxxxxxx > : POWERING TRANSFORMATION > >