Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: How to do a bitwise OR from SQL*Plus

Re: How to do a bitwise OR from SQL*Plus

From: Igor Neyman <ineyman_at_perceptron.com>
Date: Fri, 22 Jun 2001 08:37:34 -0700
Message-ID: <F001.00333B4D.20010622081101@fatcity.com>

Here is simple function, that I pu into dll (it's on NT):
 

extern "C" void __declspec(dllexport) os_cmd(char *cmd_string,
short cmd_string_indicator,
short cmd_string_length,

int e_mode,
short e_mode_indicator,
int *ret_val)
{
int exec_mode;
char *args[10];
char *l_buffer;
char *pdest;
char *pdest1;

int result;
int l_ch = ' '; /* TAB */
int i = 0;
int nI;

for (nI = 0; nI < 10; nI++)
args[nI] = NULL;
l_buffer = (char *)calloc(cmd_string_length + 1, sizeof(char)); strncpy(l_buffer, cmd_string, cmd_string_length); l_buffer[cmd_string_length] = '\0';
pdest1 = l_buffer;
while ((pdest = strchr(pdest1, l_ch)) != NULL) {
result = pdest - pdest1;
args[i] = (char *)calloc(result + 1, sizeof(char)); strncpy(args[i++], pdest1, result);
pdest1 = pdest + 1;
}
args[i] = (char *)calloc(strlen(pdest1) + 1, sizeof(char)); strncpy(args[i++], pdest1, strlen(pdest1)); args[i] = NULL;
 

if (e_mode == SyncMode)
exec_mode = _P_WAIT;
else
exec_mode = _P_NOWAIT;
if (_spawnv(exec_mode, args[0], args) == -1) {
if (errno == E2BIG)
*ret_val = 1;
else if (errno == EINVAL)
*ret_val = 2;
else if (errno == ENOENT)
*ret_val = 3;
else if (errno == ENOEXEC)
*ret_val = 4;
else if (errno == ENOMEM)
*ret_val = 5;
else
*ret_val = 6;
}
else
*ret_val = 0;

for (nI = 0; nI <= i-1; nI++) 
free(args[nI]);
free(l_buffer);

}
 

and PL/SQL wrapper:<FONT
face="Courier New" size=2>
--  Executes OS command
-- 'p-mode': 0 - sync, 1 - async.
-- If there are parameters to pass, they should be separated by TABs.
-- To run internal DOS command use 'cmd /C <your_command>'
PROCEDURE exec_os_cmd(
cmd_string IN varchar2,
e_mode IN BINARY_INTEGER,
ret_val OUT BINARY_INTEGER) IS
external
library externDDM
NAME "os_cmd"
LANGUAGE C
PARAMETERS (cmd_string STRING,
cmd_string INDICATOR,
cmd_string LENGTH,
e_mode INT,
e_mode INDICATOR,
ret_val INT);
 

'externDDM' is the name of the library I create:
 

create library externDDM as
'D:\ORANT\BIN\ext_ddm.dll';
 
 

Please read oracle docs for more details.
 

Igor Neyman, OCP DBAPerceptron, Inc.(734)414-4627<A href="mailto:ineyman_at_perceptron.com">ineyman_at_perceptron.com 

<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

  Sent: Friday, June 22, 2001 10:31
AM
  Subject: RE: How to do a bitwise OR from   SQL*Plus   

  Hi neyman,
  Thank god, i had a requirement to transfer data   files from ftp server to oracle directory, and then am processing it...   

  Can you tell me method, how to write the   external stored procedures and call from pl/sql.   thanks in advance.
  Nirmal <FONT color=#0000ff
  size=2>Qatar Telecom <A
  href="mailto:nirmalk_at_qtel.com.qa">nirmalk_at_qtel.com.qa   

    -----Original Message----- <FONT
    size=1>From:   Igor Neyman
    [SMTP:ineyman_at_perceptron.com] <FONT     size=1>Sent:   Friday, June 22, 2001 4:30     PM To:     <FONT

    size=1>Multiple recipients of list ORACLE-L <FONT 
    size=1>Subject:        <FONT 
    size=1>Re: How to do a bitwise OR from SQL*Plus 
    I am using external stored procedures (C/C++), mostly to     execute OS commands from PL/SQL code.     Pretty straightforward (following docs), works fine.      Should be accurate mapping C-types to PL/SQL     types.
    Igor Neyman, OCP DBA Perceptron,
    Inc. (734)414-4627 <FONT
    size=2>ineyman_at_perceptron.com Received on Fri Jun 22 2001 - 10:37:34 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US