Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to pass a variable for a create statement inside pl/sql function

User_KYWTCSep 30 2020

Hi Team,

My current environment is in 12.1.0.1.
Below is the sample code where I am trying to create an some policies by passing some variable. The issue is it just prints the actual string instead of printing the variable it gets.

For example:
v_machine=prod.example.com

It has to print prod.example.com but it prints the actual string v_machine.. Not sure where I m missing. Please provide your inputs as I m new to Pl/sql.
Audit policy
===========
declare
v_machine varchar2(99);
lv_stmt varchar2(32767);
begin
select host_name into v_machine from v$instance;
lv_stmt := q'[create audit policy LOG_AUDIT ACTIONS LOGON when 'SYS_CONTEXT (''USERENV'', ''HOST'') NOT IN (''v_machine'')' evaluate per session]';
execute immediate lv_stmt;
end;
/

Expected Output:
===========
Audit_policy Action_name Audit _condition
=====================================
LOG_AUDIT LOGON (''USERENV'', ''HOST'') NOT IN (''prod.example.com'')'

Actual Output
==========
Audit_policy Action_name Audit _condition
=====================================
LOG_AUDIT LOGON (''USERENV'', ''HOST'') NOT IN (''V_Machine'')'

Thanks,
Bala

This post has been answered by jaramill on Sep 30 2020
Jump to Answer
Comments
Post Details
Added on Sep 30 2020
1 comment
435 views