Reading file with PL / SQL ends with error - stored-procedures

I work in a small procedure that should read a file and validate if the file is empty or does not exist. The validation works but I tried to implement the reading and it throws me the following error:
ORA-29284: file read error
ORA-06512: at "SYS.UTL_FILE", line 106
ORA-06512: at "SYS.UTL_FILE", line 746
ORA-06512: at "HCM_ESTRUCTURES", line 23
ORA-06512: at line 3
My code:
CREATE OR REPLACE PROCEDURE hcm_estructures AS
/*-Files validation variables-*/
l_file_exists BOOLEAN;
l_file_len NUMBER;
l_blocksize BINARY_INTEGER;
/*Variables read file*/
v_archivo utl_file.file_type;
v_linea clob;
v_path varchar2(100):= 'PREPROCESSOR_DIRECTORY';
BEGIN
utl_file.fgetattr(
location => v_path,
filename => 'Worker_19032019.dat',
fexists => l_file_exists,
file_length => l_file_len,
block_size => l_blocksize);
if l_file_exists then
if l_file_len > 0 then
--dbms_output.put_line('The file will read correctly');
v_archivo := utl_file.fopen ('PREPROCESSOR_DIRECTORY', 'Worker_19032019.dat', 'r',32767);
loop
utl_file.get_line (v_archivo, v_linea);
dbms_output.put_line (v_linea);
end loop;
--utl_file.fclose(v_archivo);
else
dbms_output.put_line('The file is empty');
end if;
else
dbms_output.put_line('The file does not exists');
end if;
END;
The procedure only prints a part of the contents of the file and then shows error.

UTL_FILE has limit to the length of the data.Seems like you are reading relatively larger file so might need CLOB datatype.
Can you rewrite your code to replace utl_file with DBMS_LOB utility. Below approach should resolve the error,
Use DBMS_LOB.LoadCLOBFromFile to read the data to CLOB variable.
Storing Files in Oracle DB's CLOB field
Once data is to CLOB variable, use substr(v_clob,1,32767) to read 32767 characters, continue substr untill you reach length of the v_clob.

Related

new to dbt and trying to learn how to execute procedure using dbt but getting error

create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
return message;
end;
call output_message('Hello World');
error I'm getting:
Database Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
001003 (42000): SQL compilation error:
syntax error line 2 at position 7 unexpected 'create'.
syntax error line 3 at position 0 unexpected 'returns'.
compiled SQL at target/run/dbt_project/example/my_first_dbt_model.sql
You cannot put code for a stored procedure in a model file (any .sql file in your models directory). dbt assumes that a model file contains a single select statement; it then wraps that select statement in DDL (usually a create table my_model as (...) statement), depending on your materialization config for that model.
Macros are more flexible. Generally, Stored Procedures aren't part of the dbt workflow, but there are some valid use-cases for them (along with UDFs).
You can create a output_message.sql file in your macros directory, and use the code you provided, wrapping it in a macro definition, like:
{% macro output_message(msg) %}
create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
return message;
end;
call output_message(msg);
{% endmacro %}
You can then call that macro in a post-hook or by using run-operation:
dbt run-operation output_message --args "{'msg': 'Hello World!'}"
You can customize your code using materialization link and I have followed a link to create ddl objects. You need to write macros for that.

MYSQL 6 - You have an error in your SQL Syntax 'Diagnostics Condition 1'

I have version 8 of MySQL but need to update a database stored procedure that is using 5. When I test this code in version 8 I do not receive any errors. However when I add it to the stored procedure on the the older version I receive the following error:
ERROR 1064: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'DIAGNOSTICS CONDITION 1 errstate = RETURNED_SQLSTATE, msg =
MESSAGE_TEXT;
This is the code that I have inserted that is causing the error.
DECLARE errstate CHAR(5) DEFAULT '00000';
DECLARE msg TEXT;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1
errstate = RETURNED_SQLSTATE,
msg = MESSAGE_TEXT;
END;
I could not find any documentation specific to version 5 for using GET DIAGNOSTICS CONDITION.

SAP HANA Export Statement

In the SAP Documentation is an EXPORT statement described.
Unfortunately I have the following error in a stored procedure:
Syntax error in procedure object: incorrect syntax near '#': line 18 col 8 (at pos 487)
Line 18 is:
EXPORT #MY_EXPORT AS CSV INTO '/path/filename' with replace;
How to fix this?
Full SQL
PROCEDURE "MY_SCHEMA"."my.package::EXPORTCVINTOCSV" ( )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
DEFAULT SCHEMA MY_SCHEMA
AS
BEGIN
--create local temporary table #MY_EXPORT as (
create table MY_EXPORT as (
SELECT a.*
FROM "_SYS_BIC"."my.package/myView" a
JOIN "_SYS_BIC"."my.package/myOtherView" b
ON a."CheckID" = b."CheckID"
WHERE a."SchedulingID" IS NOT NULL
);
EXPORT MY_EXPORT AS CSV INTO '/my/export/path' with replace;
END;
for unknown reasons IMPORT & EXPORT are not supported as procedure body, but as workaround you can wrap them into exec, .e.g.
EXEC 'EXPORT MY_EXPORT AS CSV INTO ''/my/export/path'' with replace';
the error message is confusing, but export of local temporary tables is anyway not supported.
If you try such statement outside the procedure you get:
SQL Error [7] [HY000]: SAP DBTech JDBC: [7]: feature not supported: cannot export local temporary table #MY_EXPORT

how to all Oracle Stored Proc in Package from Delphi

I have been given a stored procedure (developed by a 3rd party) to execute...
create or replace package body cux_ivr_task_assigupd_pkg is
-- Private type declarations
procedure cux_update_task_assgnments(
p_task_number in varchar2,
p_pressed_number in number,
x_err_code out varchar2,
x_err_message out varchar2) is
and trying to execute this procedure from a Delphi program. when trying to call with name cux_ivr_task_assigupd_pkg.cux_update_task_assgnments I get error
[Oracle][ODBC][Ora]ORA-06564: object
CUX_IVR_TASK_ASSIGUPD_PKG.CUX_UPDATE_TASK_ASSGNMENTS does not exist
ORA-06512: at "SYS.DBMS_DESCRIBE", line 117 ORA-06512: at line 1
and if I use name cux_update_task_assgnments then get error
[Oracle][ODBC][Ora]ORA-06550: line 1, column 7: PLS-00201: identifier
'CUX_UPDATE_TASK_ASSGNMENTS' must be declared ORA-06550: line 1,
column 7: PL/SQL: Statement ignored
I do not have access to the database itself - I am just a client that needs to be able to execute the procedure. I tried both names, as the people that manage the databases told me to try it one and then the other. So I not sure if it is permission related or ???
Ideally I would like to execute using an ADO command line
exec procedure-name(arg1, arg2, arg3, arg4)
but only error about incorrect syntax and the people responsible for the DB could not help?!?
Any clues about the above error?

Add File Summary tab data in runtime in NTFS in WinXP SP3

I have given up tryng to figure out the reason of this issue, but here is the story and hope you could give a tip...
As I develop unique app ( http://code.google.com/p/sedev ) and therefore I need to polish it.
I have to add File Summary ( very useful info in my opinion ) to any created files by the app, so I decided to go with NTFS compatible structure
edit: code snippet in which problem occurs:
if (FileExists(BaseLocation + LeftStr(GetSSWData, Length(GetSSWData)
- 1) + '.vkp') = True) then // add NTFS descriptive information to output file
try
SetFileSummaryInfo
(PWideChar(BaseLocation + LeftStr(GetSSWData, Length
(GetSSWData) - 1) + '.vkp')); // in my testcase files full path is: C:\Documents and Settings\Kludge\Desktop\sedevrpg\SEDEV_RPG_O_710.vkp
ShowMessagePos('Patch Created successfuly!' + #13#13 +
'Please verify created data to www.se-developers.net.',
ParamStr2X, ParamStr3Y);
MessageBeep(0);
except // exception handler does not even fire on exception ...
on Exception do
begin
if (WarningChBx.Checked = True) then
ShowMessagePos
('Unable to add Description to Output file (' +
BaseLocation + LeftStr(GetSSWData, Length(GetSSWData)
- 1) + '.vkp )', ParamStr2X, ParamStr3Y);
MessageBeep(0);
end;
end
final edit by author: Problem was in SetFileSummaryInfo(PWideChar('')) because after PWideChar conversion you got CHARACTER, not Array of Characters ( aka Strings ) therefore it is not valid path anymore!
Here is main tutorial: http://www.delphipages.com/articles/setting_file_summary_information-9228.html
edit: a better formatted tutorial is here.
BUT, the thing is that I just cannot get that damned FileName param to accept any string ... I have EOleSysError exception: "%1 cannot be found" no matter what.
Faulting operand is:
OleCheck(StgOpenStorageEx(PWideChar(FileName),
STGM_SHARE_EXCLUSIVE or STGM_READWRITE,
STGFMT_ANY,
0, nil, nil, #IID_IPropertySetStorage, stg));
What I do not understand is why it actually wants %1 MSDOS file name input.
I am not launching app from CMD therefore I highly doubt it needs additional param for File path ...
I have tried all possible String and PString conversions, also tried various param passing methods ... It just does not work ...
Any help appreciated!
I can only reproduce your case by specifying an invalid filename. Make sure that you include the full path in your filename.

Resources