send mail with existing file as attachments using oracle procedure - oracle

DECLARE
attachments shr_pkg_send_mail.array_attachments:=shr_pkg_send_mail.array_attachments();
b_input_file BFILE:= BFILENAME('mount_dir', 'test02.txt');
c_output_file CLOB;
BEGIN
--DBMS_OUTPUT.PUT_LINE(c_output_file);
dbms_lob.open(b_input_file, DBMS_LOB.LOB_READONLY);
-- DBMS_OUTPUT.PUT_LINE('1');
dbms_lob.createtemporary(lob_loc => c_output_file, cache => false);
--DBMS_OUTPUT.PUT_LINE('2');
dbms_lob.open(c_output_file, DBMS_LOB.LOB_READWRITE);
--DBMS_OUTPUT.PUT_LINE('3');
dbms_lob.loadfromfile(c_output_file, b_input_file, DBMS_LOB.LOBMAXSIZE);
--DBMS_OUTPUT.PUT_LINE('4');
dbms_lob.close(b_input_file);
--DBMS_OUTPUT.PUT_LINE('5');
attachments.extend(1);
attachments(1).attach_name := 'test02.txt';
attachments(1).data_type := 'text/plain';
attachments(1).attach_content := c_output_file; SHR_PKG_SEND_MAIL.SEND_MAIL('EthicsandComplianceITSupport_ORG#dl.mgd.novartis.com','mansi.kekre#novartis.com','test','test',attachments => attachments);
dbms_lob.close(c_output_file);
END ;
ERROR
ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 1014
ORA-06512: at line 8

Get the directory path
select directory_path from all_directories where directory_name='MOUNT_DIR'
Check if this path exists on database server and oracle has read access to it.
Check if the file 'test02.txt' exits in this path and is accessible.
Give grants to this directory
GRANT READ, WRITE ON DIRECTORY MOUNT_DIR TO <some_user>;
And here is something interesting, how to see files in directory with select, but you should have access to the SYS user.

Related

Oracle 11g data pump import job trying to create .DB files on the wrong drive

I know absolutely nothing about Oracle until attempting this restore. I have a .DMP file that I must restore. After many failed attempts I have issued the command:
alter system set DB_CREATE_FILE_DEST='E:\app\****\oradata\orcl';
because the data pump job keeps trying to put files on a D:\ that I cannot write to (it's a DVD drive). This DMP was created in Oracle 11g so that is what I've installed.
The error I get (many, many times) is like so:
O/S-Error: (OS 3) The system cannot find the path specified.
Failing sql is:
CREATE TABLESPACE "E:\APP\******\ORADATA\ORCL" DATAFILE 'D:\ORACLE\DATA\RRAEMR\LOGICIAN.DB' SIZE 251658240 AUTOEXTEND ON NEXT 5242880 MAXSIZE 2097152000,'D:\ORACLE\DATA\RRAEMR\LOGICIAN_DATA_0002.DB' SIZE 10
ORA-39083: Object type TABLESPACE failed to create with error:
ORA-01119: error in creating database file 'D:\ORACLE\DATA\RRAEMR\LOGIC_IX.DB'
ORA-27040: file create error, unable to create file
OSD-04002: unable to open file
O/S-Error: (OS 3) The system cannot find the path specified.
When I look at ALL_DIRECTORIES there is no directory pointed at D:\, all point to E:\ or C:\ or X:.
I should add that during the data pump import wizard I have tried remapping the tablespace files to where I want them and I do see some files landing there. I do not understand if this can be done for datafiles too. It looks like it should, but when adding a row and clicking it no datafile name is supplied like it was for tablespaces.
How can I restore this dump on a different drive?
EDIT:
Ok I am firing off another data pump import job without doing any remapping and within the first few seconds the log file already has errors like:
Failing sql is:
CREATE UNDO TABLESPACE "UNDOTBS" DATAFILE 'D:\ORACLE\DATA\RRAEMR\UNDOTBS01.DB' SIZE 20971520 AUTOEXTEND ON NEXT 5242880 MAXSIZE 2097152000,'D:\ORACLE\DATA\RRAEMR\UNDOTBS02.DB' SIZE 10485760 AUTOEXTEND ON NEX
ORA-39083: Object type TABLESPACE failed to create with error:
ORA-01119: error in creating database file 'D:\ORACLE\DATA\RRAEMR\TEMP_0003.DB'
ORA-27040: file create error, unable to create file
OSD-04002: unable to open file
O/S-Error: (OS 3) The system cannot find the path specified.
So it's still wanting to put on the D:. I captured the SQL for the job and here it is:
set scan off
set serveroutput on
set escape off
whenever sqlerror exit
DECLARE
s varchar2(1000);
h1 number;
errorvarchar varchar2(100):= 'ERROR';
tryGetStatus number := 0;
begin
h1 := dbms_datapump.open (operation => 'IMPORT', job_mode => 'FULL', job_name => 'IMP_SD_44-09_53_59', version => 'COMPATIBLE');
tryGetStatus := 1;
dbms_datapump.set_parallel(handle => h1, degree => 1);
dbms_datapump.add_file(handle => h1, filename => 'IMPORT-'||to_char(sysdate,'hh24_mi_ss')||'.LOG', directory => 'DMPDIR', filetype=>DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 1);
dbms_datapump.add_file(handle => h1, filename => 'RRA.DMP', directory => 'DMPDIR', filetype => 1);
dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
dbms_datapump.set_parameter(handle => h1, name => 'REUSE_DATAFILES', value => 0);
dbms_datapump.set_parameter(handle => h1, name => 'TABLE_EXISTS_ACTION', value => 'REPLACE');
dbms_datapump.set_parameter(handle => h1, name => 'SKIP_UNUSABLE_INDEXES', value => 0);
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
dbms_datapump.detach(handle => h1);
errorvarchar := 'NO_ERROR';
EXCEPTION
WHEN OTHERS THEN
BEGIN
IF ((errorvarchar = 'ERROR')AND(tryGetStatus=1)) THEN
DBMS_DATAPUMP.DETACH(h1);
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
RAISE;
END;
/

how i use plsql for sending csv file via FTP?

For the development of a solution of replication and consolidation between 2 schema oracle 10g distant. I want to use the FTP API (ftp.pks, ftp.pkb) to transfer a CSV file to an FTP server. when performing the dedicated procedure for that I have the error
ORA-31024: Parser initialization failed with LPX-54
error while parsing a stream to XOB
and I find no solution, can help me!
PROCEDURE ftpTransfer IS
vConn UTL_TCP.connection;;
vFileName VARCHAR2(50);
vToFile VARCHAR2(200);
BEGIN
fileTransfer(vFileName);
IF vFileName IS NULL THEN
raise_application_error(-20002,'FTP - Erreur de Fichier');
END IF;
vToFile := RPLPKG_PARAMETERS.gServer.sDir||vFileName;
vConn := ftp.login(RPLPKG_PARAMETERS.gServer.sHost, RPLPKG_PARAMETERS.gServer.sHost, RPLPKG_PARAMETERS.gServer.sPort, RPLPKG_PARAMETERS.gServer.sPsw);
ftp.ascii(p_conn => vConn);
ftp.put(p_conn => vConn,
p_from_dir => 'RPLDIRECTORY',
p_from_file => 'HRM10122019.csv',
p_to_file => '/JOURNALS/HRM10122019.csv');
ftp.logout(vConn);
END ftpTransfer;
screenshot

Oracle Datapump: Invalid operation at line 6224

I've a Oracle dump file that I'm trying to import to AWS RDS Oracle 12.1.0.2.v17
database.
The dump file looks like this:
$ strings EXPDP.dmp | head -n 6
_|lM
"PACOPROD"."SYS_EXPORT_SCHEMA_01"
IBMPC/WIN_NT64-9.1.0
unicode
AL32UTF8
12.01.00.00.00
The commands I'm running is:
DECLARE
hdnl NUMBER;
BEGIN
hdnl := DBMS_DATAPUMP.OPEN( operation => 'IMPORT', job_mode => 'SCHEMA', job_name=>null, version=>'COMPATIBLE');
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.dmp', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.ku$_file_type_dump_file);
DBMS_DATAPUMP.METADATA_FILTER(hdnl,'SCHEMA_EXPR','IN (''PACOPROD'')');
DBMS_DATAPUMP.START_JOB(hdnl);
END;
/
The response is:
Error report -
ORA-39002: invalid operation
ORA-06512: at "SYS.DBMS_DATAPUMP", line 6224
ORA-06512: at line 7
The closes similar issue I've found is this, even though it's not exactly the same error message and in my case both source and target db is running 12.1.
I think the issue is one of the following:
A) The DMP file is corrupt.
B) I'm doing something wrong.
I've no clue how to get further though. Where shall I dig or what should I try to go forward?
Try to add a log file to the operation. It some times contain more information:
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.log', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.KU$_FILE_TYPE_LOG_FILE);

How to let user to browse to a file to be copied with Inno Setup

I need user to browse to a file, select it, and then have this file copied from selected source to app folder.
Following this post
How to show/use the user selected app path {app} in InputDirPage in Inno Setup?
and Inno Setup documentation, i came to this piece of code:
[Files]
Source: {code:GetDBPath}; DestDir: "{app}"; Flags: confirmoverwrite uninsneveruninstall;
[Code]
var
SelectDBPage: TInputDirWizardPage;
DBPath: String;
procedure InitializeWizard;
begin
SelectDBPage := CreateInputDirPage(wpSelectDir, 'Select file', 'Select file', 'Select file', False, '');
SelectDBPage.Add('');
SelectDBPage.Values[0] := ExpandConstant('{src}\DB.FDB');
DBPath := SelectDBPage.Values[0];
end;
function GetDBPath():String;
begin
Result := DBPath;
end;
My problem is to retrieve file path. At instruction 'Source: {code:GetDBPath}' i get an 'Unknown filename prefix {code:' error.
How can I refer to the selected file path in [File] section?
Thank you
You need to add the external flag to the [Files] entry. This means the source will be evaluated at run time and CAN include {code:...} constants.
You're also not getting the correct value in your GetDBPath() function. You're returning the value of DBPath that isn't updated after creating the page, instead of getting the latest value form the SelectDBPage.Values[0].

Problem creating a Directory object in Oracle

The code is this:
Originally:(http://www.oracle-base.com/articles/misc/FTPFromPLSQL.php)
The approach uses a combination of the UTL_TCP and UTL_FILE packages to create a simple FTP API (ftp.pks, ftp.pkb). Once the API is loaded into the appropriate schema simple FTP commands can be initiated as follows:
CREATE OR REPLACE DIRECTORY my_docs AS '/u01/app/oracle/';
SET SERVEROUTPUT ON SIZE 1000000
#c:\ftp.pks
#c:\ftp.pkb
-- Send an ASCII file to a remote FTP server.
DECLARE
l_conn UTL_TCP.connection;
BEGIN
l_conn := ftp.login('ftp.company.com', '21', 'ftpuser', 'ftppassword');
ftp.ascii(p_conn => l_conn);
ftp.put(p_conn => l_conn,
p_from_dir => 'MY_DOCS',
p_from_file => 'test_get.txt',
p_to_file => '/u01/app/oracle/test_put.txt');
ftp.logout(l_conn);
END;
/
The problem is that when I try to create the directory object I get an error saying that Create symbol wasnt expected.
where this line should be created?
Is there anything preceding the create statement line in your script? It looks like there might be something you left off the post.

Resources