質問

Could some one explain in the following TCL source code:

set sql "SELECT PROD.KEY || ' {' || PARAMETERS || '}' \
         FROM PRV_PROD_MAPPING PROD \
         WHERE PROD.SERVICE_ID = :service_id \
         AND (PROD.KEY || ' ' || PROD.KEY_VAL) \
         IN (:keys) "

what :service_id and :keys mean. Could I see the values behind by simple trace. How could I find where these vars are defined?

Thanks in advance!

役に立ちましたか?

解決 4

I've done it using traces:

sys.DBMS_SYSTEM.SET_EV(n_sid, n_serial, 10046, 12, '');
DBMS_OUTPUT.put_line('Trace started: ' || to_char(SYSDATE,'dd.mm.yyyy hh24:mi:ss'));

他のヒント

It's not TCL its an SQL query embedded in a TCL string, specifically one that binds a variable, which is then assigned to a normal TCL variable

As glenn points out, on its own this snippet of TCL does very little. presuembly somewhere in your program you actually connect to a DB and pass it a query from this string and some other variables

If you're using TDBC, you might have

# assume the connection has already occured and is named "db"
set sql "SELECT ... WHERE a.b=:service_id IN (:keys)"
set statement [db prepare $sql]

# get the bind variables' values from the local context:
set service_id 42
set keys [join {key1 key2 key3} ,]
set resultset [$statement execute]

# or, without setting the "service_id" and "keys" variables, 
# provide them as an argument to the execute subcommand
unset service_id keys
set resultset [$statement execute {service_id 24 keys "foo,bar,baz"}]

As others pointed out it you just assign a string* to a variable.

More exactly, you assign the following string to a variable called sql

SELECT PROD.KEY || ' {' || PARAMETERS || '}'  FROM PRV_PROD_MAPPING PROD  WHERE PROD.SERVICE_ID = :service_id  AND (PROD.KEY || ' ' || PROD.KEY_VAL)  IN (:keys) 

The values of :service_id and :keys are bound values that are passed later (In a oraplexec statement probably).

|| is string concatenation in SQL. So PROD.KEY || ' {' || PARAMETERS || '}' could be PRODKEY {PARAMETERS}.

*Everything is a string

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top