Send Parameter to SQL

Discussion in 'Perl Misc' started by Gomer, Jan 31, 2005.

  1. Gomer

    Gomer Guest

    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
     
    Gomer, Jan 31, 2005
    #1
    1. Advertising

  2. Gomer <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 1, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,127
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  2. Nathan Sokalski
    Replies:
    3
    Views:
    1,985
    Larry Lard
    Nov 23, 2005
  3. ecoolone
    Replies:
    0
    Views:
    798
    ecoolone
    Jan 3, 2008
  4. JT
    Replies:
    1
    Views:
    126
    Bob Barrows [MVP]
    Sep 27, 2005
  5. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    238
    Chris Reay
    Nov 4, 2003
Loading...

Share This Page