Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In the following lines of codes, I

Status
Not open for further replies.

spirou

Programmer
Oct 22, 2001
22
FR
In the following lines of codes, I tried to insert some records of a table into another. There is a cursor witch has an ORDER BY clause on the field N_RIB. The insert comes after some work.
Just a example of what's going wrong :

Source Table N_RIB : 2, 3, 1
Program Insert Work : 1, 2, 3
Result Table N_RIB : 2, 3, 1

So the order by clause doesn't affect how records are ordered.

Here is some of my code :


void InsertionRibs( char N_PMP[11], char N_EXT_PMP[11] )
{
int n_rib;
char c_cle_rib[5];
int n_cle_rib;
char c_bq[6], c_gu[6], c_cpt[12];
char ribOK[3];
char domiciliation[61];

EXEC SQL WHENEVER SQLERROR DO sql_error( "Erreur ORACLE" );

EXEC SQL DECLARE sel_ribs CURSOR FOR
SELECT n_rib,
l_banq_cpt_princ,
l_guich_cpt_princ,
l_cpt_princ
FROM bol_ribs
WHERE PMP_N_PMP = :N_PMP
ORDER BY N_RIB;
EXEC SQL OPEN sel_ribs;

for( ; ; )
{
EXEC SQL FETCH sel_ribs INTO :n_rib, :c_bq, :c_gu, :c_cpt;

if( sqlca.sqlcode == ORA_NOTFOUND ) break;
if( sqlca.sqlcode > 0 )
{
printf( "Erreur Fatale: %s", sqlca.sqlerrm.sqlerrmc );
break;
}
if( sqlca.sqlcode < 0 )
printf( &quot;Erreur : %s&quot;, sqlca.sqlerrm.sqlerrmc );

n_cle_rib = CalculCleRib(c_bq, c_gu, c_cpt);
sprintf( c_cle_rib, &quot;%02d&quot;, n_cle_rib );


strcpy( domiciliation, &quot;&quot; );

EXEC SQL INSERT INTO TAB_RIBS ( SELECT
:n_rib,
PMP_N_PMP,
PMP_N_EXT_PMP,
L_PREPO_VIL_BQ,
L_RIB_LIBELLE,
C_PAYS_CPT_PRINC,
L_BANQ_CPT_PRINC,
L_GUICH_CPT_PRINC,
L_CPT_PRINC,
:c_cle_rib,
to_date(D_DEB_UTIL,'YYYYMMDD'),
to_date(D_FIN_UTIL,'YYYYMMDD'),
L_PHONE_RESP_CPT,
L_VILLE,
:domiciliation,
C_REF_ANT,
L_NOM_RESP_CPTE,
C_TYPE_RIB
FROM BOL_RIBS
WHERE PMP_N_PMP = :N_PMP
AND N_RIB = :n_rib );
EXEC SQL COMMIT;
}
EXEC SQL CLOSE sel_ribs;
}


Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top