Proc

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 12

https://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_05adv.

htm#i429905

http://www.srikanthtechnologies.com/blog/oracle/procgetstarted.aspx

http://programmingexamples.wikidot.com/pro-c-tutorial

http://infolab.stanford.edu/~ullman/fcdb/oracle/or-proc.html

https://web.stanford.edu/dept/itss/docs/oracle/10gR2/appdev.102/b14407/toc.htm

pro*c virtusa
Padma priya and jeyaraman

xoriant
1.storage classes in c
auto,static,extern,register
2.string to integer conversion
nsigned char text[]="1234";
int intValue;

intValue=atoi(text);
3.pro*c compilation
4.multiple c files compilation.(linking)
5.make files
6.printf and scanf
7.call by value and call by reference
8.what is pointer
9.how to handle null values in c
10.difference bw structure and union
11.banking transactions writing into a file?
fetch from table and write into the file.last 1 month credit and debit
transactions.
12.traslate and replace difference
13.delete and truncate
14.cursor - cursor attibutes
15.differnce between function procedures and packages
16.difference bw cmp and diff
17.changing file permissions

proc ireclen=132 sqlcheck=semantics userid=uname/pwd iname=file.pc oname=file.c

Proc

Error codes

https://docs.oracle.com/cd/B10500_01/appdev.920/a97269/pc_09err.htm

Class Condition
0 success completion
1 warning
2 no data
7 dynamic SQL error
8 connection exception
0A feature not supported
21 coordinately violation
22 data exception
23 integrity constraint violation
24 invalid cursor state
25 invalid transaction state
26 invalid SQL statement name
27 triggered data change violation
28 invalid authorization specification
2A direct SQL syntax error or access rule violation
2B dependent privilege descriptors still exist
2C invalid character set name
2D invalid transaction termination
2E invalid connection name
33 invalid SQL descriptor name
34 invalid cursor name
35 invalid condition number
37 dynamic SQL syntax error or access rule violation
3C ambiguous cursor name
3D invalid catalog name
3F invalid schema name
40 transaction rollback
42 syntax error or access rule violation
44 with check option violation
HZ remote database access

mms$tgt:smsc_client.exe depends_on $(SMSC_CLIENT_OBJ)


.IFDEF DEBUG
lnproc $(MMS$TARGET) $(SMSC_CLIENT_OBJ) D
.ELSE
lnproc $(MMS$TARGET) $(SMSC_CLIENT_OBJ)
.ENDIF

mms$int:smsc_client.obj :
mms$src:smsc_client.c,mms$src:smsc_client.h

mms$int:smsc_client_db.obj : mms$int:smsc_client_db.c

mms$int:smsc_client_db.c :
mms$src:smsc_client_db.pc,mms$src:smsc_client.h

---------------------------------------------------------------------------

mms$tgt:gmlc_client.exe depends_on $(GMLC_CLIENT_OBJ)


.IFDEF DEBUG
lnproc $(MMS$TARGET) $(GMLC_CLIENT_OBJ) D
.ELSE
lnproc $(MMS$TARGET) $(GMLC_CLIENT_OBJ)
.ENDIF

mms$int:gmlc_client.obj : mms$src:gmlc_client.c, -
mms$src:gmlc_client.h

mms$int:gmlc_client_db.obj : mms$int:gmlc_client_db.c

mms$int:gmlc_client_db.c : mms$src:gmlc_client_db.pc, -
mms$src:gmlc_client.h
-----------------------------------------------------------------------

proc ireclen=132 sqlcheck=semantics userid=absowner37/absowner371


iname=DISK$DEVELOPERS:[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.SRC]UBFMOD.PC
oname=DISK$DEVELOPERS:[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.INT]UBFMOD.C
include=(mms$src:,DISK$DEVELOPERS:[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.SRC]:)

cc/noopt/stand=vaxc /nolist/object=DISK$DEVELOPERS:
[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.INT]UBFMOD.obj
/nodebug/include=(mms$src:,DISK$DEVELOPERS:
[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.SRC],DISK$DEVELOPERS:
[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.SRC],tcpware_include:)/nested_include_directory=prim
ary_file DISK$DEVELOPERS:[SUPP_TEAM.TAMILSR1.ABSSUP_DEV.INT]UBFMOD.C

-----------------------------------------------------------------------------------
-------------
gcc -c -o my.o my.c

gcc hello.c -- a.out


gcc hello.c -o hello -- hello
./hello

gcc -c hello.c -- hello.o


gcc -c world.c -- world.o
gcc -o hworld hello.o world.o -- hworld
./hworld

Library linking
gcc -o hello.o world.o -lpam -- Linker looks for /lib or /usr/lib directory
for libpam.a library for linking
-lpam -- link the library
libpam.a
gcc -o hello.o world.o -L. -lpam -- Linker looks for current directory for
libpam.a library for linking
-L. -- current directory
gcc -o hello.o world.o -L/usr/local/lib/pam -lpam -- looks for directory
usr/local/lib/pam

Make file

hworld:hello.o world.obj
gcc $(CFLAGS) -o hworld hello.o world.obj

hello.o : hello.c abc.h


gcc $(CFLAGS) -c hello.c

world.o : world.c xyz.h


gcc $(CFLAGS) -c world.c

clean:
rm -f *.o hworld

GCC compilation process

https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

1.Preprocessing Source code (.c .cpp .h) --> .i .ii


2.Compiling -- header included , macros expanded , .i,.ii --> .s
3.Assembling -- .s --> .0 / .obj
4.Linking -- static linking (static lib .a .lib) + (.o, .obj) --> .exe
Shared Library (.dll, .so)
3.58

File operations

http://psoug.org/definition/UTL_FILE.htm

Term: UTL_FILE

http://psoug.org/reference/utl_file.html

Definition:
In Oracle PL/SQL, UTL_FILE is an Oracle supplied package which is used for file
operations (read and write) in conjunction with the underlying operating system.
UTL_FILE works for both server and client machine systems.

SQLCA

if ( sqlca.sqlcode != 0 )

sqlcode
0 No error.
>0 Statement executed but exception detected. This occurs when Oracle cannot
find a row that meets your WHERE condition or when a SELECT INTO or FETCH returns
no rows.
<0 Oracle did not execute the statement because of an error. When such errors
occur, the current transaction should, in most cases, be rolled back.

https://docs.oracle.com/cd/B10500_01/appdev.920/a97269/pc_09err.htm

Class Condition
0 success completion
1 warning
2 no data
7 dynamic SQL error
8 connection exception
0A feature not supported
21 coordinately violation
22 data exception
23 integrity constraint violation
24 invalid cursor state
25 invalid transaction state
26 invalid SQL statement name
27 triggered data change violation
28 invalid authorization specification
2A direct SQL syntax error or access rule violation
2B dependent privilege descriptors still exist
2C invalid character set name
2D invalid transaction termination
2E invalid connection name
33 invalid SQL descriptor name
34 invalid cursor name
35 invalid condition number
37 dynamic SQL syntax error or access rule violation
3C ambiguous cursor name
3D invalid catalog name
3F invalid schema name
40 transaction rollback
42 syntax error or access rule violation
44 with check option violation
HZ remote database access

-----------------------------------------------------------------------------------
-------------------------------

--PRO*C

* Pro*c is writing a C program with embedded SQL statements


* It is possible to access Oracle database from C program using Pro*C
* Oracle provides PROC compiler,
which takes a C program with embedded SQL statements and converts the embedded SQL
statements to Oracle Runtime Library.
* installation of Oracle has Pro*C components installed by examining PRECOMP
directory of Oracle home
C:\ORACLE8i\PRECOMP.

PUBLIC Contains the required header (.h) files.


LIB Contains the libraries used by language linker.
DEMO Contains demo program.
ADMIN Contains configuration files.
DOC Documentation related to Precompilers.

--Embedded Commands

1.Executable - they are executed by Oracle to perform some operation


2.Declarative - they are used to declare host variables etc.

--Pro*C Syntax

* All SQL statements need to start with EXEC SQL and end with a semicolon ";".
* We can place the SQL statements anywhere within a C/C++ block,
with the restriction that the declarative statements do not come after the
executable statements.
* Pro*C compiler is converting all lines that start with EXEC SQL into appropriate
C code.

--Preprocessor Directives

* The C/C++ preprocessor directives that work with Pro*C are #include and #if.
* Pro*C does not recognize #define. For example, the following code is invalid:

#define THE_SSN 876543210


/* ... */
EXEC SQL SELECT salary INTO :a
FROM Employee
WHERE SSN = THE_SSN; /* INVALID */

--Statement Labels

* We can connect C/C++ labels with SQL as in:

EXEC SQL WHENEVER SQLERROR GOTO error_in_SQL;


/* ... */
error_in_SQL:
/* do error handling */
-- Host Variables

* used to communicate with Oracle


* used to send values from C to Oracle and also to receive values from Oracle.
* Declared between BEGIN DECLARE SECTION and END DECLARE SECTION and used in
embedded sql with prefix : (colon).
* but should not be prefixed with a colon in C statements

-- data types
char
char[n]
int
short
long
float
double
VARCHAR[n]

-- Indicator Variable
* indicates the value or condition of the host variable
* "NULL flags" attached to host variables
* You can associate every host variable with an optional indicator variable
* 2-byte integer (using the type short)
* in SQL statements, must be prefixed by a colon and immediately follow its host
variable (Or)
you may use the keyword INDICATOR in between the host variable and indicator
variable

short indicator_var;
EXEC SQL SELECT xyz INTO :host_var:indicator_var
FROM ...;
/* ... */
EXEC SQL INSERT INTO R
VALUES(:host_var INDICATOR :indicator_var, ...)
-- indicator variables in the INTO clause of a SELECT statement to detect NULL's or
truncated values in the output host variables

0 Oracle assigned an intact column value to the host variable.


-1 The column value is NULL, so the value of the host variable is indeterminate.
-2 Oracle assigned a truncated column variable to the host variable, but the
original column value could not be determined.
>0 Oracle assigned a truncated column value to the host variable. The integer
returned by the indicator variable is the original length of the column value.

-- SET clause of an INSERT or UPDATE statement to assign NULL's to input host


variables

-1 Oracle will assign a NULL to the column, ignoring the value of the host
variable.
>=0 Oracle will assign the value of the host variable to the column.

--Pointers

* define pointers using the regular C syntax, and use them in embedded SQL
statements. As usual, prefix them with a colon:

int *x;
/* ... */
EXEC SQL SELECT xyz INTO :x FROM ...;

The result of this SELECT statement will be written into *x, not x.

-- Structures
Structures can be used as host variables, as illustrated in the following example:

typedef struct {
char name[21]; /* one greater than column length; for '\0' */
int SSN;
} Emp;
/* ... */
Emp bigshot;
/* ... */
EXEC SQL INSERT INTO emp (ename, eSSN)
VALUES (:bigshot);

-- Arrays
Host arrays can be used in the following way:

int emp_number[50];
char name[50][11]; -- Pro*C actually considers name a one-dimensional array of
strings rather than a two-dimensional array of characters.
/* ... */
EXEC SQL INSERT INTO emp(emp_number, name)
VALUES (:emp_number, :emp_name);

which will insert all the 50 tuples in one go.

-- Dynamic SQL
* it is required for a program to create the SQL statements dynamically.
* With dynamic SQL, a statement stored in a string variable can be issued.
* PREPARE turns a character string into a SQL statement, and
* EXECUTE executes that statement.

char *s = "INSERT INTO emp VALUES(1234, 'jon', 3)";


EXEC SQL PREPARE q FROM :s;
EXEC SQL EXECUTE q;

(or)
char *s = "INSERT INTO emp VALUES(1234, 'jon', 3)";
EXEC SQL EXECUTE IMMEDIATE :s;

plsql_block VARCHAR2(500);
plsql_block := 'BEGIN create_dept(:a, :b, :c, :d); END;';
EXECUTE IMMEDIATE plsql_block
USING IN OUT new_deptid, new_dname, new_mgrid, new_locid;

-- Error Handling
* SQLCA
-- After each executable SQL statement, your program can find the status of
execution either by explicit checking of SQLCA
* WHENEVER
-- implicit checking using the WHENEVER statement

-- SQLCA
* used to detect errors and status changes in your program
* This structure contains components that are filled in by Oracle at runtime after
every executable SQL statement.

* need to include the header file sqlca.h using the #include directive
-- components id,bc,code

1. sqlcaid: It is an array of char character which is initialized to "SQLCA", and


used to determine the SQL Communication area.
2. sqlcabc: It is declared as an integer type to hold the length of the SQLCA
structure in bytes.
3. sqlcode: It is declared as an integer type that stores the status code of the
most recently executed SQL statement. The status determines the outcome of the SQL
statement, and the outcome can come in the following ways:

-- sqlcode
0 The statement has been executed successfully with no error.
>0 Some error occurs while executing the statement. For example, when we are
using SELECT command with Where clause, then no such row found mentioned in the
Where clause condition.
<0 In this case, statement is not executed due to the database, system,
application or network error.

-- sqlerrm This embedded structure contains the following two components:

sqlerrml - Length of the message text stored in sqlerrmc.


sqlerrmc - Up to 70 characters of the message text corresponding to the error
code stored in sqlcode.

struct sqlca {
char sqlcaid[8];
long sqlabc;
long sqlcode;
struct {
unsigned short sqlerrml;
char sqlerrmc[70];
} sqlerrm;
char sqlerrp[8];
long sqlerrd[6];
char sqlwarn[8];
char sqlext[8];
};
-----------------------------------------------------------------------------------
-------------------------------

-- WHENEVER Statement

This statement allows you to do automatic error checking and handling. The syntax
is:

EXEC SQL WHENEVER <condition> <action>;

Oracle automatically checks SQLCA for <condition>, and if such condition is


detected, your program will automatically perform <action>.

<condition> can be any of the following:

SQLWARNING - sqlwarn[0] is set because Oracle returned a warning


SQLERROR - sqlcode is negative because Oracle returned an error
NOT FOUND - sqlcode is positive because Oracle could not find a row that meets
your WHERE condition, or a SELECT INTO or FETCH returned no rows
<action> can be any of the following:

CONTINUE - Program will try to continue to run with the next statement if
possible
DO - Program transfers control to an error handling function
GOTO <label> - Program branches to a labeled statement
STOP - Program exits with an exit() call, and uncommitted work is rolled back

Some examples of the WHENEVER statement:

EXEC SQL WHENEVER SQLWARNING DO print_warning_msg();


EXEC SQL WHENEVER NOT FOUND GOTO handle_empty;

-------------------
UTL_FILE----------------------------------------------------------------

* Oracle supplied package which is used for file operations


* UTL_FILE works for both server and client machine systems.
Steps
1. A directory has to be created on the server, which points to the target file.
2. For the files located on the server machine, the actual path can be given while
creating the directory.
3. For the files which are located on the client machines, however, the relative
path is required along with the client machine name.
4. In addition, the relative file path must be in shared mode with read and write
access for the required users.
5. A DBA must create the directory and then grant Read/Write access to the required
users.

A Append Text
AB Append Byte Mode
R Read Text
RB Read Byte Mode
W Write Text
WB Write Byte Mode

-- the parameter UTL_FILE_DIR was used to specify the file location path.

-- Example
v_directory varchar2(20);
out_fopen_handle UTL_FILE.FILE_TYPE;

v_directory:='CELL0_REP';

out_fopen_handle := UTL_FILE.FOPEN (v_directory,'SYS.txt','w');


-- L_HANDLER := UTL_FILE.FOPEN('MYDIR', 'SYS.txt', 'W');
UTL_FILE.PUTF(out_fopen_handle, 'UTL_FILE write mode demonstration');

UTL_FILE.FCLOSE(out_fopen_handle);

http://psoug.org/reference/utl_file.html

utl_file.fclose_all;
set serveroutput on

DECLARE
vInHandle utl_file.file_type;
vOutHandle utl_file.file_type;
BEGIN
vInHandle := utl_file.fopen('ORALOAD', 'test.txt', 'R');
vOutHandle := utl_file.fopen('ORALOAD', 'out.txt', 'W');

IF utl_file.is_open(vInHandle) THEN
utl_file.fclose_all;
dbms_output.put_line('Closed All');
END IF;
END fopen;
/

-----------------------------------------------------------------------------------
-----------------------------

EXEC SQL BEGIN DECLARE SECTION;

varchar o_uid[100];
int o_session_id;
VARCHAR o_smsc_cfg_supp_ref_id[MAX_SIZE_03];

EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;


EXEC SQL CONNECT :o_uid;

EXEC SQL
SELECT LCDI_INSTRUCTION
INTO :o_login
FROM LC_DETAILED_INSTRUCTIONS
WHERE LCDI_QUEUE = 'SMSC'
AND LCDI_REQUEST_TYPE = 'LOGIN';

if ( sqlca.sqlcode == 0 )
{
o_login.arr[o_login.len] = '\0';
o_login.len = strlen((char *)o_login.arr);

strcpy(smsc_lcdi.login,(char *)o_login.arr);
}
EXEC SQL
UPDATE LC_REQUESTS
SET LCR_STATUS = 'COMP_FAIL',
LCR_ERROR_CODE = nvl(LCR_ERROR_CODE,652),
LCR_STATUS_CHANGE_DTTM = to_date(:cur_date,'YYYYMMDDHH24MISS')
WHERE LCR_REQUEST_ID = :lcr_req_id;

EXEC SQL
INSERT
INTO LC_INSTRUCTIONS
( LCI_REQUEST_ID,
LCI_SEQ_ORDER,
LCI_MOBILE_NO,

LCI_REQUEST_TYPE,
LCI_QUEUE,

LCI_STATUS,
LCI_STATUS_CHANGE_DTTM,

LCI_SCP_ROLLBACK_REQUEST,
LCI_IMSI_NO
)
VALUES (
:o_lci_request_id,

:o_lci_seq_order + 2,

:o_lcr_mobile_no,
'DEPROVISION',
'SMS',
'READY',

to_date(:cur_date,'YYYYMMDDHH24MISS'),
'Y',
:o_lci_imsi_no
);

--
varchar o_ocos[40];
varchar o_tcos[40];
varchar o_name[105];
int o_sl;
EXEC SQL
SELECT SVP_OCOS,
SVP_TCOS,
SVP_NAME,
SVP_SERVICE_LEVEL
INTO :o_ocos,
:o_tcos,
:o_name,
:o_sl
FROM smsc_variable_params
WHERE SVP_VALID = 'POSTPAY_MOJ';

if (sqlca.sqlcode == 0)
{
o_ocos.arr[o_ocos.len] = '\0';
o_ocos.len = strlen((char *)o_ocos.arr);

o_tcos.arr[o_tcos.len] = '\0';
o_tcos.len = strlen((char *)o_tcos.arr);

o_name.arr[o_name.len] = '\0';
o_name.len = strlen((char *)o_name.arr);

strcpy(postpay_moj_svp.ocos,(char *)o_ocos.arr);
strcpy(postpay_moj_svp.tcos,(char *)o_tcos.arr);
strcpy(postpay_moj_svp.name,(char *)o_name.arr);
postpay_moj_svp.sl = o_sl;

}
else
{
write_msg("F",REQ,"L","Error while reading
SMSC_VARIABLE_PARAMS Table for SVP_VALID[POSTPAY_MOJ]");
write_msg("F",REQ,"L","SQL Error - <
%.*s>",sqlca.sqlerrm.sqlerrml-1,sqlca.sqlerrm.sqlerrmc);
return(SMSC_CL_FAIL);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy