如何将参数传递给SQL脚本? [英] How can i pass parameter to sql script?
问题描述
CREATE TABLE DMS_POP_WKLY_REFRESH_20100201 NOLOGGING PARALLEL AS
SELECT wk.*,bbc.distance_km ,NVL(bbc.tactical_broadband_offer,0) tactical_broadband_offer ,
sel.tactical_select_executive_flag,
sel.agent_name,
res.DMS_RESIGN_CAMPAIGN_CODE,
pclub.tactical_select_flag
FROM spineowner.pop_wkly_refresh_20100201 wk,
dms_bb_coverage_102009 bbc,
dms_select_executive_group sel,
DMS_RESIGN_CAMPAIGN_26052009 res,
DMS_PRIORITY_CLUB pclub
WHERE wk.mpn = bbc.mpn(+)
AND wk.mpn = sel.mpn (+)
AND wk.mpn = res.mpn (+)
AND wk.mpn = pclub.mpn (+)
vijay.sql(上面的sql脚本的名称)
vijay.sql ( name given to above sql script)
我如何在SQL脚本中传递20100201的参数,每次此日期格式时我都需要更改. 我如何调用此sql脚本并通过传递日期作为参数在unix中运行它.因此应该在每次运行中修改脚本中的日期
How can i pass a parameter for 20100201 in side the sql script, I need to change every time this date format. how can i call this sql script and run it in unix by passing date as parameter. so that date in the script should be modified in every run
请帮助我.
推荐答案
SQL * Plus使用& 1,& 2 ...& n访问参数.
SQL*Plus uses &1, &2... &n to access the parameters.
假设您具有以下脚本test.sql
:
SET SERVEROUTPUT ON
SPOOL test.log
EXEC dbms_output.put_line('&1 &2');
SPOOL off
例如,您可以像这样调用此脚本:
you could call this script like this for example:
$ sqlplus login/pw @test Hello World!
在UNIX脚本中,您通常会这样调用SQL脚本:
In a UNIX script you would usually call a SQL script like this:
sqlplus /nolog << EOF
connect user/password@db
@test.sql Hello World!
exit
EOF
,以便您的登录名/密码在其他会话的ps
so that your login/password won't be visible with another session's ps
这篇关于如何将参数传递给SQL脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!