Encountered the symbol "." when expecting one of the following - plsql

create or replace procedure zivtest is
utl_mail.send_attach_varchar2 varchar2(100) :=utl_mail;
mail_subject varchar2(255) := 'zivtest'||sysdate;
mail_message varchar2(1000):='zivtest'
||'<br>'||'User count of all active users in all Realms';
recipients_list varchar2(255) :='user#user.com';
p_sender varchar2(50) := 'user#user.com';
data clob;
data_header varchar2(255);
--E_too_much_values exception;
begin
for item IN ( select decode(r.irl_id,1,'UPSEC',2,'PC',3,'CSM',6,'DMROAM',7,'WORKFLOW',8,'CSS_DEALER',10,'CCBATCH',14,'CSS',61,'COL',81,'CRM'
,82,'FIU',83,'OCM',84,'BOA',127,'SAPI') realm,
count (a.user_id) users
from sec_idm_user a , SEC_IDM_REALM_A r
where a.iu_rlid=r.irl_id
and a.iu_lock='N'
and a.iu_last_login >= sysdate -90
group by r.irl_id) LOOP
if data is not null then
utl_mail.send_attach_varchar2(
sender => p_sender,
recipients => recipients_list,
subject => mail_subject,
message => mail_message,
mime_type => 'text/html; charset=WINDOWS-1255',
attachment => data_header || data ,
att_filename => 'USER_COUNT.csv');
end if ;
END LOOP;
END;
How can I fix this?
I got the following error when I try to compile it:
PLS-00103: Encountered the symbol "." when expecting one of the following:
<an identifier> <a double-quoted delimited-identifier> current

You are seeing this error because second line
utl_mail.send_attach_varchar2 varchar2(100) :=utl_mail;
doesn't make sense. you are trying to declare variable named utl_mail.send_attach_varchar2.
What you need is to install utl_mail package, to be able to use procedure utl_mail.send_attach_varchar2

Related

Oracle - store large string in CLOB

I need to save a procedure body into a Clob column with a use of variable. String is longer than 4000 characters, so I can't use VarChar2, but with CLOB variable I receive error "ORA-01422: exact fetch returns more than requested number of rows". Same error appears with Varchar2. My PL/SQL block:
DECLARE
txt_procedure CLOB;
BEGIN
SELECT text INTO txt_procedure
FROM all_source
WHERE name = 'My_procedure'
ORDER BY line;
INSERT INTO TABLE1(ID,DATE,CLOB_COLUMN)
VALUES (my_seq.NEXTVAL,'11.10.2018',txt_procedure);
END;
/
How could I insert procedure body into clob column ?
As you will get multiple rows from your query for every line of your source, the following might help:
DECLARE
txt_procedure CLOB;
BEGIN
FOR source_r IN ( SELECT text
FROM all_source
WHERE name = 'My_procedure'
ORDER BY line
)
LOOP
txt_procedure := txt_procedure || chr(10) || source_r.text;
END LOOP;
INSERT INTO TABLE1(ID,DATE,CLOB_COLUMN)
VALUES (my_seq.NEXTVAL,'11.10.2018',txt_procedure);
END;
/
UPDATE
As an alternative, you might also use the DBMS_METADATA package for this:
DECLARE
txt_procedure CLOB;
BEGIN
txt_procedure := DBMS_METADATA.get_ddl(
object_type => 'PROCEDURE',
name => 'My_procedure',
owner => 'YOUR_SCHEMA'
);
INSERT INTO TABLE1(ID,DATE,CLOB_COLUMN)
VALUES (my_seq.NEXTVAL,'11.10.2018',txt_procedure);
END;
/

Showing error ' ORA-01858: a non-numeric character was found where a numeric was expected' in this command

Here are my code.
Create OR Replace Procedure new_prof
(
Pno IN VARCHAR2,
ProLast_Name IN VARCHAR2,
ProFirst_Name IN VARCHAR2,
Pro_rank IN VARCHAR2,
ProResearch_Specialty IN VARCHAR2,
Pro_DOB IN DATE,
Time_percentage DECIMAL
)
IS
BEGIN
INSERT INTO professors VALUES(Pno,ProLast_Name,ProFirst_Name,Pro_DOB,Pro_rank,ProResearch_Specialty,Time_percentage);
DBMS_OUTPUT.PUT_LINE('New Professors'||Pno||'is successfully created');
END;
/
When I Execute the code,
EXECUTE new_prof('P0026','Ronaldo','Christiano',TO_DATE('07/25/1978','MM/DD/YYYY'),'Senior','Programming',0.40);
After I execute this code, it show me "the non-numeric character was found where a numeric was expected" at the Date there.
You are passing parameters in the wrong order.
To avoid problems like this, you should better pass the parameters explicitly, instead of relying on their order.
For example:
begin
new_prof( Pno => 'P0026',
ProLast_Name => 'Ronaldo',
ProFirst_Name => 'Christiano',
Pro_rank => 'Senior',
ProResearch_Specialty => 'Programming',
Pro_DOB => TO_DATE('07/25/1978','MM/DD/YYYY'),
Time_percentage => 0.40
);
end;

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.

How to retrieve calendaring expression from DB table

I am making a job with a determined repeat_interval. My goal was to retrieve this value from a table, so that I could change this value in the table afterwards and modify the job accordingly. For this, I made the following trigger:
CREATE OR REPLACE TRIGGER config_table_aur AFTER
UPDATE OF value ON config_table FOR EACH row WHEN (new.property = 'job_interval') DECLARE v_job NUMBER;
BEGIN
dbms_job.submit (v_job, 'begin
update_interval (' || :new.value || ');
end;');
END;
And this trigger calls the following procedure:
CREATE OR REPLACE
PROCEDURE update_interval(
p_new_interval IN config_table.value%type)
AS
BEGIN
dbms_scheduler.set_attribute ('jobu', 'repeat_interval', p_new_interval);
END update_interval;
Where p_new_interval is the value I'm retrieving from the table. The problem that I'm having is that if I try setting a value in the table like this:
FREQ=DAILY; INTERVAL=1;
Then I get an error saying:
Fila 1: ORA-06550: line 2, column 46:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
year month day hour minute second
The symbol ";" was ignored.
ORA-06512: at "SYS.DBMS_JOB", line 82
ORA-06512: at "SYS.DBMS_JOB", line 140
ORA-06512: at "SOMESCHEMA.CONFIG_TABLE_AUR", line 3
ORA-04088: error during execution of trigger 'SOMESCHEMA.CONFIG_TABLE_AUR'
I guess the problem is that the attribute value contains semicolons ';' because if I don't use them I don't get the error.
Do you have any suggestions to circumvent this problem?
Thank you
I guess the problem is that the attribute value contains semicolons ';' because if I don't use them I don't get the error.
Do you have any suggestions to circumvent this problem?
Err ... Your question makes no sense. You know the problem but you don't want to fix the syntax error you have in the repeat_interval calendaring syntax ?
For this simple example your trigger looks unnecessary complex (but you might have a valid reason to use DBMS_JOB though). Here is an example that first sets a scheduled job to run at every minute on 30th second and then later changes the repeat_interval via configuration table to run every 10 seconds:
--
-- scheduler configuration via tailored config table
--
create table scheduler_config (
Job_name varchar2(100) not null,
repeat_interval varchar2(100) not null
);
insert into scheduler_config values('logger1', 'FREQ=SECONDLY; BYSECOND=30');
commit;
create or replace trigger scheduler_config_trg
after update of repeat_interval
on scheduler_config
for each row
declare
pragma autonomous_transaction;
begin
-- Note: throws an exception if no such job
dbms_scheduler.set_attribute(name => :new.job_name,
attribute => 'repeat_interval',
value => :new.repeat_interval);
end;
/
show errors
--
-- a simple job we want to schedule
--
create table scheduler_log (
job_name varchar2(100),
time timestamp(3),
text varchar2(4000)
);
begin
dbms_scheduler.create_job(
job_name => 'logger1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into scheduler_log values(''logger1'', systimestamp, ''Executed!''); commit; END;',
start_date => systimestamp,
repeat_interval => 'FREQ=SECONDLY; BYSECOND=30',
end_date => null,
enabled => true,
comments => 'Testing configuration');
end;
/
--
-- check how much work has been done and when
--
col job_name for a10
col time for a25
col text for a20
select * from scheduler_log order by time;
--
-- I want more job for my money !
--
update scheduler_config
set repeat_interval = 'FREQ=SECONDLY; INTERVAL=10'
where job_name = 'logger1';
commit;
--
-- remove the job
--
exec dbms_scheduler.drop_job('logger1')

How do I run PL/SQL code within SQLPlus?

I am trying to run the following code within SQLPlus:
exec lbacsys.sa_sysdba.create_policy(policy_name => 'ACCESS_LOCATIONS',
column_name => 'OLS_COLUMN',
default_options => 'READ_CONTROL,INSERT_CONTROL,UPDATE_CONTROL,DELETE_CONTROL,LABEL_DEFAULT,LABEL_UPDATE,CHECK_CONTROL,');
However, I'm getting the following error:
BEGIN lbacsys.sa_sysdba.create_policy(policy_name => 'ACCESS_LOCATIONS',; END;
*
ERROR at line 1:
ORA-06550: line 1, column 78:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternatively
It seems to me to be something I'm doing wrong with the syntax. I'm just not sure what it is. Any help would be appreciated. Thanks :)
The EXEC statement takes a line of code and wraps it in a BEGIN/END block. In this case you want to split your call over several lines of code, so you'll probably find it easier to add the BEGIN/END yourself:
BEGIN
lbacsys.sa_sysdba.create_policy(policy_name => 'ACCESS_LOCATIONS',
column_name => 'OLS_COLUMN',
default_options =>
'READ_CONTROL,INSERT_CONTROL,'
|| 'UPDATE_CONTROL,DELETE_CONTROL,'
|| 'LABEL_DEFAULT,LABEL_UPDATE,CHECK_CONTROL,');
END;
/

Resources