Proc
Proc
Proc
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
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$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$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
-----------------------------------------------------------------------
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
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
clean:
rm -f *.o hworld
https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html
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
--Embedded Commands
--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:
--Statement Labels
-- 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
-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);
-- 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.
(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
-- 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.
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:
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
-------------------
UTL_FILE----------------------------------------------------------------
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';
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;
/
-----------------------------------------------------------------------------------
-----------------------------
varchar o_uid[100];
int o_session_id;
VARCHAR o_smsc_cfg_supp_ref_id[MAX_SIZE_03];
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);
}