Send Parameter to SQL

G

Gomer

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
 
T

Tad McClellan

Gomer said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top