I'm currently using the Apex context to deploy a page created directly from PLSQL, I need to use the "Shared Components/Items" to store some dynamic values for the user and then be destroyed when the context is destroyed.
I'm using the Items but I couldn't find a way to create them dynamically from PLSQL so I'm looking for a replacement to this app behavior.
This is my current solution:
APEX_UTIL.SET_SESSION_STATE (p_name => 'Item_Name',
p_value => 'Item Value');
But this is not possible with dynamic Items or Variables,
What would you suggest?
Thanks for your answer.
Solution for this:
Collections
APEX_COLLECTION.CREATE_COLLECTION(
p_collection_name IN VARCHAR2);
--and to add a value
Begin
APEX_COLLECTION.ADD_MEMBERS(
p_collection_name => 'EMPLOYEE',
p_c001 => l_arr1,
p_c002 => 1_arr2);
End;
See documentation for more information:
https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_collection.htm#AEAPI531
Related
I have some problems when trying to solve my homework about VPD Policy of Oracle. The question is "MYADMIN account has the right to select and update students' Enroll Information. But he is not allowed to see the Score of the student's Enroll Information as well as update the Score of the student's Enroll Information.
I have done the first task (they are not allowed to see the Score of the student's Enroll Information by using column masking), but when I trying to add the word "update" to statement_type to my code like this, the DBMS notifies errors. I have searched the Internet and realized that column masking can be only used for "Select" statment.
So if I want to apply the Oracle VPD Policy to restrict MYADMIN to update the Score of students' Enroll Information. How can I do that? Will I have to create a session_context view?
Here is my code. Thank you so much
CREATE OR REPLACE FUNCTION Question5
(p_schema IN VARCHAR2, p_object IN VARCHAR2)
RETURN VARCHAR2
AS
user_value VARCHAR2(60);
user varchar2(60);
BEGIN
user := SYS_CONTEXT('userenv','session_user');
user_value:= '(select (SYS_CONTEXT(''USERENV'',''SESSION_USER'')) from dual)';
IF(UPPER(user) = 'MYADMIN') THEN
RETURN 'USER != ''MYADMIN''';
ELSE
RETURN 'StudentID = ' || user_value;
END IF;
END;
/
BEGIN
DBMS_RLS.ADD_POLICY(
object_schema =>'SYSTEM',
object_name => 'EnrollInformation',
policy_name => 'Question5_MyAdmin',
statement_types => 'select, update',
function_schema => 'sec_mgr',
policy_function => 'Question5',
sec_relevant_cols => 'Score',
sec_relevant_cols_opt => dbms_rls.all_rows,
update_check => TRUE);
end;
/
we have tables that were created with "NOROWDEPENDENCIES" (the default).
I've read in oracle documentation that the only two ways to do so are:
redefine the table using the DBMS_REDEFINITION package or recreate the table.
I can not recreate the table, so my only solution is to redefine it, but I couldn't find anywhere an example or a guide to do it.
can you show me an example or reference to any guide?
Thanks
First of all you have to check if redefinition is allowed for your table.
If the following procedure returns an exception you are not allowed:
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE(
uname => '<USER NAME>',
orig_table => '<TABLE NAME>'
);
END;
/
If the table can be redefined you have to create an interim table on the same schema with the desired attributes. The execute (no column mapped in your table):
BEGIN
DBMS_REDEFINITION.start_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM'
);
END;
/
If everything is ok you can finish the process executing the procedure:
BEGIN
DBMS_REDEFINITION.finish_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
Before finishing redefinition with the previous procedure you can create indexes, constraints, etc.. on the interim table.
If you want to keep the interim table synchronized with the original table you also might need:
BEGIN
DBMS_REDEFINITION.sync_interim_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
to be called before the FINISH_REDEF_TABLE Procedure.
dbms_redefinition.copy_table_dependents(..); can be useful to complete the job.
To abort the redefinition procedure you might need:
BEGIN
DBMS_REDEFINITION.abort_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
Pay attention, you might need a lot of space if the original table is big.
If the system is on line redefinition should be monitored. It might be heavy.
Hey Guys I need Help How to send EMAIL Automatically in oracle APEX, I know some using DBMS_SCHEDULER we can achieve it, I have no idea how to do it where to start any suggestion, Along with that i want to attach a report. COuld you help me?
Can you Suggestest any blog?
Thank You in Advance.......
This blog is a good place to start: https://blogs.oracle.com/apex/creating-email-campaign-app-with-oracle-apex
The code below as long as the owner of the job is a schema that has been provisioned for the APEX workspace, or the schema has been granted the role APEX_ADMINISTRATOR_ROLE. You will need to substitute 100 for your actual application number and 1 with an actual page in that application. The third parameter is the username and can be anything.
DECLARE
l_mail_id NUMBER;
BEGIN
apex_session.create_session (100, 1, 'send_email');
l_mail_id :=
apex_mail.send (p_to => 'youremail#gmail.com',
p_from => 'nobody#test.com',
p_body => 'plaintext body',
p_body_html => '<h1>HTML Body</h1>',
p_subj => 'Test Email Subject');
apex_mail.add_attachment (p_mail_id => l_mail_id,
p_attachment => EMPTY_BLOB (),
p_filename => 'attachment_name.json',
p_mime_type => 'application/json');
apex_mail.push_queue;
apex_session.delete_session;
END;
/
Env: Oracle 12c
I am new to Oracle Advanced Queues (AQ) and it looks like it's supposed to be the best approach to use instead of polling.
Based on this, I want to utilise AQ to be used based on the following trigger:
CREATE OR REPLACE TRIGGER MY_TRG
AFTER UPDATE OF STATUS ON "MY_TABLE"
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
declare
v_status INTEGER;
begin
if :OLD.status = 'ERROR' and (:NEW.status = 'OK' or :NEW.status = 'ERROR') then
--
-- do some Advanced Queue processing here ?
--
end if;
end;
So instead of polling when the STATUS column is updated, is it possible to have some type of CALLBACK feature using AQs?
I basically need a means of knowing when the STATUS column is updated in order to perform some other operation when this occurs.
FYI, I have taken the links/information provided from the comments as well as other sites to base my solution using Oracle Advanced Queues.
Another link that was provided to me for this very purpose was:
https://markhoxey.wordpress.com/2016/03/01/asynchronous-processing-using-aq-callback/
To better answer this, I used the sample code that Mark Hoxey provided within his article, specifically the PL/SQL CALLBACK routine that was invoked via my table trigger, during a STATUS update.
You can see all available code here:
https://onedrive.live.com/?id=B48A94826582EA7D%2158434&cid=B48A94826582EA7D
This is by far the best option to use when it comes to asynchronous processing instead of polling tables with scheduled jobs.
Not very clear question. Is "MY_TABLE" is a table for AQ Queue? If so, then look towards AQ "native" callbacks (just as you ask).
Not exhaustive example, see docs for full variations.
declare
p$queue varchar2(30) := 'YOU_QUEUE';
p$call_back_procedure_name varchar2(30) := 'you_cb_proc';
p$consumer varchar2(30) := 'YOU_CONS';
m$reg SYS.AQ$_REG_INFO_LIST;
begin
m$reg := SYS.AQ$_REG_INFO_LIST();
m$reg.extend();
m$reg(1) := SYS.AQ$_REG_INFO(
name => p$queue || ':' || p$consumer,
namespace => DBMS_AQ.NAMESPACE_AQ,
callback => 'plsql://' || p$call_back_procedure_name || '?PR=1',
context => null,
qosflags => DBMS_AQ.NTFN_QOS_RELIABLE,
timeout => 0
);
dbms_aq.register(m$reg, 1);
end;
/
More in docs: https://docs.oracle.com/database/121/ARPLS/d_aq.htm#ARPLS100
I'm currently using:
BEGIN
PACKAGE1.PROCEDURE1('PARAM_1','PARAM_A','PARAM_B');
END;
I need to run the same procedure multiple times (Oracle), but this time changing only the first parameter, for example:
PACKAGE1.PROCEDURE1('PARAM_2','PARAM_A','PARAM_B');
PACKAGE1.PROCEDURE1('PARAM_3','PARAM_A','PARAM_B');
How can i accomplish this? Thank you in advance.
In anonym plsql block write a loop with number of iteration depends on how many parameters You want to call procedure with. At the top of loop put logic that will be setting a paramter an then call a procedure with it. But remember that there is no option in plsql to read data from console or user during a program run.
// I think that You can ask about passing an other variable in loop each time, I am not sure is it can be done in plsql You can try use
execute_immidiate
command with string conncatenate as a parameter name.
You Package Procedure must be with IN OUT parameter and i assume the first parameter is IN so the master should take care of the thing of supplying the values to this.
Procedure is working as expected now the external stream of incoming this have to take which is coming from outer source or some other passing mechanism.
Just align those to this package procedure and you may call this procedure as many time as you want according to IN this takes.
You could try to submit it as job if you want to run the same procedure simultaneously.
BEGIN
begin
dbms_scheduler.create_job
(
job_name => 'One_Time_Job_1',
job_type => 'PLSQL_BLOCK',
job_action => 'begin PACKAGE1.PROCEDURE1('PARAM_2','PARAM_A','PARAM_B'); end;',
start_date => sysdate,
enabled => TRUE,
auto_drop => TRUE,
comments => 'one-time job');
end;
begin
dbms_scheduler.create_job
(
job_name => 'One_Time_Job_2',
job_type => 'PLSQL_BLOCK',
job_action => 'begin PACKAGE1.PROCEDURE1('PARAM_3','PARAM_A','PARAM_B'); end;',
start_date => sysdate,
enabled => TRUE,
auto_drop => TRUE,
comments => 'one-time job');
end;
END;
look at DBMS_SCHEDULER for further details.
If this is for an ongoing production process with a fixed number of parallel procedures, I would consider using a Scheduler Chain.
This would execute all the procedures at the same time, and give you extra features, such as:
the ability to run other procedures when one or all of them has completed
control over which procedures run afterwards, depending on the success or failure of the procedures.