How to ignore "Application collection already exists" error? - plsql

How can I ignore the errors below?
create_co - errc=-20104 errm=ORA-20104: create_collection_from_query_b Error:ORA-20101: Application collection exists
create_co - errc=-20104 errm=ORA-20104: create_collection_from_queryb2 Error:ORA-00001: Schending van UNIQUE-beperking (APEX_180200.WWV_FLOW_COLLECTIONS_UK).
This error is confusing for users.
declare
pl_query varchar2(4000);
cl_collectie constant varchar2(255) := 'MY_COLLECTION';
begin
--
if apex_collection.collection_exists( p_collection_name => cl_collectie )
then
apex_collection.delete_collection( p_collection_name => cl_collectie );
end if;
--
pl_query := q'[select QUERY]' ;
--
apex_collection.create_collection_from_queryb2( p_collection_name => cl_collectie
, p_query => pl_query );
end;
We're using Application Express 18.2.0.00.12.

if you run the dynamic action for example on button click then you have to disable the button until the dynamic action is finished. generally you need to find a way to prevent your users from running the dynamic action a second time if the first time isn't finished yet.

Related

PLSQL is it possible to update a table column on a certain date?

I have this table :
penalities(player,dateofpenality,penalityDays,status)
Based on certain criteria a player is added to this table where the status goes to 'yes'. I want his status to change to 'no' jusrt after the penality period (=penalityDays) is gone.
I thought of a trigger on date but I couldn't find it in plsql.
Please note that I don't want to delete the player as I need the history .
The only way to do this is to schedule a background job which kicks off once a day.
Write a simple stored procedure to apply the change of status:
create or replace procedure update_penalty_status as
begin
update penalties
set status = 'no'
where sysdate >= dateofpenality + penalityDays
and status = 'yes';
commit;
end update_penalty_status;
Then submit a job to run once a day. This uses DBMS_SCHEDULER (available since 10g) rather than the older DBMS_JOB.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'your_schema.my_job1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN update_penalty_status; END;',
start_date => trunc(sysdate)+1,
repeat_interval => 'FREQ=DAILY'
enabled => TRUE,
comments => 'Revoke expired penalties');
END;
/
Note that you will need the CREATE JOB privilege to do this. You may need to ask your DBA for help and guidance. Normally I would link to the Oracle documentation at this point, but I think the Oracle-Base article is a friendlier place to start.

How to update a parameter in a job in Oracle SQL

I have just created a job using SQL Developer build-in wizard and i would like to change the parameters of the created job from my application.
The job is launching a stored procedure every day at 7 o'clock.
In the application I have to field:
Disable: true/false
Hour: 10:00
And this is my job and fields I would like to update depending on what was selected in the app:
I see two ways of doing it:
Make the fields dependent on the values in the table
Make a pl/sql block that updates the values
Of course I don't know how to do it (in the first option the select statement doesn't work and in the second I don't know how to acces the jobs fields)
Please help
Begin
dbms_scheduler.disable( 'ATOS."job_email_notifications"' );
DBMS_SCHEDULER.SET_ATTRIBUTE ( name => 'ATOS."job_email_notifications"', attribute => 'repeat_interval', value => 'freq=daily;byday=FRI,SAT;byhour=20;byminute=0; bysecond=0');--change value--as per need
dbms_scheduler.enable( 'ATOS."job_email_notifications"' );
End;
/
Use below procedure for dynamic updates based on values
Create or replace procedure change_attributes(a_job_name varchar2, a_param varchar2, a_new_val varchar2)
As
Begin
dbms_scheduler.disable( a_job_name);
DBMS_SCHEDULER.SET_ATTRIBUTE ( name => a_job_name,attribute => a_param, value => a_new_val);
dbms_scheduler.enable( a_job_name);
End;
/

How to create a procedure to run through table and send an email in Oracle Apex?

I'm currently using Oracle Apex 4.2 and I need a way to have the program run through a table and send a email if it has not been sent yet. What is the best way to do this and how?
It sounds like you just want something like this (I'm speculating about your table definition, the names of your columns, etc.)
FOR m IN (SELECT *
FROM email_table
WHERE sent_yet = 'N')
LOOP
apex_mail.send( p_to => m.to,
p_from => <<your email address>>,
p_body => m.text_of_email,
p_subj => m.subject );
UPDATE email_table
SET sent_yet = 'N'
WHERE primary_key = m.primary_key;
END LOOP;
The apex_mail.send procedure documentation shows more options that you can pass in. Note that if you're not already sending email in this environment using apex_mail, you probably want to have a separate job that actually sends the queued up emails. For example, this will submit a job that sends queued up emails every minute.
DECLARE
l_jobno pls_integer;
BEGIN
dbms_job.submit( l_jobno,
'begin apex_mail.push_queue( <<smtp server>>, <<port>> ); end;',
sysdate + interval '1' minute,
q'{sysdate + interval '1' minute}' );
commit;
END;
I figured out what was the issue. I need a line of code to allow apex to send emails through my application.
BEGIN
wwv_flow_api.set_security_group_id;
for rst in (
select aud.LAN_ID, aud.ID, sent.TEMPLATE_TEXT, temp.TEMPLATE_NAME from EMAIL_Audit aud
INNER JOIN EAMAIL_SENT sent
ON aud.TEMP_TEXT_ID = sent.id
INNER JOIN EMAIL_TEMP temp
ON sent.PROCESS_ID = temp.id
WHERE SENT_IND is null
)
loop
APEX_MAIL.SEND(
p_to => 'someEmail#email.com',
p_from => 'otherEmail#email.com',
p_body => rst.TEMPLATE_TEXT,
p_subj => rst.TEMPLATE_NAME );
END loop;
APEX_MAIL.PUSH_QUEUE;
END;​

Issue With PL/SQL Bind Variables

Recently, I deployed an Oracle WareHouse Builder (OWB) mapping. In the scenario I'm working right now, this mapping (ETL process) needs to be fired up by a trigger after an Update statement takes place on the fact table (working with WriteBack values).
As the mapping is deployed to the target schema as a package, the trigger must call the main procedure that OWB creates for the package. At first I didn't knew how to accomplish this task, but SQL Developer gave me a hint:
So, I took this code and put it inside my trigger. Like this:
CREATE OR REPLACE TRIGGER RESPALDO_HISTORIAL
AFTER UPDATE ON MONITOR_FT_TAB
FOR EACH ROW
DECLARE
P_STATUS VARCHAR2(200);
P_MAX_NO_OF_ERRORS VARCHAR2(200);
P_COMMIT_FREQUENCY VARCHAR2(200);
P_OPERATING_MODE VARCHAR2(200);
P_BULK_SIZE VARCHAR2(200);
P_AUDIT_LEVEL VARCHAR2(200);
P_PURGE_GROUP VARCHAR2(200);
P_JOB_AUDIT VARCHAR2(200);
BEGIN
P_MAX_NO_OF_ERRORS := NULL;
P_COMMIT_FREQUENCY := NULL;
P_OPERATING_MODE := NULL;
P_BULK_SIZE := NULL;
P_AUDIT_LEVEL := NULL;
P_PURGE_GROUP := NULL;
P_JOB_AUDIT := 'TRUE';
SINIESTROS_MARCADOS_MAP.MAIN(
P_STATUS => P_STATUS,
P_MAX_NO_OF_ERRORS => P_MAX_NO_OF_ERRORS,
P_COMMIT_FREQUENCY => P_COMMIT_FREQUENCY,
P_OPERATING_MODE => P_OPERATING_MODE,
P_BULK_SIZE => P_BULK_SIZE,
P_AUDIT_LEVEL => P_AUDIT_LEVEL,
P_PURGE_GROUP => P_PURGE_GROUP,
P_JOB_AUDIT => P_JOB_AUDIT
);
:P_STATUS := P_STATUS;
END RESPALDO_HISTORIAL;
/
When I tried to compile this trigger, I got this screen:
In this screen I tried clicking "Aplicar" (Apply in spanish) with and without the NULL checkbox, always getting this output:
TRIGGER RESPALDO_HISTORIAL compilado
Errors: check compiler log
Then I ran the SHOW ERRORS command and I got this:
33/3 PLS-00049: bad bind variable 'P_STATUS'
Now I don't quite understand these bind variables. If this is the code generated by SQL Developer to run the package, then why I get this error??
Please help! I need some guidelines in this matter!
Greetings!
A colon preceding a variable indicates that that variable is a bind variable. Bind variables of this type are typically used to pass values in and out of anonymous blocks. They're not allowed in procedures, functions, or triggers. In this case, you need to remove the line :P_STATUS := P_STATUS;.

Retrieving issues from jira conditoinally

I am using a sql http request to retrieve issues from JIRA , so far I can retrieve chosen number of issues according to the assignee name or reporter.
My problem now that I can not retrieve issues according to the creation field (date when the issues has been created) or othe custom field, I am receiving error :
Unrecognized field !
My approach was to play around with this part of the code :
**lv_json_request := '{'
||'"jql": "assignee='||:P9_ASSIGNEE||'",'
||'"startAt": '||NVL(:P9_STARTAT,0)||','
||'"maxResults": '||:P9_MAXRESULTS
||'}';**
You can find below the whole pl/sql block , it works fine with the current situation .
DECLARE
http_req utl_http.req;
http_resp utl_http.resp;
lv_json_request VARCHAR2(32767);
lc_response CLOB;
lv_response VARCHAR2(32767);
BEGIN
lv_json_request := '{'
||'"jql": "assignee='||:P9_ASSIGNEE||'",'
||'"startAt": '||NVL(:P9_STARTAT,0)||','
||'"maxResults": '||:P9_MAXRESULTS
||'}';
UTL_HTTP.set_wallet('file:/oracle/ora11/owm/wallets/oracle', 'apex4wallet');
http_req:= utl_http.begin_request
( url => 'https://rb-wam.bosch.com/tracker/rest/api/2/search'
, method => 'POST'
);
utl_http.set_header(http_req, 'Authorization', 'Basic '||:F_JIRA_TOKEN_REST);
utl_http.set_header(http_req, 'Content-Type', 'application/json');
utl_http.set_header(http_req, 'Content-Length', LENGTH(lv_json_request));
utl_http.write_text(http_req, lv_json_request);
http_resp:= utl_http.get_response(http_req);
-- read data from response
BEGIN
LOOP
utl_http.read_text(http_resp, lv_response);
HTP.PRN(lv_response);
lc_response := lc_response || TO_CLOB(lv_response);
END LOOP;
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
utl_http.end_response(http_resp);
END;
-- log details
--DELETE webservice_log;
INSERT INTO webservice_log (seq_id,clob_response,clob_request) VALUES (sqe_Webservice_Log.NEXTVAL,lc_response,TO_CLOB(lv_json_request));
--HTP.P(lc_response);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
You can add something like this to your lv_json_request statement:
"createdDate<='||:P9_CREATED||'"
using any valid operator instead of "<=", depending on your needs.

Resources