<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Call sqlplus with exec command FROM PERL in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888162#M845407</link>
    <description>one problem I see, unless I'm losing it is your "here" doc is looking for OEF and you end it with EOF. &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 25 Feb 2005 17:09:06 GMT</pubDate>
    <dc:creator>Marvin Strong</dc:creator>
    <dc:date>2005-02-25T17:09:06Z</dc:date>
    <item>
      <title>Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888161#M845406</link>
      <description>Hi gurus,&lt;BR /&gt;&lt;BR /&gt;I want to call sqlplus from Perl, but passing parameters, I do not want use DBI, it's a simple call.. What shoud I correct?&lt;BR /&gt;&lt;BR /&gt;Notes:&lt;BR /&gt;1. Remember, Oracle end each command with ';' like perl.&lt;BR /&gt;2. I want to mix variables, inside oracle command put perl variables, see below.&lt;BR /&gt;3. The output from sql command is redirected to a file out_file, see below.&lt;BR /&gt;&lt;BR /&gt;For each line en the file, call sqlplus and execute one command but passing variables from perl.&lt;BR /&gt;&lt;BR /&gt;If you think... it's better with unix shell rather than perl, I accepted too.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;open(INFILE,"salida");&lt;BR /&gt;while (&lt;INFILE&gt;) {&lt;BR /&gt;   $user=~substr($_,1,20);&lt;BR /&gt;   $vday=~substr($_,22,8);&lt;BR /&gt;   $vtime=~substr($_,32,8);&lt;BR /&gt;   exec 'sqlplus',&lt;BR /&gt;   ' &amp;lt;&amp;lt; OEF&lt;BR /&gt;     connect system/manager;&lt;BR /&gt;     select username,status&lt;BR /&gt;       from v$session&lt;BR /&gt;      where username = $user&lt;BR /&gt;        and logon_time = $vday$time;&lt;BR /&gt;    EOF&lt;BR /&gt;   ' &amp;gt; out_file.txt;&lt;BR /&gt;}&lt;BR /&gt;close(INFILE);&lt;BR /&gt;&lt;BR /&gt;Thanks for your time...&lt;/INFILE&gt;</description>
      <pubDate>Fri, 25 Feb 2005 16:26:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888161#M845406</guid>
      <dc:creator>GerGon</dc:creator>
      <dc:date>2005-02-25T16:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888162#M845407</link>
      <description>one problem I see, unless I'm losing it is your "here" doc is looking for OEF and you end it with EOF. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Feb 2005 17:09:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888162#M845407</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2005-02-25T17:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888163#M845408</link>
      <description>wish there was an edit. &lt;BR /&gt;&lt;BR /&gt;here is how I am doing it in a ksh. &lt;BR /&gt;&lt;BR /&gt;sqlplus /nolog &amp;lt;&amp;lt; eof&lt;BR /&gt;connect ${usr}&lt;BR /&gt;column file_name format a55&lt;BR /&gt;column member format a55&lt;BR /&gt;set pagesize 0&lt;BR /&gt;select file_name from dba_data_files&lt;BR /&gt;order by file_name&lt;BR /&gt;/&lt;BR /&gt;select member from v\$logfile&lt;BR /&gt;order by member&lt;BR /&gt;/&lt;BR /&gt;exit&lt;BR /&gt;eof</description>
      <pubDate>Fri, 25 Feb 2005 17:12:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888163#M845408</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2005-02-25T17:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888164#M845409</link>
      <description>For such simple sqplus 'one liner' I would use something like:&lt;BR /&gt;&lt;BR /&gt;$username = "SAPLNX";&lt;BR /&gt;$command = "select status from v\\\$session where username = '${username}';";&lt;BR /&gt;foreach (`echo "$command" | sqlplus -s "/ as sysdba"`) {&lt;BR /&gt;  print "-- $_";&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;For somewhat more elaborate work I would create an sqlplus script that takes params.&lt;BR /&gt;&lt;BR /&gt;For even more advanced work I'd 'OPEN' a sqlplus command: open (SQL ,"sqlplus..|")&lt;BR /&gt;Redirect output to a file and feed commands.&lt;BR /&gt;Later parse the file.&lt;BR /&gt;&lt;BR /&gt;Or... generate a sqplus script and open a sqplus session for output (backticks again?)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;For full control of input and output you'll need a fork and wait and stuff.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 26 Feb 2005 08:56:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888164#M845409</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-26T08:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888165#M845410</link>
      <description>&lt;BR /&gt;On re-visit I noticed that you intend to invoke sqlplus once for each line in 'salida'. That's rather clumsy.&lt;BR /&gt;&lt;BR /&gt;Why not have SQLplus/Oracle do it all?&lt;BR /&gt;Define an EXTERNAL TABLE over 'salida' and just JOIN with SQL statements.&lt;BR /&gt;&lt;BR /&gt;Here is a simplified example:&lt;BR /&gt;First...&lt;BR /&gt;&lt;BR /&gt;CREATE OR REPLACE DIRECTORY salida_dir AS '/tmp';&lt;BR /&gt;CREATE TABLE salida_exernal (username VARCHAR (20))&lt;BR /&gt;ORGANIZATION EXTERNAL (&lt;BR /&gt;DEFAULT DIRECTORY salida_dir&lt;BR /&gt;ACCESS PARAMETERS ( records delimited by newline)&lt;BR /&gt;LOCATION ('salida.dat')&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;Next just execute the appropriate procedure over the tables:&lt;BR /&gt;&lt;BR /&gt;cat &amp;gt; /tmp/test.sql&lt;BR /&gt;select status, s.username &lt;BR /&gt;from v$session s, salida_external e &lt;BR /&gt;where s.username = e.username;&lt;BR /&gt;:&lt;BR /&gt;order..&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;back to perl (or shell)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$foreach (`sqlplus -s "/ as sysdba" @/tmp/test.sql`){&lt;BR /&gt;... your result processing ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This way you can create and maintain the more or less complex join in a seperate .sql file. You could of course also stick it in a string as per earlier reply.&lt;BR /&gt;&lt;BR /&gt;You'll have to create the external table definition to match the data of course. I did not test this, but I think the actuall definition you need is something like:&lt;BR /&gt;&lt;BR /&gt;CREATE TABLE salida_exernal (&lt;BR /&gt;username VARCHAR (20),&lt;BR /&gt;fill_1 CHAR (1),&lt;BR /&gt;vday VARCHAR (8),&lt;BR /&gt;fill_2 CHAR (1),&lt;BR /&gt;vtime VARCHAR (8))&lt;BR /&gt;:&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein.</description>
      <pubDate>Sat, 26 Feb 2005 16:39:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888165#M845410</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-26T16:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888166#M845411</link>
      <description>A couple of thoughts...&lt;BR /&gt;&lt;BR /&gt;I like to "hide" the login information ("system/manager") -- preferably by prompting the user.  Next choice is creating an Oracle account with just enough permissions to do what's needed.  Last choice, and I've had to do this, is create a file that's only readable by the user that runs the script and embed the information there.  &lt;BR /&gt;&lt;BR /&gt;As to shell vs Perl -- I guess part of that depends on other sysadmins at your site.  If they know Perl, more power to you.  If they don't, shell might be better so that you're not the only one who knows how to do it.  &lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Mic</description>
      <pubDate>Sat, 26 Feb 2005 18:48:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888166#M845411</guid>
      <dc:creator>Mic V.</dc:creator>
      <dc:date>2005-02-26T18:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888167#M845412</link>
      <description>&lt;BR /&gt;Also... always consider turning things around :-)&lt;BR /&gt;Given that the query action desired is trivial,&lt;BR /&gt;you might just want to do it all in perl. Untested:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;$command = "select username, logon_time, status from v\\\$session;" &lt;BR /&gt;foreach (`echo "$command" | sqlplus -s "/ as sysdba"`) {&lt;BR /&gt;($user,$logon,$status} = split;&lt;BR /&gt;$session{$logon.$user} = $status;&lt;BR /&gt;}&lt;BR /&gt;open (INFILE,"&lt;SALIDA&gt;&lt;/SALIDA&gt;open (OUTFILE,"&amp;gt;out_file.txt) or die "xxx";&lt;BR /&gt;while (&lt;INFILE&gt;) {&lt;BR /&gt;$user=~substr($_,1,20);&lt;BR /&gt;$vday=~substr($_,22,8);&lt;BR /&gt;$vtime=~substr($_,32,8);&lt;BR /&gt;$status = $session{$vday.$vtime.$user};&lt;BR /&gt;print OUT_FILE "$user $vday $vtime $status\n" if $status;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;grins,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;/INFILE&gt;</description>
      <pubDate>Sat, 26 Feb 2005 21:11:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888167#M845412</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-26T21:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Call sqlplus with exec command FROM PERL</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888168#M845413</link>
      <description>Thanks a lot everybody that has participated here..&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Feb 2005 08:51:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/call-sqlplus-with-exec-command-from-perl/m-p/4888168#M845413</guid>
      <dc:creator>GerGon</dc:creator>
      <dc:date>2005-02-28T08:51:29Z</dc:date>
    </item>
  </channel>
</rss>

