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( "Erreur : %s", sqlca.sqlerrm.sqlerrmc );
n_cle_rib = CalculCleRib(c_bq, c_gu, c_cpt);
sprintf( c_cle_rib, "%02d", n_cle_rib );
strcpy( domiciliation, "" );
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.
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( "Erreur : %s", sqlca.sqlerrm.sqlerrmc );
n_cle_rib = CalculCleRib(c_bq, c_gu, c_cpt);
sprintf( c_cle_rib, "%02d", n_cle_rib );
strcpy( domiciliation, "" );
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.