Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing Values of Bind Variables

Posted on 2009-04-01
10
Medium Priority
?
802 Views
Last Modified: 2013-12-18
I have PL/SQL package where in I am executing the dynamic insert as shown below
--code snippet
v_ins_sql:=
' INSERT INTO tablea 
(col1, col2)
VALUES
(:1,
:2)
 
--p_col1_value, p_col2_value values are passed as parameters to procedure
EXECUTE IMMEDIATE v_ins_sql
USING (p_col1_value, p_col2_value);
 
DBMS_OUTPUT.PUT_LINE(v_ins_sql);
--------------------------------------------------
 
--problem statement
Now, I have log table where in I have to insert the v_ins_sql string along with values.
But I am not getting values of p_col1_value, p_col2_value when I print DBMS_OUTPUT.PUT_LINE(v_ins_sql);
 
I get this 
INSERT INTO tablea (col1, col2) VALUES (:1, :2)
 
I wish to see the values of :1 and :2 and store in log table?
Is this doable in PL/SQL?

Open in new window

0
Comment
Question by:ajexpert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 24045801
Hi ajexpert,

try doing

DBMS_OUTPUT.PUT_LINE(':1=" || p_col1_value || ' :2=' || p_col2_value);

lwadwell
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24045804
sorry ... quotes not quite right

DBMS_OUTPUT.PUT_LINE(':1=' || p_col1_value || ' :2=' || p_col2_value);
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24045817
Rather than peppering log statements all over your code, and doing your own log/audits, why not use the builtin Oracle features? You can configure Oracle to log statements as well as bind variable values, and you can do it on a fine-grained per table basis.
The danger is using your own logging is unless you catch exceptions, a log statement may cause your overall procedure / transaction to fail.

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 14

Author Comment

by:ajexpert
ID: 24045819
I want to insert the sql statement not using DBMS_OUTPUT.PUT_LINE.
something like
 

' INSERT INTO tablea 
(col1, col2)
VALUES
(:1,
:2)
-----------------------
I wish to store the entire string along with bind variables values and not printing bind variable values separately
 

Open in new window

0
 
LVL 14

Author Comment

by:ajexpert
ID: 24045826
@mrjoltcola
This is one of the package we are developing which requires this logging.
I cannot alter oracle configuration because of this package.
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24045862
How do you want it look in your log table?  Although I support mrjoltcola's suggestion of using Oracle's built in features.

Using bind variable's (which is good for performance) - the actual values are only resolved at time of execution and will never be part of the executed SQL string.

It would be possible to put replace() or similar functions in place to do the substitution for logging ... or you could concatenate them onto the end ... what is your requirement?
0
 
LVL 14

Author Comment

by:ajexpert
ID: 24045877
My requirement is
suppose I get parameter values as '
p_col1_value = 'test1'
p_col2_value = 100000  
My insert statement should go in log table like this

INSERT INTO tablea 
(col1, col2)
VALUES
('test1',
100000)

Open in new window

0
 
LVL 25

Accepted Solution

by:
lwadwell earned 375 total points
ID: 24045910
REPLACE(REPLACE(sql_str,':1',p_col1_value),':2',p_col2_value) would get you close ... except 'test1' would not be quoted.

REPLACE(REPLACE(sql_str,':1','''' || p_col1_value || ''''),':2',p_col2_value) would have the quotes included.
0
 
LVL 14

Author Comment

by:ajexpert
ID: 24045918
too much of homework I think...
is there any simple way?
I am ok even if I have to just log the statement after EXECUTE IMMEDIATE;
0
 
LVL 14

Author Closing Comment

by:ajexpert
ID: 31565615
Though I didnt implented it, but I got another idea.  Thanks anyways
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question