oracle - How to use a Perl variable in a SQL script (using backticks) -
i have seen various examples unable use dbi. how use perl variable in external sql script? example code in perl script want be:
$text = 'germany'; @sql_output = `sqlplus -s user/pass\@databasename <<! @/pathtofile/test.sql; quit; !`; print @sql_output;
the sql script be:
select distinct city customers country = '$text'
(just example, i'm using code comes w3schools.com sql tutorial http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_distinct)
an example found through searching had:
@/pathtofile/test.sql $text;
but did not work when tried code. correct way incorporate perl variable external sql script?
- define replacement variable(s)
- use them in here doc based on content of test.sql
- save test.sql
- execute backtick command
or
- if want learn basic sql: install dbms gui allows interactive/ad hoc queries (eg sqlite/sqliteman/sqlite browser plugin, mysql/mysqlworkbench, access, oo/lo base, ...)
- if want work oracle: concentrate on complete/working install (which includes dbd:oracle if scripting language perl)
Comments
Post a Comment