plsql cannot use variables in sql select - sql

I am getting very fed up of APEX in recent days, i am trying to run a interactive report within application express and cannot seem to use variables i declare within my sql queries. Below is the error, i also included the code that works. the get_longlat() function is tested and works it returns a SDO_GEOMETRY data type.
ORA-06550: line 7, column 12: PLS-00306: wrong number or types of
arguments in call to '||' ORA-06550: line 7, column 1: PL/SQL:
Statement ignored
DECLARE
l_query VARCHAR2(4096);
l_location SDO_GEOMETRY := get_longlat(v('P2_POSTCODE'));
BEGIN
l_query := '
SELECT
"VENUE_ID",
"VENUE_NAME",
"CITY",
"VENUE_NO",
"POSTCODE",
dbms_lob.getlength("THUMBNAIL") "THUMBNAIL",
"DESCRIPTION",
SDO_GEOM.SDO_DISTANCE(G_LOCATION, ' || l_location || ',0.005,''unit=mile'') "G_LOCATION"
FROM "GAMEVENUE"
WHERE (SDO_WITHIN_DISTANCE(G_LOCATION,' || l_location || ',''distance=250 unit=mile'') = ''TRUE'');';
RETURN l_query;
This works
l_query := '
SELECT
"VENUE_ID",
"VENUE_NAME",
"CITY",
"VENUE_NO",
"POSTCODE",
dbms_lob.getlength("THUMBNAIL") "THUMBNAIL",
"DESCRIPTION",
SDO_GEOM.SDO_DISTANCE(G_LOCATION, MDSYS.SDO_GEOMETRY(2001,4326,SDO_POINT_TYPE(-4.1530439,50.371089,NULL),NULL,NULL),0.005,''unit=mile'') "G_LOCATION"
FROM "GAMEVENUE"
WHERE (SDO_WITHIN_DISTANCE(G_LOCATION,SDO_GEOMETRY(2001,4326,SDO_POINT_TYPE(-4.1530439,50.371089,null),null,null),''distance=250 unit=mile'') = ''TRUE'')';

Because SDO_GEOMETRY is not of type char or number( implicitly considerable as char ), you can't use it in direct concetenation.
Try this instead :
l_query := '
SELECT
"VENUE_ID",
"VENUE_NAME",
"CITY",
"VENUE_NO",
"POSTCODE",
dbms_lob.getlength("THUMBNAIL") "THUMBNAIL",
"DESCRIPTION",
SDO_GEOM.SDO_DISTANCE(G_LOCATION, MDSYS.SDO_GEOMETRY('||l_sdo_gtype||','||l_sdo_srid||',MDSYS.SDO_POINT_TYPE('||l_longitude||','||l_latitude||',NULL),NULL,NULL),0.005,''unit=mile'') "G_LOCATION"
FROM "GAMEVENUE"
WHERE (SDO_WITHIN_DISTANCE(G_LOCATION,SDO_GEOMETRY('||l_sdo_gtype||','||l_sdo_srid||',SDO_POINT_TYPE('||l_longitude||','||l_latitude||',null),null,null),''distance=250 unit=mile'') = ''TRUE'')';
where l_sdo_gtype,l_sdo_srid, l_longitude, l_latitude are of type number;

Related

SnowSQL, procedure - error 904 when using variable in insert statement

I'm working on snowflake procedure in snowsql and want to use variable as value in insert statement - something like that:
execute immediate $$
declare
select_statement string;
begin
select_statement := '''Some text''';
INSERT INTO SOME_TABLE(MESSAGE) values (select_statement);
exception
when statement_error then
return object_construct('Error type', 'STATEMENT_ERROR',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
when other then
return object_construct('Error type', 'Other error',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
end;
$$
;
{
"Error type": "STATEMENT_ERROR",
"SQLCODE": 904,
"SQLERRM": "SQL compilation error: error line 1 at position 102\ninvalid identifier 'SELECT_STATEMENT'",
"SQLSTATE": "42000"
}
I was trying to use single quote as well
select_statement := 'Some text';
and also without declaring it and using let
let select_statement := 'Some text';
Each time getting the same error...
please try this.
create or replace table SOME_TABLE(MESSAGE varchar2 );
select * from SOME_TABLE;
execute immediate $$
declare
select_statement string;
begin
select_statement := '''Some text''';
INSERT INTO SOME_TABLE(MESSAGE) values (:select_statement);
exception
when statement_error then
return object_construct('Error type', 'STATEMENT_ERROR',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
when other then
return object_construct('Error type', 'Other error',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
end;
$$;
This just needs some minor adjustments to the syntax. To use execute immediate as a string, create the string with one or more bind variables. Use the "using" clause to bind them in the execute immediate.
create or replace table some_table(message string);
execute immediate $$
declare
rs resultset;
select_statement string;
ins string default 'INSERT INTO SOME_TABLE(MESSAGE) values (?)';
begin
select_statement := 'Some text';
rs := (execute immediate :ins using (select_statement));
return table(rs);
exception
when statement_error then
return object_construct('Error type', 'STATEMENT_ERROR',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
when other then
return object_construct('Error type', 'Other error',
'SQLCODE', sqlcode,
'SQLERRM', sqlerrm,
'SQLSTATE', sqlstate);
end;
$$
;
The return of the table is optional, but helps with the return for programmatic access or human readability.
number of rows inserted
1

Parsing XML containing name space

I am having problems with parsing XML containing name-space.
This is my XML structure (snipped, with modified data):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02 ./camt.053.001.02.xsd">
<BkToCstmrStmt>
<Stmt>
<Ntry>
<Amt Ccy="EUR">0.0</Amt>
<CdtDbtInd>CCCC</CdtDbtInd>
<Sts>BBBB</Sts>
<BookgDt>
<Dt>2011-01-01</Dt>
</BookgDt>
<ValDt>
<Dt>2011-01-01</Dt>
</ValDt>
<AcctSvcrRef>325569685ASDAS</AcctSvcrRef>
<BkTxCd>
<Prtry>
<Cd>NOTPROVIDED</Cd>
</Prtry>
</BkTxCd>
<NtryDtls>
<TxDtls>
<Refs>
<EndToEndId>DD545454545-54545-54</EndToEndId>
<TxId>46545445G5GG54DD5S</TxId>
</Refs>
<RltdPties>
<Dbtr>
<Nm>TEST</Nm>
<PstlAdr>
<Ctry>JJ</Ctry>
<AdrLine>TEST ADD</AdrLine>
<AdrLine>TEST ADD2</AdrLine>
</PstlAdr>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>000000000000000</IBAN>
</Id>
</DbtrAcct>
<Cdtr>
<Nm>TEST NAME</Nm>
<PstlAdr>
<Ctry>JJ</Ctry>
<AdrLine>TEST ADD3</AdrLine>
<AdrLine>TEST ADD4</AdrLine>
</PstlAdr>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>22222222222222</IBAN>
</Id>
</CdtrAcct>
</RltdPties>
<Purp>
<Cd>IIII</Cd>
</Purp>
<RmtInf>
<Strd>
<CdtrRefInf>
<Ref>GG56565656565656</Ref>
</CdtrRefInf>
<AddtlRmtInf>TEST TEST 123</AddtlRmtInf>
</Strd>
</RmtInf>
<RltdDts>
<IntrBkSttlmDt>2011-01-01</IntrBkSttlmDt>
</RltdDts>
</TxDtls>
</NtryDtls>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document>
This is the code i use that works if root element is without namespace ():
DECLARE
l_clob CLOB;
l_bfile BFILE := BFILENAME('XML_IMPORT', 'test_import.xml');
l_dest_offset INTEGER := 1;
l_src_offset INTEGER := 1;
l_bfile_csid NUMBER := 0;
l_lang_context INTEGER := 0;
l_warning INTEGER := 0;
l_xml xmltype;
BEGIN
DBMS_LOB.createtemporary (l_clob, TRUE);
DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
DBMS_LOB.loadclobfromfile (
dest_lob => l_clob,
src_bfile => l_bfile,
amount => DBMS_LOB.lobmaxsize,
dest_offset => l_dest_offset,
src_offset => l_src_offset,
bfile_csid => l_bfile_csid ,
lang_context => l_lang_context,
warning => l_warning);
DBMS_LOB.fileclose(l_bfile);
l_xml := xmltype(l_clob);
BEGIN
FOR r IN (
SELECT ExtractValue(Value(p),'/Ntry/Amt/text()') as TEMP_COL1
,ExtractValue(Value(p),'/Ntry/Amt/#Ccy/text()') as TEMP_COL2
,ExtractValue(Value(p),'/Ntry/ValDt/Dt/text()') as TEMP_COL3
,ExtractValue(Value(p),'/Ntry/BookgDt/Dt/text()') as TEMP_COL4
FROM TABLE(XMLSequence(Extract(l_xml,'/Document/BkToCstmrStmt/Stmt/Ntry'))) p
)
LOOP
dbms_output.put_line('Some value 1: ' || r.TEMP_COL1);
dbms_output.put_line('Some value 2: ' || r.TEMP_COL2);
dbms_output.put_line('Some value 3: ' || r.TEMP_COL3);
dbms_output.put_line('Some value 4: ' || r.TEMP_COL4);
END LOOP;
END;
END;
I would like to know how to modify my code to work with name space.
Google provided few examples but so far i had no luck implementing them into my solution.
I believe you need to pass the namespace to both the Extract() and ExtractValue() functions e.g.
FOR r IN (
SELECT ExtractValue(Value(p),'/Ntry/Amt/text()', 'xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"') as TEMP_COL1
,ExtractValue(Value(p),'/Ntry/Amt/#Ccy','xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"') as TEMP_COL2
,ExtractValue(Value(p),'/Ntry/ValDt/Dt/text()','xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"') as TEMP_COL3
,ExtractValue(Value(p),'/Ntry/BookgDt/Dt/text()','xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"') as TEMP_COL4
FROM TABLE(XMLSequence(Extract(l_xml,'/Document/BkToCstmrStmt/Stmt/Ntry', 'xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"'))) p
)
LOOP
dbms_output.put_line('Some value 1: ' || r.TEMP_COL1);
dbms_output.put_line('Some value 2: ' || r.TEMP_COL2);
dbms_output.put_line('Some value 3: ' || r.TEMP_COL3);
dbms_output.put_line('Some value 4: ' || r.TEMP_COL4);
END LOOP;
I don't think there is a way to specify a default namespace for the ExtractValue function, so my personal preference would be to do something like this instead which avoids repeatedly declaring the namespace:
FOR r IN (
SELECT p.temp_col1,
p.temp_col2,
p.temp_col3,
p.temp_col4
FROM xmltable(
--define a default namespace to be used for all values
xmlnamespaces(
DEFAULT 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.02'
),
--define an xpath expression for the values you want to extract
'/Document/BkToCstmrStmt/Stmt/Ntry'
--pass the xml type in here
PASSING l_xml
--declare the columns you would like to extract and the formats they are expected to be in
COLUMNS
temp_col1 VARCHAR2(128) path '/Ntry/Amt/text()',
temp_col2 VARCHAR2(128) path '/Ntry/Amt/#Ccy',
temp_col3 VARCHAR2(128) path '/Ntry/ValDt/Dt/text()',
temp_col4 VARCHAR2(128) path '/Ntry/BookgDt/Dt/text()'
) p
)
LOOP
dbms_output.put_line('Some value 1: ' || r.temp_col1);
dbms_output.put_line('Some value 2: ' || r.temp_col2);
dbms_output.put_line('Some value 3: ' || r.temp_col3);
dbms_output.put_line('Some value 4: ' || r.temp_col4);
END LOOP;

I want to extract the tag name using sql from table with XML stored as clob. (ORACLE)

Sample XML as below:
<Root>
...
<XMLNSC>
...
<SOAP-ENV:Envelope>
...
<SOAP-ENV:Body>
<typesNS0:getABCD xmlns:typesNS0="http://xxx.xx/xxxxxx/xxxxxxxxx/x/" xmlns:xalan="http://xml.apache.org/xslt">
last tag typesNS0:getABCD want to select
select xmltype(a).extract('//typesNS0:getABCD','xmlns:typesNS0="http://xxx.xx/xxxxxx/xxxxxxxxx/x/"')
from (
select
'<Root xmlns:SOAP-ENV="http://a.b.org/">
<XMLNSC />
<SOAP-ENV:Envelope/>
<SOAP-ENV:Body/>
<typesNS0:getABCD xmlns:typesNS0="http://xxx.xx/xxxxxx/xxxxxxxxx/x/" xmlns:xalan="http://xml.apache.org/xslt">123</typesNS0:getABCD>
</Root>' a from dual
)
You may run below script if you want get exact tag value;
DECLARE
vs_Xml VARCHAR2(32000):= '<Root xmlns:SOAP-ENV="http://a.b.org/">
<XMLNSC />
<SOAP-ENV:Envelope/>
<SOAP-ENV:Body/>
<typesNS0:getABCD xmlns:typesNS0="http://xxx.xx/xxxxxx/xxxxxxxxx/x/" xmlns:xalan="http://xml.apache.org/xslt">123</typesNS0:getABCD>
</Root>';
vx_ParameterList XMLTYPE;
vx_Parameter XMLTYPE;
vn_ParameterIndex NUMBER;
vs_Key VARCHAR2(64);
vs_XPath VARCHAR2(255);
vs_Value VARCHAR2(10000);
BEGIN
vx_ParameterList := xmltype(vs_Xml);
vn_ParameterIndex := 1;
vs_XPath := '/Root';
WHILE vx_ParameterList.existsNode(vs_XPath || '[' || vn_ParameterIndex || ']') = 1 LOOP
vx_Parameter := vx_ParameterList.extract(vs_XPath || '[' || vn_ParameterIndex || ']');
vs_Value := vx_Parameter.extract('//typesNS0:getABCD/text()','xmlns:typesNS0="http://xxx.xx/xxxxxx/xxxxxxxxx/x/"').GetStringVal();
vn_ParameterIndex := vn_ParameterIndex + 1;
dbms_output.put_line(vs_Value);
END LOOP;
END;

PL/SQL Numeric or value error: character to number conversion error

Procedure Code:
CREATE OR REPLACE PROCEDURE GetOrder(
p_Order IN NUMBER,
p_OrderDate OUT DATE,
p_CusNbr OUT NUMBER,
p_OrderOut OUT NUMBER,
p_Name OUT VARCHAR2,
p_Address OUT VARCHAR2,
p_City OUT VARCHAR2,
p_State OUT CHAR,
p_Zip OUT NUMBER,
p_Itm OUT NUMBER,
p_Desc OUT VARCHAR2,
p_Qty OUT NUMBER,
p_Price OUT NUMBER)
AS
v_OrderDate ord.ord_date%type;
v_CusNbr ord.Cus_nbr%type;
v_Order ord.Ord_nbr%type;
v_Name cus.cus_nme%type;
v_Address cus.str_adr%type;
v_City zip.city%type;
v_state zip.st%type;
v_Zip zip.zip%type;
v_Itm itm.itm_nbr%type;
v_Desc itm.ITM_DSC%TYPE;
v_Qty ord_itm.ord_Qty%type;
v_Price itm.ord_itm_price%type;
BEGIN
SELECT O.ORD_NBR, C.CUS_NBR, O.ORD_DATE, C.CUS_NME, C.STR_ADR, Z.CITY, Z.ST, I.ITM_NBR, I.ITM_DSC, OI.ORD_QTY, I.ORD_ITM_PRICE
INTO
v_Order, v_CusNbr, v_OrderDate, v_Name, v_Address, v_Zip, v_state, v_Itm, v_Desc, v_Qty, v_Price
FROM ITM I JOIN ORD_ITM OI ON (I.ITM_NBR = OI.ITM_NBR)
JOIN ORD O ON (OI.ORD_NBR = O.ORD_NBR)
JOIN CUS C ON (O.CUS_NBR = C.CUS_NBR)
JOIN ZIP Z ON (C.ZIP_ADR = Z.ZIP)
WHERE O.ORD_NBR = p_Order;
DBMS_OUTPUT.PUT_LINE('ILLINOIS COMPUTERS');
DBMS_OUTPUT.PUT_LINE('CUSTOMER ORDER FORM');
DBMS_OUTPUT.PUT_LINE(v_Order || v_OrderDate || v_CusNbr);
DBMS_OUTPUT.PUT_LINE('Name: ' || v_Name);
DBMS_OUTPUT.PUT_LINE('Address: ' || v_Address);
DBMS_OUTPUT.PUT_LINE('City: ' || v_City || ' State : ' || v_state || ' Zip: ' || v_Zip);
DBMS_OUTPUT.PUT_LINE('Item No.' || 'Description' || 'Quantity' || 'Price');
DBMS_OUTPUT.PUT_LINE(v_Itm || v_Desc || v_Qty || v_Price);
END GetOrder;
/
And when I call the procedure:
DECLARE
p_OrderNbr NUMBER := &ordernumber;
p_OrderDateOutput DATE;
p_CusNbrOutput NUMBER;
p_OrderNbrOutput NUMBER;
p_NameOutput cus.cus_nme%type;
p_AddressOutput cus.str_adr%type;
p_CityOutput zip.city%type;
p_StateOutput CHAR;
p_ZipOutput NUMBER;
p_ItmOutput NUMBER;
p_DescOutput itm.itm_dsc%type;
p_QtyOutput NUMBER;
p_PriceOutput NUMBER;
begin
GetOrder(p_OrderNbr,
p_OrderDateOutput,
p_CusNbrOutput,
p_OrderNbrOutput,
p_NameOutput,
p_AddressOutput,
p_CityOutput,
p_StateOutput,
p_ZipOutput,
p_ItmOutput,
p_DescOutput,
p_QtyOutput,
p_PriceOutput);
END;
/
I'm getting
ORA-06502 error: numeric or value error: character to number
conversion error.
I believe all my parameters are in order so I'm not getting conflicting variable assignments.
I ran this query seperately to make sure I'm getting the right output and it works fine.
SELECT O.ORD_NBR, C.CUS_NBR, O.ORD_DATE, C.CUS_NME, C.STR_ADR, Z.CITY, Z.ST, I.ITM_NBR, I.ITM_DSC, OI.ORD_QTY, I.ORD_ITM_PRICE
--INTO
--v_Order, v_CusNbr, v_OrderDate, v_Name, v_Address, v_Zip, v_state, v_Itm, v_Desc, v_Qty, v_Price
FROM ITM I JOIN ORD_ITM OI ON (I.ITM_NBR = OI.ITM_NBR)
JOIN ORD O ON (OI.ORD_NBR = O.ORD_NBR)
JOIN CUS C ON (O.CUS_NBR = C.CUS_NBR)
JOIN ZIP Z ON (C.ZIP_ADR = Z.ZIP)
WHERE O.ORD_NBR = 100;
Select list says
... C.STR_ADR, Z.CITY, Z.ST, ...
Into list says
... v_Address, v_Zip, v_state ...
Seems you got the wrong field in Z table.
Unless Z.CITY is the numeric zip code?

how to upload any file from local machine to database server file system using SQL developer

Here is my Code:
I need to upload a file from the local machine to the file system
Also, i got an error when opening the file attached in the oracle application (ORA-01403: no data found
FRM-40735: WHEN-BUTTON-PRESSED trigger raised unhandled exception
ORA-01403.)
CREATE OR REPLACE DIRECTORY in_file_loc AS '/oracle/TEST';
CREATE TABLE test_files (p_id NUMBER,
pl_name VARCHAR2(100),
pl_pict BLOB);
DECLARE
x_blob BLOB;
fils BFILE := BFILENAME ('IN_FILE_LOC', 'aa.pdf');
blob_length INTEGER;
BEGIN
-- Obtain the size of the blob file
DBMS_LOB.fileopen (fils, DBMS_LOB.file_readonly);
blob_length := DBMS_LOB.getlength (fils);
DBMS_LOB.fileclose (fils);
-- Insert a new record into the table containing the
-- filename you have specified and a LOB LOCATOR.
-- Return the LOB LOCATOR and assign it to x_blob.
INSERT INTO test_files (p_id,pl_name,pl_pict)
VALUES (7, 'aa.pdf', EMPTY_BLOB ())
RETURNING pl_pict
INTO x_blob;
-- Load the file into the database as a BLOB
DBMS_LOB.OPEN (fils, DBMS_LOB.lob_readonly);
DBMS_LOB.OPEN (x_blob, DBMS_LOB.lob_readwrite);
DBMS_LOB.loadfromfile (x_blob, fils, blob_length);
-- Close handles to blob and file
DBMS_LOB.CLOSE (x_blob);
DBMS_LOB.CLOSE (fils);
COMMIT;
-- Confirm insert by querying the database
-- for LOB length information and output results
blob_length := 0;
SELECT DBMS_LOB.getlength (pl_pict)
INTO blob_length
FROM test_files
WHERE pl_name = 'aa.pdf';
DBMS_OUTPUT.put_line ('Successfully inserted BLOB ''' ||'aa.pdf' || ''' of size ' || blob_length || ' bytes.');
END;
DECLARE
TYPE result_set_type IS REF CURSOR;
l_name VARCHAR2 (100);
l_doc_size NUMBER;
l_result_set_curr result_set_type;
x_access_id NUMBER;
x_file_id NUMBER;
p_file_name VARCHAR2 (100) := 'aa.pdf';
PROCEDURE load_file_details (p_name IN VARCHAR2, result_set_curr OUT result_set_type)
AS
l_error VARCHAR2 (2000);
BEGIN
INSERT INTO fnd_lobs_document
(NAME, mime_type, doc_size, content_type, blob_content)
SELECT pl_name, 'application/pdf', DBMS_LOB.getlength (pl_pict), 'BINARY', '(BLOB)'
FROM test_files
WHERE pl_name = 'aa.pdf';
OPEN result_set_curr FOR
SELECT blob_content
FROM fnd_lobs_document
WHERE NAME = p_name;
EXCEPTION
WHEN OTHERS
THEN
NULL;
l_error := 'LOAD_FILE_DETAILS - OTHERS' || SUBSTR (SQLERRM, 2000);
DBMS_OUTPUT.put_line (l_error);
END load_file_details;
PROCEDURE upload_file (v_filename IN VARCHAR2, x_access_id OUT NUMBER, x_file_id OUT NUMBER)
AS
v_access_id NUMBER;
v_file_id NUMBER;
x_errbuf VARCHAR2 (200);
BEGIN
v_access_id := fnd_gfm.authorize (NULL);
x_access_id := v_access_id;
DBMS_OUTPUT.put_line ('Access id :' || v_access_id);
-- The function fnd_gfm.confirm_upload return the file id
v_file_id :=
fnd_gfm.confirm_upload (access_id => v_access_id
, file_name => v_filename
, program_name => 'TEST'
, program_tag => 'TEST'
, expiration_date => NULL
, LANGUAGE => 'US'
, wakeup => TRUE
);
x_file_id := v_file_id;
DBMS_OUTPUT.put_line ('File id :' || x_file_id);
EXCEPTION
WHEN OTHERS
THEN
x_errbuf := 'Procedure upload_file errored out with the following error : ' || SQLERRM;
DBMS_OUTPUT.put_line (x_errbuf);
END upload_file;
BEGIN
fnd_global.apps_initialize (0, 20634, 401);
load_file_details (p_name => p_file_name, result_set_curr => l_result_set_curr);
upload_file (v_filename => p_file_name, x_access_id => x_access_id, x_file_id => x_file_id);
COMMIT;
END;
DECLARE
TYPE result_set_type IS REF CURSOR;
l_name VARCHAR2 (100);
l_doc_size NUMBER;
l_result_set_curr result_set_type;
x_access_id NUMBER;
x_file_id NUMBER;
p_file_name VARCHAR2 (100) := 'aa.pdf';
PROCEDURE attach_file (p_access_id IN NUMBER, p_file_Id in number, p_filename IN VARCHAR2)
IS
BEGIN
fnd_webattch.add_attachment (seq_num => 900
,category_id => 1
,document_description => 'Test1'
,datatype_id => 5
,text => NULL
,file_name => p_filename
,url => NULL
,function_name => 'INVIDITM'
,entity_name => 'MTL_SYSTEM_ITEMS'
,pk1_value => 85 --organization_id
,pk2_value => 10 --Inventory_item_Id
,pk3_value => NULL
,pk4_value => NULL
,pk5_value => NULL
,media_id => p_file_id
,user_id => 0
,usage_type => 'O'
);
DBMS_OUTPUT.put_line ('File Attached!');
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('error in loading the attachement');
END attach_file;
BEGIN
fnd_global.apps_initialize (0, 20634, 401);
attach_file (p_access_id => x_access_id, p_file_id=>x_file_id,p_filename => p_file_name);
COMMIT;
END;
I believe we are mixing context here. I assume Local machine here means the machine that you build the PL/SQL - only issue here is when you run it runs within the server context. So i would either FTP the file to the server or load your file content to an oracle table in a different way.