SQL script, how can i execute the following script? - sql

I have to execute this script . The problem in that in SQL Developer i cant run it,since some operators are not recognized .
P_jobgroup_id :
'GDWH2MYGDWH-GDWH2MYGDWH' CORE load finished
'GDWH2MYGDWH-GDWH2MYGDWH_IF' IF finished
'GDWH2MYGDWH-GDWH2MYGDWH_INIT' IF or CORE started
declare
p_context_code varchar2(100) := 'GDWH2MYGDWH';
v_res varchar2(100);
begin
v_res := OJC.jc_master.main
(
p_batch_number => NULL,
p_jobgroup_id => 'GDWH2MYGDWH-GDWH2MYGDWH'),
p_parameters_string => 'GDWH2MYGDWH.PRM_REPORTING_DATE='||to_char(sysdate,'yyyymmddhh24miss',
p_context_code =>p_context_code
);
end;
/
Error starting at line 1 in command: P_jobgroup_id : Error report:
Unknown Command
Error starting at line 2 in command: 'GDWH2MYGDWH-GDWH2MYGDWH'
CORE load finished Error report: Unknown Command ORA-06550: line 8,
column 50: PLS-00103: Encountered the symbol "," when expecting one of
the following:
. ( * % & = - + ; < / > at in is mod remainder not rem

The first par of the script is not valid PLSQL code.
Commenting or removing it will make the script run, once fixed a couple of syntax errors.
/*
P_jobgroup_id :
'GDWH2MYGDWH-GDWH2MYGDWH' CORE load finished
'GDWH2MYGDWH-GDWH2MYGDWH_IF' IF finished
'GDWH2MYGDWH-GDWH2MYGDWH_INIT' IF or CORE started
*/
DECLARE
p_context_code VARCHAR2(100) := 'GDWH2MYGDWH';
v_res VARCHAR2(100);
BEGIN
v_res := OJC.jc_master.main
(
p_batch_number => NULL,
p_jobgroup_id => 'GDWH2MYGDWH-GDWH2MYGDWH',
p_parameters_string => 'GDWH2MYGDWH.PRM_REPORTING_DATE=' || TO_CHAR(SYSDATE, 'yyyymmddhh24miss'),
p_context_code => p_context_code
);
END;
/

Related

Why does a commit trigger an access violation?

The following code using the Community version of Delphi and Interbase 2020 running on a Windows 10 machine results in the following error when the Commit is executed. What am I doing wrong?
Project FamilyTree.exe raised exception class $C0000005 with message ‘access violation at 0x00481a6f: read of address 0x8b57569f’.
procedure writepreamble;
var
sqltext : string;
basicaction : tbasicaction;
begin
sqltext := 'insert into preambleds(preambleseq,text) values(';
sqltext := sqltext+inttostr(preambleseq)+','+quotedstr(cardimage)+');';
datamodule1.IBSQL1.SQL.text := sqltext;
datamodule1.geddb.DefaultTransaction := datamodule1.IBTransaction1;
datamodule1.IBsql1.Transaction := datamodule1.IBTransaction1;
datamodule1.IBsql1.Transaction.StartTransaction;
datamodule1.ibsql1.ExecuteAction(basicaction) ;
datamodule1.IBsql1.Transaction.Commit;
sqlcount := sqlcount+1;
end;
why you are using `ExecuteAction` ?
use `ExecQuery` to execute insert :
IBSQL1.ExecQuery();
best regards
Moskw#

Error in return of PLSQL ORACLE Not Working

This Code is:
CREATE OR REPLACE
PROCEDURE Actualiza_Saldo(fecha_ini IN DATE, fecha_fin IN DATE) RETURN NUMBER
AS
fechaTemp DATE;
diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
BEGIN
diasLaborables:= diastotales;
FOR i IN 0..diasTotales LOOP
fechaTemp := fecha_ini + i;
DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
diaslaborables := diaslaborables-1;
END IF;
END LOOP;
dbms_output.put_line(diaslaborables);
RETURN diasLaborables;
END Actualiza_Saldo;
If I execute without returning it works, if I try to return a value it fails, I do not know what could be happening.
The error of oracle is:
Warning: la ejecución ha terminado con advertencias
PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
Error que empieza en la línea 1 del comando:
EXEC Actualiza_Saldo();
Informe de error:
ORA-06550: línea 1, columna 7:
PLS-00905: el objeto HR.ACTUALIZA_SALDO no es válido
ORA-06550: línea 1, columna 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
The code with constant value:
CREATE OR REPLACE
PROCEDURE Actualiza_Saldo(fecha_ini IN DATE DEFAULT '10/08/2018', fecha_fin IN DATE DEFAULT '30/08/2018')
AS
fechaTemp DATE;
diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
BEGIN
diasLaborables:= diastotales;
FOR i IN 0..diasTotales LOOP
fechaTemp := fecha_ini + i;
DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
diaslaborables := diaslaborables-1;
END IF;
END LOOP;
dbms_output.put_line(diaslaborables);
END Actualiza_Saldo;
EXEC Actualiza_Saldo();
And the exit of the code without the returns and the test values ​​is a route from the start date and the final date subtracting the days Saturday and Sunday.
PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
anonymous block completed
10/08/18
11/08/18
12/08/18
13/08/18
14/08/18
15/08/18
16/08/18
17/08/18
18/08/18
19/08/18
20/08/18
21/08/18
22/08/18
23/08/18
24/08/18
25/08/18
26/08/18
27/08/18
28/08/18
29/08/18
30/08/18
14
But if I try to return the value the algorithm dies.
I have no idea what I am doing wrong or where is the fault, if you could help me I would greatly appreciate it.
Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.
But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes
An example as follows
create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
as
begin
open result_set for
select trunc(start_date)+level as output_dates
from dual
connect by level<=trunc(end_date)-trunc(start_date);
end;
if you are using sqlplus to connect to your database
you would call the proc as follows
var x refcursor
begin
generate_dates(date '2018-01-01',date '2018-12-31',:x);
end;
print x;
My mistake was that I was not doing a function but a procedure solved.
CREATE OR REPLACE
FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
AS

pdf to text conversion using oracle package

i m seeing some strange behavior for my pdf to text conversion using oracle
bellow is the code of a sql file.
create or replace directory pdf_dir as '&1';
create or replace directory l_curr_dir as '&3';
declare
ll_clob CLOB;
l_bfile BFILE;
l_filename VARCHAR2(100) := '&2';
begin
begin
ctx_ddl.drop_policy('test_policy');
exception
when others then
null;
end;
ctx_ddl.create_policy('test_policy','ctxsys.auto_filter');
l_bfile := bfilename('PDF_DIR',l_filename);
dbms_lob.createtemporary(ll_clob, true);
ctx_doc.policy_filter(
policy_name => 'test_policy'
, document => l_bfile
, restab => ll_clob
, plaintext => true
);
ll_clob := REPLACE(TRIM(ll_clob), chr(13), chr(10));
ll_clob := REPLACE(ll_clob, chr(10), chr(32) || '<<EOL>>' || chr(10)||'<<BOL>>');
INSERT into tempclob_op(filename, data) VALUES(l_filename, ll_clob);
DBMS_XSLPROCESSOR.clob2file (ll_clob,'L_CURR_DIR' , 'plaintext.text');
dbms_lob.freeTemporary( ll_clob );
end;
/
problem is i have run this code for 10000 files and it gives correct results for almost all but for almost 10 files it corrupts the output in plaintext.text file. And i dont know why is it happening? Also when i run this sql code for individual files it gives me correct results.
I have added some delay of 2 seconds in every execution while in loop for each file. and seems it resolved the problem strangely ..no concrete answers though.

Virtual Private Database policy predicate has error

I'm trying to implement a vpd. So far I have created a function:
> CREATE OR REPLACE FUNCTION sales_select(
schema_var IN VARCHAR2,
table_var IN VARCHAR2
)
RETURN VARCHAR2
IS
return_val VARCHAR2(400);
BEGIN
return_val := 'time_id >= "01-JAN-01"';
RETURN return_val;
END sales_select;
/
and the policy I made is the following:
L> BEGIN
2 DBMS_RLS.ADD_POLICY (
3 object_schema => 'sh',
4 object_name => 'costs1',
5 policy_name => 'costs_policy',
6 function_schema => 'policy_admin',
7 policy_function => 'sales_select',
8 statement_types => 'select'
9 );
0 END;
1 /
when I run the follow query:
select * from sh.costs1;
I get the following error:
ERROR at line 1:
ORA-28113: policy predicate has error
I'm thinking it has something to do with the quotes in the function but when I try changing them I get compile errors.
Is time_id a date column? If so, try changing line 9 to:
return_val := 'time_id >= date ''2001-01-01''';
Note the double quotes.

PL/SQL error LPX-00249 while parsing XML file from web

I'm writing a programm in PL/SQL for downloading XML files from internet, parsing them and storing values in Oracle database. I have one large XML file, which includes links for a huge amount of smaller XMLs. There are about 6253 files to be parsed. I have function, which downloads XML file into CLOB and saves data into XmlType. This value is returned into programm and is further processed. This is the function:
create or replace function get_xml_by_url
( v_url VARCHAR2
)
RETURN XMLType
AS
req SYS.UTL_HTTP.REQ;
resp SYS.UTL_HTTP.RESP;
xmlClob CLOB;
x XmlType;
l_offset number := 1;
value VARCHAR2(3999); -- URL to post to
BEGIN
BEGIN
UTL_HTTP.SET_PROXY('http://10.1.250.233:8080');
req := UTL_HTTP.BEGIN_REQUEST (url=> v_url, method => 'GET');
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
UTL_HTTP.SET_HEADER
( r => req
, name => 'Content-Type'
, value => 'text/xml;charset=UTF-8'
);
resp := UTL_HTTP.GET_RESPONSE(req);
DBMS_LOB.CREATETEMPORARY(xmlClob, true);
-- Loading first line
UTL_HTTP.READ_LINE(resp,value,false);
DBMS_LOB.WRITE(xmlClob,length(value),l_offset,value);
l_offset := l_offset + length(value);
-- Loading and adjusting second line
UTL_HTTP.READ_LINE(resp,value,true);
value := rtrim(value,'xmlns="http://seznam.gov.cz/ovm/datafile/seznamovm/v1">')||'>';
DBMS_LOB.WRITE(xmlClob, length(value), l_offset,value);
l_offset := l_offset + length(value);
-- Filling CLOB
LOOP
UTL_HTTP.READ_LINE(resp,value,false);
DBMS_LOB.WRITE(xmlClob,length(value),l_offset,value);
l_offset := l_offset + length(value);
END LOOP;
EXCEPTION
when UTL_HTTP.END_OF_BODY
then
UTL_HTTP.END_RESPONSE(resp);
when others
then
utl_http.end_response(resp);
END;
x := XMLType.createXML(xmlClob);
DBMS_LOB.FREETEMPORARY(xmlClob);
RETURN x;
END;
I was calling this function in a loop for all 6.253 XMl files and every time I've got an error, but every time in different file, and when I ran the script again for only the one XML file which raised an error, it ran fine. I think that the problem is something about memory, but I don't know where a nd why it occurs.
I'm getting following error:
Error report:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00249: invalid external ID declaration
Error at line 1
ORA-06512: in "SYS.XMLTYPE", line 5
ORA-06512: in "GET_XML_BY_URL", line 47
ORA-06512: in line 29
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
GET_XML_BY_URL is a name given to described function. Does anybody have any experience wuth this kind of problem?
Best regards, Michal