External Procedure Returns Bad String
Hello,
I have an strange issue. I have an external procedure that returns an string but when i call it Oracle gets an string of zero's ascii chars. The length it`s ok but the content not.... The wrapper function is
PROCEDURE getString(returnValue OUT VARCHAR2) AS
LANGUAGE C
LIBRARY "UFDs"
NAME "getString"
WITH CONTEXT
PARAMETERS (
context,
returnValue STRING,
returnValue INDICATOR short,
returnValue LENGTH int
And the C code is
DLLIMPORT void getString(OCIExtProcContext* context,
char* returnValue,
short* returnValue_ind,
int* returnValue_len )
returnValue = (char*)OCIExtProcAllocCallMemory(context, 13);
//returnValue[0] = '\0';
strcpy(returnValue,"hello from c");
/* I have test this to gen a file an the string is OK
char buffer[500];
strcpy(buffer,"echo ");
strcat(buffer,returnValue);
strcat(buffer," >c:\\sal.txt");
system(buffer);
*returnValue_len = strlen(returnValue);
*returnValue_ind = (short)OCI_IND_NOTNULL;
return;
When i call this from oracle i get an string of size 12 but the string has invalid chars (zero ascii chars). Could it be a problem with charset conversion? Anybody has an example or idea?.
Regards
Can you please post your query / stored procedure you are using? Very possible reason includes one among your substring (within the concat) is null and making the final output to be null. Size, esp 800 shouldn't matter.
Similar Messages
-
We have an external procedure running fine on 8.1.7 on VMS. After compiling and linking succesfully under 10.1.0, I get ORA-06521 PL/SQL: Error mapping function and ORA-06522: ERROR - vms_dlsym for file x, where x in the filename of the linked executable. Another external procedure that does not connect to the 10.1.0 database runs fine. What could be causing this error in Server 10.1.0 on VMS?
Thanks,
DaveHere is the code to create the function:
CREATE OR REPLACE FUNCTION f1
(h_file_name IN VARCHAR2)
RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY l1
NAME "f1"
LANGUAGE C
WITH CONTEXT
PARAMETERS
(CONTEST,
h_file_name string);
Here is the beginning of the Pro*C:
int f1(epctx, h_file_name)
OCIExtProcContext *epctx;
char h_file_name[70];
char h_line_txt [251];
int lineno;
FILE *fptr;
/* register the connection context ... */
EXEC SQL REGISTER CONNECT USING :epctx;
The function loads a flat file into the database. It is probably not related but are unable to SQLPLUS/ or SQLLDR/ into the database from an OS autheniticated account (get ORA-12547: TNS:lost contact.) Thanks for taking the time to look at this. There aren't many people trying this on VMS, I'd bet. -
Not able to get Oracle stored procedure return value passed to Powerbuilder
I have an Oracle Stored Procedure that receives a string value and returns a string value.. When I call it from Powerbuilder, it executes but does not send the return value of a string back. I am trying to encrypt a string in Powerbuilder, pass it to a .net web page and then decrypt so I can check the security tables for permissions to view the web page. I have tried creating a simple stored procedure that takes a string and returns a string to Powerbuilder; but even that is not working. Any suggesstions?
Oracle Procedure:
CREATE OR REPLACE
PROCEDURE TESTINOUT_VARCHAR
( P_STRING IN VARCHAR2, P_OUT OUT VARCHAR2)
IS
BEGIN
P_OUT := P_STRING || 'TESTING';
END TESTINOUT_VARCHAR;
Powerbuilder Call:
string p_string =' '
Declare TestingString procedure for TESTINOUT_VARCHAR(:ls_group, :p_out) using SQLCA
Execute TestingString;
IF SQLCA.CODE = 0 THEN
FETCH TestingString into:p_out;
End If
p_string = p_out;Hello John,
I'm not sure if you already found a solution using an ODBC connection.
Below the solution with an RPC call:
Create a user object (uo_trans) of type transaction with the following local external function:
subroutine TESTINOUT_VARCHAR(string P_STRING,ref string P_OUT) RPCFUNC
Execute this script
uo_trans l_transaction
string ls_outparam
l_transaction = CREATE uo_trans
// Profile ODBC_ORA
l_transaction.DBMS = "ODBC"
l_transaction.AutoCommit = False
l_transaction.DBParm = "ConnectString='DSN=ODBC_ORA;UID=system;PWD=<xxxxxx>'"
connect using l_transaction;
ls_outparam = space (30)
l_transaction.testinout_varchar( sle_1.text, ls_outparam)
messagebox("OUT parameter", ls_outparam)
disconnect using l_transaction;
DESTROY l_transaction -
Not able to create Oracle External Procedure to Run Host Commands
Trying to follow this article
http://timarcher.com/node/9
Its related to
Oracle External Procedure to Run Host Commands
steps
1)mkdir –p /u01/app/usfapp/oracle_external_procs/oracle_host
2)
Author is suggesting to create a file
but header file is missing in very first line... may be not sure..say it is <stdio.h>Create a file named oracle_host.c. The contents of this file will be:
#include
int RunCmd(char *cmd)
return(system(cmd));
4) Create the file named makefile. The contents of this file will be:
oracle_host: oracle_host.o
gcc -shared -o oracle_host.so oracle_host.o
$ cat makefile
oracle_host: oracle_host.o
gcc -shared -o oracle_host.so oracle_host.o
5)
Now run the command make
The output on my server looks like:
[u01/app/usfapp/oracle_external_procs/oracle_host]
banner@usfbannerte [TRNG] > make
gcc -shared -o oracle_host.so oracle_host.o
here I stuck .. Not able to run this step ]$ make
gcc -shared -o oracle_host.so oracle_host.o
/usr/bin/ld: oracle_host.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
oracle_host.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [oracle_host] Error 1
Any one has any idea what went wrong
Any other link related to this is most welcomed.
Please suggest ...hi
please update
or
provide any other link / document for
Oracle External Procedure to Run Host Commands
--using c
Thanks in advance. -
SQL Developer and External Procedures not in tree.
Does sql Dveloper add external procedures to the object browser tree? I have SQL Developer 1.5 and if you have external procedures/functions before your regular PLSQL objects they will not display in the tree. I can make the tree work but the tree still doesn't capture the externals. Am I doing something wrong or should this be a feature request?
VSAMPLE1 shows the problem.
VSAMPLE2 is a try to resolve...
/* the problem.. */
CREATE OR REPLACE package VSAMPLE_1 IS
PROCEDURE foobar(feedname IN VARCHAR2);
END VSAMPLE_1;
CREATE OR REPLACE PACKAGE BODY VSAMPLE_1
IS
* Function Name:- canread
* Description :-This function checks the file will give any error or not while reading
FUNCTION canread (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.canRead (java.lang.String) return int';
* Function Name:- is_exist
* Description :-This function checks the existance of the filein the required folder
FUNCTION is_exist (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.exists (java.lang.String) return int';
* Function Name:- isDirectory
* Description :-This function checks the name provided by the user is a directory or not
FUNCTION isDirectory (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.isDirectory (java.lang.String) return int';
* Function Name:- isFile
* Description :-This function checks the name provided by the user is a file or not
FUNCTION isFile (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.isFile (java.lang.String) return int';
* Function Name:- isExist
* Description :-This function checks the existance of file,correctness of the directory provided by the user.
* @Param file_name :- File Name in directory
* @return retcode :- Error checking while uploading the feed.
FUNCTION isExist(file_name IN VARCHAR2,
is_dir BOOLEAN)
RETURN PLS_INTEGER
IS
retcode PLS_INTEGER := -1;
v_errcode PLS_INTEGER;
v_errtext VARCHAR2(1000);
l_section_name VARCHAR2(32) := 'isExist ' ;
BEGIN
IF VTMLOG.isDebugEnabled THEN
VTMLOG.debug(l_section_name,$$PLSQL_LINE, 'Checking existense of '||file_name);
END IF;
retcode := is_exist(file_name);
IF retcode = 1 THEN
IF is_dir THEN
retcode := isDirectory(file_name);
ELSE
retcode := isFile(file_name);
END IF;
IF retcode = 1 THEN
retcode := canread(file_name);
IF retcode != 1 THEN
VTMLOG.error(l_section_name,$$PLSQL_LINE, ' Can not read ' || file_name);
END IF;
ELSE
VTMLOG.error(l_section_name,$$PLSQL_LINE, ' Unable to check if ' || file_name || ' is directory or file ');
END IF;
ELSE
VTMLOG.error(l_section_name,$$PLSQL_LINE, file_name || ' does not exist ');
END IF;
VTMLOG.debug(l_section_name,$$PLSQL_LINE, 'Leaving ' );
RETURN retcode;
EXCEPTION
WHEN OTHERS THEN
VTMLOG.SHOW_ERROR_MESSAGE(l_section_name,$$PLSQL_LINE);
RAISE;
END isExist;
PROCEDURE foobar(feedname VARCHAR2)
IS
retval PLS_INTEGER;
BEGIN
/* implementation omitted */
retval := isExist('feed.txt',false);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END foobar;
END VSAMPLE_1;
/* This version at least shows the tree. But I can't reach the external by clicking in the navigation tree just the placeholders */
PROCEDURE foobar(feedname IN VARCHAR2);
END VSAMPLE_2;
CREATE OR REPLACE PACKAGE BODY VSAMPLE_2
IS
FUNCTION canread (FILE IN VARCHAR2) RETURN NUMBER;
FUNCTION is_exist (FILE IN VARCHAR2) RETURN NUMBER;
FUNCTION isDirectory (FILE IN VARCHAR2) RETURN NUMBER;
FUNCTION isFile (FILE IN VARCHAR2) RETURN NUMBER;
* Function Name:- isExist
* Description :-This function checks the existance of file,correctness of the directory provided by the user.
* @Param file_name :- File Name in directory
* @return retcode :- Error checking while uploading the feed.
FUNCTION isExist(file_name IN VARCHAR2,
is_dir BOOLEAN)
RETURN PLS_INTEGER
IS
retcode PLS_INTEGER := -1;
v_errcode PLS_INTEGER;
v_errtext VARCHAR2(1000);
l_section_name VARCHAR2(32) := 'isExist ' ;
BEGIN
IF VTMLOG.isDebugEnabled THEN
VTMLOG.debug(l_section_name,$$PLSQL_LINE, 'Checking existense of '||file_name);
END IF;
retcode := is_exist(file_name);
IF retcode = 1 THEN
IF is_dir THEN
retcode := isDirectory(file_name);
ELSE
retcode := isFile(file_name);
END IF;
IF retcode = 1 THEN
retcode := canread(file_name);
IF retcode != 1 THEN
VTMLOG.error(l_section_name,$$PLSQL_LINE, ' Can not read ' || file_name);
END IF;
ELSE
VTMLOG.error(l_section_name,$$PLSQL_LINE, ' Unable to check if ' || file_name || ' is directory or file ');
END IF;
ELSE
VTMLOG.error(l_section_name,$$PLSQL_LINE, file_name || ' does not exist ');
END IF;
VTMLOG.debug(l_section_name,$$PLSQL_LINE, 'Leaving ' );
RETURN retcode;
EXCEPTION
WHEN OTHERS THEN
VTMLOG.SHOW_ERROR_MESSAGE(l_section_name,$$PLSQL_LINE);
RAISE;
END isExist;
PROCEDURE foobar(feedname VARCHAR2)
IS
retval PLS_INTEGER;
BEGIN
/* implementation omitted */
retval := isExist('feed.txt',false);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END foobar;
* Function Name:- canread
* Description :-This function checks the file will give any error or not while reading
FUNCTION canread (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.canRead (java.lang.String) return int';
* Function Name:- is_exist
* Description :-This function checks the existance of the filein the required folder
FUNCTION is_exist (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.exists (java.lang.String) return int';
* Function Name:- isDirectory
* Description :-This function checks the name provided by the user is a directory or not
FUNCTION isDirectory (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.isDirectory (java.lang.String) return int';
* Function Name:- isFile
* Description :-This function checks the name provided by the user is a file or not
FUNCTION isFile (FILE IN VARCHAR2)
RETURN NUMBER AS LANGUAGE JAVA NAME 'com.myCompany.myApp.bulk.FileUtil.isFile (java.lang.String) return int';
END VSAMPLE_2;
/Hi,
I am afraid that according to the error message, it seems that this issue is mainly related to third-party, since issues using oracle database are not supported here, you could consider posting this issue in its website to get supports.
In addition, you could mark any reply as answer if it is helpful.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
ORA-06520 when External Procedure run.
I need to run a C application that will run an external procedure and I am getting the following errors reported when I run the function call in PL/SQL.
The test program follows
declare
rn number;
begin
rn:=wpleca('CUSTCODE PASSTEST');
END;
The error that is generated is
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: ld.so.1: extproc: fatal: libgcc_s.so.1: open failed: No such file or directory
ORA-06512: at "CUSTOM.WPLECA", line 0
ORA-06512: at line 4
The C program follows
#include<stdio.h>
#include<stdlib.h>
int sysrun(char *command) {
int num;
char str[80];
strcpy (str, "/xxxx/test/adhoc/syscr/wpleca2unix.sh ");
strcpy (str,command);
num = system(str);
return num;
The C compile commands follow
gcc -fPIC -c wpleca.c
gcc -shared -o libwpleca.so wpleca.o
The create library command follows
CREATE OR REPLACE LIBRARY PLECA_LIB
AS '/xxxx/test/adhoc/syscr/libwpleca.so'
The create function call follows
CREATE OR REPLACE FUNCTION wpleca (params_in in varchar2)
return binary_integer
as language C
name "sysrun"
library pleca_lib
parameters(params_in string);
The shared library and the script both exist with approporate permissions
-rwxr-xr-x 1 root other 5800 Feb 27 14:12 /xxxx/test/adhoc/syscr/libwpleca.so
-rwxrwxr-x 1 xyz test 1139 Feb 27 14:14 /xxxx/test/adhoc/syscr/wpleca2unix.sh
Any help with this error would be most appreciated.We are getting the error, Has anyone faced this issue, appreciate your help in advance.
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: ld.so.1: extproc: fatal: /tmp/utils.so: wrong ELF class: ELFCLASS32
while trying to call the external C program
Steps done for calling external procedure
1. Insert entries in the tnsnames.ora and listner.ora at oracle server location
Tnsnames.ora
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC) (KEY = extproc_key))
(CONNECT_DATA = (SID = extproc))
Listner.ora
CALLOUT_LISTENER =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = IPC)
(KEY = extproc_key)
SID_LIST_CALLOUT_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = extproc)
(ORACLE_HOME = /opt/oradba92/OraHome)
(PROGRAM = extproc)
(ENVS="EXTPROC_DLLS=ANY")
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ctsinpunsun10)(PORT = 1523))
2. restart the listener external service
3. create library using create library c_utils as ‘/tmp/c_utils.so’
4. create sample c program on /tmp location as test.c
5. compile c program on unix using cc test.c command
For compile c program
$ cc –c util.c command
Create object file
$cc –G –c util.c
Create .so file
$ld –r –o utils.so util.o
6. create object file of above c program using cc –G –c test.c , this command will create new object file as test.o
7. after creating the object file , create dynamic link using
ld –r –o utils.so test.o
8. Give the permission to utils.so as 775
Add “/tmp” path in LD_LIBRARY_PATH
9. using sqlplus execute the command “SELECT Plscallscdivisor_Func FROM dual” it will gives error as
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: ld.so.1: extproc: fatal: /tmp/utils.so: wrong ELF class: ELFCLASS32
Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
Message was edited by:
user573236 -
Problem with external procedure
Please,
i'm doing some experiments in Microsoft Win2003 environment calling a c function as external procedures.
I've build a sample using Dev-C++ that make a DLL (i don't know c language) named sysDLL.dll
DllClass::DllClass(char *cmd)
int num;
num = system(cmd);
I need only to execute some OS command from PL/SQL (rdbms 10.2).
I've putted DLL in $ORACLE_HOME\bin.
Then I've created library with this statement :
Create Library scott.c_sysdll as 'C:\oracle\product\10.2.0\db_3\bin\sysdll.dll'
and at the end I've created the procedure :
create or replace procedure scott.shell(cmd IN varchar2)
as language C
library c_SysDll
name "DllClass"
parameters (cmd string);
But when I execute this procedure from sql*plus I've always get :
ORA-06521: PL/SQL: Error mapping function
ORA-06522: Unable to load symbol from DLL
ORA-06512: at "SCOTT.SHELL", line 1
ORA-06512: at line 1
Please help me, thanks !Suggest that you first make it much simpler. Do not object orientation. Use plain vanilla flavour C. And even before using C, use a kernel call instead. For example, the gethostname() is a standard Socket call that you will find on many operating system (including Windows & Unix).
The following code sample illustrates (can be run as is via SQL*Plus):<font color="blue">
-- specify the external library (shared lib on Unix, DLL on Windows)
create or replace library libc as 'libc.sl';
-- The kernel call that we're going to wrap with a PL/SQL function:
-- int gethostname(char *hostname, size_t size);
-- wrapping this API call with a PL/SQL function
create or replace function gethostname( hostname OUT string, size_t binary_integer ) return binary_integer is
external
library libc
name "gethostname"
language C
calling standard C
parameters
hostname STRING,
size_t INT
-- calling the kernel API routine from within PL/SQL
set serveroutput on
declare
host$ varchar2(60);
rc$ integer;
begin
rc$ := gethostname( host$, 60 );
dbms_output.put_line( 'hostname is ['|| host$ ||'] return code=['|| TO_CHAR(rc$) || ']' );
end;
/</font>
<p>
Of course, the DLL name for Window is different than the Shared Library ('libc.sl') used in the above snippet. Do not have a Win32 Oracle platform to test on, but you should find this API call in the winsock.dll library.
<p>
As for writing your custom extproc in C. Plain vanilla C is something as follows:
int dosomestuff()
return( 123456 );
<p>
Remember that this function has to be exported in the DLL interface.
<p>
Also keep in mind that using extproc is usually the last option to pursue when dealing with Oracle development. The basic rules are as follows:
1. Do it in SQL.
2. If it cannot be done in SQL, do it as a PL/SQL proc
3. If if cannot be done in PL/SQL. do it as a Java stored proc
4. If if cannot be done in Java, do is as an external proc<p>
The times that I need to resort to using Java is less than a handful (most obvious one is using Java to gain o/s command line access). I have never put external proc code into production as we have yet to have a need for something so exceptional, that it cannot be done using SQL, PL/SQL or Java as the last resort. -
How to compile external procedure for Linxu
Hello to all.
I'm not able to find how to compile external procedure on Linux.
I have 64bit release Linux (I don't know if I need special 64bit library or not).
I found only something like that:
gcc -fPIC -shared -o comsh64.so comsh64.c
Listener are correctly configured.
Library is in Oracle bin directory.
If I run select externproc from dual ... I don't receive any error message but program don't work.
I think that there is some missing parameter in gcc or some small thing ?
Thank you for possible answeer
FilipDo you have someone any idea?
Now I have 1 library, 2 functions and 1 package with 2 functions:
int renamefile(char source, char destination)
{ int result;
result=rename(source,destination);
return result;
int comexi (char *c)
{ int ret;
ret = system(c);
return ret;
FUNCTION callSystemI(c in varchar2) RETURN binary_integer is
EXTERNAL LIBRARY extern_utils
NAME "comexi"
LANGUAGE C
PARAMETERS (c string);
function renamefile (src IN varchar2, dst IN varchar2) return binary_integer
AS EXTERNAL
NAME "renamefile"
LIBRARY extern_utils
LANGUAGE C
PARAMETERS (src string, dst string);
The first function still don't works, second function works.
Why? -
External Procedure with Windows "Handle" datatype
hi all,
I want to create a external procedure which use windows kerne32.dll library and GetFileSize function which is in dll.
http://msdn.microsoft.com/en-us/library/aa364955(v=vs.85).aspx
as you can see in this link , GetFileSize has two parameter, first one is a HANDLE type, how can I assign this parameter ? String is not working.
DWORD WINAPI GetFileSize(
__in HANDLE hFile,
__out_opt LPDWORD lpFileSizeHigh
Create Or Replace Function GetSize (FileName Varchar2, P_Value in out pls_integer) Return binary_double As
Language C Library Mylib Name "GetFileSize"
parameters (FileName by reference String, P_Value int, return double );
Declare
X1 number ;
X2 Pls_Integer;
X Number;
Begin
x2 := 40000000;
X1 := Getsize('C:\b.sql', X2);
X := X1;
dbms_output.put_line('x: ' ||x);
End;
/I allways getting zero value, file is exists and its size is bigger than zero.
what am i doing wrong?I don't know, Why you are using kernel32.dll to know the file size. This can be done very easily using UTL_FILE.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE FUNCTION utl_filesize(pi_dir_name IN VARCHAR2,
2 pi_file_name IN VARCHAR2)
3 RETURN NUMBER IS
4 file_size NUMBER;
5 blk_size BINARY_INTEGER;
6 fexists BOOLEAN;
7 BEGIN
8 UTL_FILE.fgetattr(pi_dir_name,
9 pi_file_name,
10 fexists,
11 file_size,
12 blk_size);
13 RETURN file_size;
14 END utl_filesize;
15 /
Function created.
SQL> SELECT utl_filesize('SAUBHIK','test2.csv') "Size in Bytes" FROM dual;
Size in Bytes
61
SQL> SELECT utl_filesize('SAUBHIK','Winter.jpg') "Size in Bytes" FROM dual;
Size in Bytes
105542
SQL> Now, coming to your actual question.
This is a demo, How to call kernel32.dll from PL/SQL.*
By the way, I have copied kernel32.dll from C:\WINDOWS\system32 to C:\oracle\product\10.2.0\db_3\bin
My listener.ora setup
SID_LIST_LISTENEREXTPROC =
(SID_LIST =
(SID_DESC =
(PROGRAM = extproc)
(ENV = "EXTPROC_DLLS=ONLY:C:\oracle\product\10.2.0\db_3\bin\kernel32.dll")
(SID_NAME = extproc)
(ORACLE_HOME = C:\oracle\product\10.2.0\db_3)
)My tnsnames.ora setup
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)A little verification.
LSNRCTL> stop LISTENEREXTPROC
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc)))
The command completed successfully
LSNRCTL> start LISTENEREXTPROC
Starting tnslsnr: please wait...
TNSLSNR for 32-bit Windows: Version 10.2.0.3.0 - Production
System parameter file is C:\oracle\product\10.2.0\db_3\network\admin\listener.o
a
Log messages written to C:\oracle\product\10.2.0\db_3\network\log\listenerextpr
c.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\extprocipc
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc)))
STATUS of the LISTENER
Alias LISTENEREXTPROC
Version TNSLSNR for 32-bit Windows: Version 10.2.0.3.0 - Prod
ction
Start Date 21-JAN-2011 17:32:26
Uptime 0 days 0 hr. 0 min. 3 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\oracle\product\10.2.0\db_3\network\admin\listener.
ra
Listener Log File C:\oracle\product\10.2.0\db_3\network\log\listenerext
roc.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\extprocipc)))
Services Summary...
Service "extproc" has 1 instance(s).
Instance "extproc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> exit
C:\Documents and Settings\Administrator>
C:\>tnsping EXTPROC_CONNECTION_DATA
TNS Ping Utility for 32-bit Windows: Version 10.2.0.3.0 - Production on 21-JAN-2
011 21:53:10
Copyright (c) 1997, 2006, Oracle. All rights reserved.
Used parameter files:
C:\oracle\product\10.2.0\db_3\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)
(KEY = EXTPROC1))) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO)))
OK (70 msec)
C:\>Now, the actual codes.
SQL> CREATE OR REPLACE LIBRARY kernel32 AS 'C:\oracle\product\10.2.0\db_3\bin\kernel32.dll';
2 /
Library created.
SQL> CREATE OR REPLACE FUNCTION CreateFile (FileName VARCHAR2 --1
2 ,p_DesiredAccess BINARY_INTEGER --2
3 ,p_ShareMode BINARY_INTEGER --3
4 ,p_SecurityAttributes BINARY_INTEGER --4
5 ,p_CreationDisposition BINARY_INTEGER --5
6 ,p_FlagsAndAttributes BINARY_INTEGER --6
7 ,p_TemplateFile BINARY_INTEGER )--7
8 Return BINARY_INTEGER
9 IS EXTERNAL
10 LIBRARY kernel32 Name "CreateFileA"
11 PARAMETERS (FileName STRING
12 ,p_DesiredAccess long
13 ,p_ShareMode long
14 ,p_SecurityAttributes long
15 ,p_CreationDisposition long
16 ,p_FlagsAndAttributes long
17 ,p_TemplateFile long
18 ,return long );
19 /
Function created.
SQL> /* This is for closing the handle after use. */
SQL> CREATE OR REPLACE FUNCTION CloseFile (p_FileHandle BINARY_INTEGER)
2 Return BINARY_INTEGER
3 IS EXTERNAL
4 LIBRARY kernel32 Name "CloseHandle"
5 PARAMETERS (p_FileHandle long, return long);
6 /
Function created.
SQL> /* This is the main function for getting size */
SQL> CREATE OR REPLACE FUNCTION GetSize (p_FileHandle BINARY_INTEGER,
2 p_FileSizeHigh IN OUT BINARY_INTEGER)
3 RETURN BINARY_INTEGER
4 IS EXTERNAL
5 LIBRARY kernel32 NAME "GetFileSize"
6 PARAMETERS (p_FileHandle long, p_FileSizeHigh long, return long );
7 /
Function created.
SQL> set serverout on
SQL> DECLARE
2 v_FileSize BINARY_INTEGER;
3 v_FileSizeHigh PLS_INTEGER;
4 v_FileHandle BINARY_INTEGER;
5 v_filename VARCHAR2(500) :='C:\test2.csv';
6 v_dummy BINARY_INTEGER;
7 BEGIN
8 v_FileSizeHigh := 400000000;
9 v_FileHandle:=CreateFile(v_filename -- File name
10 ,0 -- Type of access required (read/write ect)
11 ,0 -- disable share mode
12 ,0 --no securoty attribute
13 ,3 -- Means Open existing
14 ,128 --080h, File attribute normal.
15 ,0); --7
16 v_FileSize := Getsize(v_FileHandle, v_FileSizeHigh);
17 DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_FileSize);
18 v_dummy:=CloseFile(v_FileHandle);
19 END;
20 /
File Size in Bytes: 61
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL> DECLARE
2 v_FileSize BINARY_INTEGER;
3 v_FileSizeHigh PLS_INTEGER;
4 v_FileHandle BINARY_INTEGER;
5 v_filename VARCHAR2(500) :='C:\Winter.jpg';
6 v_dummy BINARY_INTEGER;
7 BEGIN
8 v_FileSizeHigh := 400000000;
9 v_FileHandle:=CreateFile(v_filename -- File name
10 ,0 -- Type of access required (read/write ect)
11 ,0 -- disable share mode
12 ,0 --no securoty attribute
13 ,3 -- Means Open existing
14 ,128 --080h, File attribute normal.
15 ,0); --7
16 v_FileSize := Getsize(v_FileHandle, v_FileSizeHigh);
17 DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_FileSize);
18 v_dummy:=CloseFile(v_FileHandle);
19 END;
20 /
File Size in Bytes: 105542
PL/SQL procedure successfully completed.
SQL> Verification.
C:\>dir test2.csv
Volume in drive C has no label.
Volume Serial Number is 6806-ABBD
Directory of C:\
12/15/2010 01:35 PM 61 test2.csv
1 File(s) 61 bytes
0 Dir(s) 3,405,336,576 bytes free
C:\>dir Winter.jpg
Volume in drive C has no label.
Volume Serial Number is 6806-ABBD
Directory of C:\
10/11/2010 05:27 PM 105,542 Winter.jpg
1 File(s) 105,542 bytes
0 Dir(s) 3,405,336,576 bytes free
C:\> -
Java external procedure parameters
Hi, I'm calling a Java External Procedure like this:
CREATE FUNCTION HAS_GROUP (STRGROUP IN VARCHAR2)
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'PKGPORTAL.GROUPS.HAS_GROUP
(java.lang.String) return java.lang.String';
The thing is that I need also to send it the CLIENT_IDENTIFIER, but I saw in every example that the parameters that the PLSQL function recieves are the same that you send to Java. Am I able to send an extra parameter to Java?. I need it to recieve the CLIENT_IDENTIFIER. Thank you.I am using CREATE OR REPLACE JAVA CLASS,i missed that step in my first mail.
Is it possible that jdk version in oracle 9i is giving me poblem . Becoz for my java class i am using j2sdk1.4.2
I tried to deploy my class using Jdeveloper and i get this following error :
"ORA-29521: referenced name javax/crypto/NoSuchPaddingException could not be found"
I am importing javax.crypto in my class.
How i can update oracle java file to latest version? -
Error in calling Stored procedure returns REFCURSOR
Hi,
I've written a oracle stored procedure returning REFCURSOR. say,extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc).
Following statement throwing error.
CallableStatement cs = con.PrepareCall("{extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc)}");
rs = cs.executeQuery();
Could you rectify this problem and give me the currect code.
riyazYour naming convention leaves a little to be desired.
String command = "{CALL extractorderdespatchconfirmsp(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
CallableStatement cstmt = conn.prepareCall(command);
//set the variables here ie, dates need to be a timestamp format. use set timestamp.
cstmt.setInt(1, 2);
cstmt.setString(2, "a string");
cstmt.setInt(3, 0);
//for return values
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.registerOutParameter(2, Types.INTEGER);
cstmt.execute();
int status = cstmt.getInt(3);
int status2 = cstmt.getInt(2);
cstmt.close();
It took me awhile too to get JDBC to call these right. -
Using an AIX archive file as a library for an external procedure.
I cannot use an archive file, created with the ar command, that contains a shared object that was created with the xlc and ld commands as a library for external procedures. I can use the shared object file created with the ld command as a library for an external procedure. Why would I encounter an invalid magic number and what is the resolution?
Example:
oracle:@husk21:/home/oracle> ksh -x ./Oracle_demo.ksh
+ rm shell.o shell.so shell.so.exp shell.so.imp
+ make -f /u01/oracle/product/11.1.0.7/db/rdbms/demo/demo_rdbms32.mk extproc_no_context SHARED_LIBNAME=shell.so OBJS=shell.o
/u01/oracle/product/11.1.0.7/db/bin/oraxlc -q32 -c -I/u01/oracle/product/11.1.0.7/db/rdbms/demo -I/u01/oracle/product/11.1.0.7/db/rdbms/public -I/u01/oracle/product/11.1.0.7/db/plsql/public -I/u01/oracle/product/11.1.0.7/db/network/public -I/u01/oracle/product/11.1.0.7/db/precomp/public shell.c
generate_export_list() { /bin/nm -X32_64 -B -h -g "$1" | grep -v ' U ' | awk '{print $3}' | egrep -v '^\.|^TOC' | sort | uniq ; }; generate_import_list() { LIB_NAME=$1; IMP_FILE=$2; cat /u01/oracle/product/11.1.0.7/db/rdbms/lib/xa.imp | head -1 | awk '{print $0, "." }' > ${IMP_FILE}; /bin/nm -X32_64 -C -B -h -g ${LIB_NAME} | grep ' U ' | grep -v "::" | grep -v "(" | grep -v "\.cc" | awk '{print $3}' | sed -e "s/\.//g" | grep -v "^_" >> ${IMP_FILE}; }; generate_import_list shell.o shell.so.imp; generate_export_list shell.o > shell.so.exp; /bin/ld -b32 -bnoentry -bM:SRE -bE:shell.so.exp -bI:shell.so.imp -o shell.so shell.o -L/u01/oracle/product/11.1.0.7/db/lib -lc_r -lm
ld: 0711-224 WARNING: Duplicate symbol: .system
ld: 0711-224 WARNING: Duplicate symbol: system
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
oracle:@husk21:/home/oracle> ar rv libshell.a shell.so
ar: Creating an archive file libshell.a.
a - shell.so
oracle:@husk21:/home/oracle> ar tv libshell.a
rwxr-xr-x 3514/3516 1263 Sep 08 10:00 2009 shell.so
oracle:@husk21:/home/oracle> file shell.so
shell.so: executable (RISC System/6000) or object module not stripped
oracle:@husk21:/home/oracle> file libshell.a
libshell.a: archive (big format)
SQL> CREATE OR REPLACE LIBRARY shell_lib is '/home/oracle/libshell.a';
/ 2
Library created.
SQL> CREATE OR REPLACE PROCEDURE shell(command IN char)
AS EXTERNAL
NAME "shell"
LIBRARY shell_lib
LANGUAGE C
PARAMETERS (command string);
/ 2 3 4 5 6 7
Procedure created.
SQL> exec shell('ls');
BEGIN shell('ls'); END;
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: 0509-022 Cannot load module /home/oracle/libshell.a.
0509-103 The module has an invalid magic number.
ORA-06512: at "V500.SHELL", line 1
ORA-06512: at line 1
SQL> CREATE OR REPLACE LIBRARY shell_lib is '/home/oracle/shell.so';
2 /
Library created.
SQL> exec shell('ls');
PL/SQL procedure successfully completedUsing an AIX archive file as a library for an external procedure.
-
Error mapping function in external procedure call
I'm trying to create an external procedure in PL/SQL8.1 to run an operating system command from within a PL/SQL block.
The C function couldn't be simpler:
extern void host_command(char *command)
(void)system(command);
It's even ignoring the return value of SYSTEM!
I've generated what I THINK is a shared object file and copied it to $ORACLE_HOME/lib/host_command.so
I've then done CREATE LIBRARY HOST_COMMAND_LIB as '...'
Then I created a PL/SQL procedure:
CREATE PROCEDURE SHELL(IP_COMMAND IN VARCHAR2)
AS
LANGUAGE C
NAME "host_command"
LIBRARY HOST_COMMAND_LIB
PARAMETERS (IP_COMMAND);
And then EXEC SHELL ('touch /tmp/fred')
That's when ORA-6521 is raised.
I am running Oracle8.1.7.4.0 on AIX 4.3
Am I missing something?
Any suggestions will be thankfully received.
Andrew HunterThanks.
In fact, using the supplied makefile in $ORACLE_HOME/plsql/demo and MAKING SURE THAT THE .SO IS EXECUTABLE(!) works. -
'Error mapping function' with external procedures
I'm trying to create an external procedure in PL/SQL8.1 to run an operating system command from within a PL/SQL block.
The C function couldn't be simpler:
extern void host_command(char *command)
(void)system(command);
It's even ignoring the return value of SYSTEM!
I've generated what I THINK is a shared object file and copied it to $ORACLE_HOME/lib/host_command.so
I've then done CREATE LIBRARY HOST_COMMAND_LIB as '...'
Then I created a PL/SQL procedure:
CREATE PROCEDURE SHELL(IP_COMMAND IN VARCHAR2)
AS
LANGUAGE C
NAME "host_command"
LIBRARY HOST_COMMAND_LIB
PARAMETERS (IP_COMMAND);
And then EXEC SHELL ('touch /tmp/fred')
That's when ORA-6521 is raised.
I am running Oracle8.1.7.4.0 on AIX 4.3
Am I missing something?
Any suggestions will be thankfully received.
Andrew HunterThanks.
In fact, using the supplied makefile in $ORACLE_HOME/plsql/demo and MAKING SURE THAT THE .SO IS EXECUTABLE(!) works. -
Help me, please ORA-28576: lost RPC connection to external procedure agent
when i call external program
SQL>exec shell_all ('/bin/ls /oracle/product/10.2.0/',:result, 3) ;
BEGIN shell_all ('/bin/ls /oracle/product/10.2.0/',:result, 3) ; END;
ERROR at line 1:
ORA-28576: lost RPC connection to external procedure agent
ORA-06512: at "SYS.SHELL_ALL", line 1
ORA-06512: at line 1
and my configure
#listener.ora
SID_LIST_LISTENER_AADB02 =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/10.2.0/db)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ANY")
LISTENER_AADB02 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = aadb02-vip)(PORT = 1521)(IP = FIRST))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 203.144.222.82)(PORT = 1521)(IP = FIRST))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = extproc))
#tnsname.ora
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = extproc))
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
Please tell me to resolve this problemDoes not execl() and friends replace the current program with the one supplied as a parameter?
The upshot of this would be as you suggest, viz:
- Oracle call's your procedure (but doens't wait for a result due to the void return type?)
- your program executes its code (cd /tmp)
- it then replaces itself with *program
- *program terminates
Presumably, Oracle isn't expecting it to terminate but to continue waiting for subsequent requests.
I'd check out fork() and see if that offers more appropriate semantics.
d.
Maybe you are looking for
-
Sync problem 7.1.1
yesterday night I updated my iphone 5 to 7.1.1. This noon, my iphone 5, has started to waste on 3g all my data conetion, further than 200 mb in 2 hour. I've confirm that the problem is in the system service, particullary on documents and sync. anyone
-
Customer Invoice Printing FB70
Hi All, I want to print customer invoice for transaction FB70. Please give me the details like triggering the form (Customization settings) and standard SAPScript form name. And one more, Is there any option for attaching any file to this invoice. Th
-
I have created an export of a mailbox ; this result in a mbox file , in which I "think" I have put 7.500 messages, occupying 3,7 GO, ranging from 1 1 2011 to 31 12 2011 When I later import this mbox into mail ( in an other OSX account or in the same
-
hi there...i forgot my security questions how can i reset it because everytime i try to reset it it always ask me my old security questions...
-
Selecting same column twice makes query slow
Hello, Has anybody any idea why following statement is slow when selecting the DATA_TYPE column twice? SELECT S.OWNER, S.SYNONYM_NAME, UCOL.COLUMN_NAME, UCOL.DATA_TYPE, UCOL.DATA_TYPE, UCOL.DATA_LENGTH, COLUMN_ID FROM ALL_SYNONYMS S, ALL_TAB_COLUMNS