Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Send Parameter to SQL

Reply
Thread Tools

Send Parameter to SQL

 
 
Gomer
Guest
Posts: n/a
 
      01-31-2005
How can I send a parameter I read inside of a PERL script to a SQL
script.
For example, I have the following:

chomp ($login_name = uc(<STDIN>));

Now, I want to send that $login_name to a SQL script. I'm doing
something like the following:

$sql = "declare \n";
$sql .= " v_new_pswd varchar2(20); \n";
$sql .= "begin \n";
$sql .= " v_new_pswd := db_login.crypt_passwd('NEW_PASSWORD'); \n";
$sql .= " update table set pswd = v_new_pswd where user_id =
'$login_name'; \n";
$sql .= "end; \n";
$sql .= "/ \n";
$sql .= "commit; \n";
@output = run_sql_query ($login,$password,$sql);

I'm using some libraries that came with my system so I know that
everything is working correctly except that the login_name isn't being
passed.
How can I format the login_name so it's correctly interpreted in
my SQL script?

Thanks,
Gomer

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      02-01-2005
Gomer <(E-Mail Removed)> wrote:
> How can I send a parameter I read inside of a PERL script to a SQL
> script.
> For example, I have the following:
>
> chomp ($login_name = uc(<STDIN>));
>
> Now, I want to send that $login_name to a SQL script. I'm doing
> something like the following:
>
> $sql = "declare \n";
> $sql .= " v_new_pswd varchar2(20); \n";
> $sql .= "begin \n";
> $sql .= " v_new_pswd := db_login.crypt_passwd('NEW_PASSWORD'); \n";
> $sql .= " update table set pswd = v_new_pswd where user_id =
> '$login_name'; \n";
> $sql .= "end; \n";
> $sql .= "/ \n";
> $sql .= "commit; \n";



Did you try adding this statement at this point?

print $sql;

You should use a "here-document" if you want to see what
you are writing:

my $sql =<<ENDSQL;
declare
v_new_pswd varchar2(20);
begin
v_new_pswd := db_login.crypt_passwd('NEW_PASSWORD');
update table set pswd = v_new_pswd where user_id = '$login_name';
end;
/
commit;
ENDSQL


Does the same thing as your code, but *looks like* what
you are constructing.


> @output = run_sql_query ($login,$password,$sql);
>
> I'm using some libraries that came with my system so I know that
> everything is working correctly except that the login_name isn't being
> passed.



How does run_sql_query() indicate errors?

No Perl there.


> How can I format the login_name so it's correctly interpreted in
> my SQL script?



That depends on how an "SQL script" wants it formatted. Looks OK to me...

No Perl there either.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
without declare parameter [double square(parameter)] return 0 in main WanHongbin@gmail.com C Programming 5 10-01-2008 03:31 AM
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
Using declaration inside first template parameter as default valuefor second template parameter. Stuart Redmann C++ 5 12-14-2007 08:42 AM
Parameter List / Parameter Block / Anything patterns... mast2as@yahoo.com C++ 4 03-29-2007 09:37 PM
send batch of sql statements to sql server JT ASP General 1 09-27-2005 10:07 PM



Advertisments