| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> How to make the spaces be gone?
Hi,
Using Pro*C++ I select all records
of specific table from Database.
However I can't get *pure* (without spaces) value
of VARCHAR2-column.
For instance (see below):
1) value of column FFF4 in table FFF is
ZZZ_1_4 // Record#1 [missing] // Record#2 ZZZ_3_4 // Record#3
2) My host variable col_value4 are char [15].
3) Value of col_value4 is
col [4] : value = <ZZZ_1_4 >, indicator = <0> // Record#1
col [4] : value = < >, indicator = <-1> // Record#2
col [4] : value = <ZZZ_3_4 >, indicator = <0> // Record#3
Note. The values contain spaces.
4) I would like to get output as following (using Pro*/C++ features):
col [4] : value = <ZZZ_1_4>, indicator = <0> // Record#1
col [4] : value = --- Never mind ---, indicator = <-1> // Record#2
col [4] : value = <ZZZ_3_4>, indicator = <0> // Record#3
Thanks in advance,
Alex
//#########################################################
//------------------- Pro*C++ code : BEGIN ----------------
// File ttt2.pc
#include <stdio.h>
#include <strings.h>
#include <assert.h>
#include <iostream.h>
#include <sqlca.h>
#include <oraca.h>
//=========================================
#define PRINT_VALUE(col_no, col_value, col_indicator) \
cout << "" \ << " \t" \ << "col [" \ << col_no \ << "] : " \ << "value = <" \ << col_value \ << ">" \ << ", " \ << "indicator = <" \ << col_indicator \ << ">" \ << endl //========================================= void sql_error_print ( const char * const msg_i, const char * const conclusion_i ) { cout << msg_i << " : " << conclusion_i << "; sqlca.sqlcode = " << sqlca.sqlcode << endl; cout << "" << sqlca.sqlerrm.sqlerrmc << endl; cout << "in " << oraca.orastxt.orastxtc << "..." << endl; cout << "on line " << oraca.oraslnr << " " << "of " << oraca.orasfnm.orasfnmc << endl; EXEC SQL WHENEVER SQLERROR CONTINUE; EXEC SQL ROLLBACK RELEASE;
} // void sql_error_print ()
//=========================================void sql_error_action (const char * const msg_i) {
sql_error_print (msg_i, "Cannot Do It");
assert (0);
//=========================================void ListRecords()
long col_value1; char col_value2[15]; char col_value3[15]; char col_value4[15]; char col_value5[15]; short indicator1; short indicator2; short indicator3;
EXEC SQL END DECLARE SECTION;
//===========================
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("PREPARE
the_exec");
EXEC SQL PREPARE the_exec FROM :select_col_value;
//===========================
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("DECLARE
the_cursor");
EXEC SQL DECLARE the_cursor CURSOR FOR the_exec;
//===========================
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("OPEN
the_cursor");
EXEC SQL OPEN the_cursor;
cout << "Available records: " << endl;
for(int i = 1; ;i++)
{
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("FETCH
the_cursor");
EXEC SQL FETCH the_cursor INTO
:col_value1 INDICATOR
:indicator1,
:col_value2 INDICATOR
:indicator2,
:col_value3 INDICATOR
:indicator3,
:col_value4 INDICATOR
:indicator4,
:col_value5 INDICATOR
:indicator5;
if (sqlca.sqlcode == 1403)
{
cout << "BREAK-" << sqlca.sqlcode << endl;
break;
}
//===========================================
cout << "======================================="
<< endl;
cout << "select ["
<< i
<< "] : \t"
<< "sqlca.sqlcode = <"
<< sqlca.sqlcode
<< ">"
<< endl;
PRINT_VALUE (1, col_value1, indicator1);
PRINT_VALUE (2, col_value2, indicator2);
PRINT_VALUE (3, col_value3, indicator3);
PRINT_VALUE (4, col_value4, indicator4);
PRINT_VALUE (5, col_value5, indicator5);
cout << endl;
//===========================================
} // for(int i = 1; ;i++)
cout << "FINISH " << endl;
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("CLOSE
the_cursor");
EXEC SQL CLOSE the_cursor;
} // void ListRecords()
//===============================
char *username = "aaa"; char *password = "bbb";
//===========================
EXEC SQL WHENEVER SQLERROR DO sql_error_action ("Connect to
ORACLE");
EXEC SQL CONNECT :username IDENTIFIED BY :password;
cout << endl << "Connected to ORACLE." << endl;
//===========================
cout << endl;
ListRecords ();
return 0;
//------------------- Pro*C++ code : END ------------------ //######################################################### //------------------- Database Status : BEGIN -------------
SQL> select * from FFF;
FFF1 FFF2 FFF3 FFF4 FFF5
---------- ---------- ---------- ------------------- ------------
19 13 ZZZ_1_4 ZZZ_1_5
12 22 ZZZ_2_5
15 32 33 ZZZ_3_4
//------------------- Database Status : END ---------------
//#########################################################
//------------------- Running Results : BEGIN -------------
Connected to ORACLE.
Available records:
col [1] : value = <19>, indicator = <0>
col [2] : value = < >, indicator = <-1>
col [3] : value = <13 >, indicator = <0>
col [4] : value = <ZZZ_1_4 >, indicator = <0>
col [5] : value = <ZZZ_1_5 >, indicator = <0>
=======================================
select [2] : sqlca.sqlcode = <0>
col [1] : value = <12>, indicator = <0>
col [2] : value = <22 >, indicator = <0>
col [3] : value = < >, indicator = <-1>
col [4] : value = < >, indicator = <-1>
col [5] : value = <ZZZ_2_5 >, indicator = <0>
=======================================
select [3] : sqlca.sqlcode = <0>
col [1] : value = <15>, indicator = <0>
col [2] : value = <32 >, indicator = <0>
col [3] : value = <33 >, indicator = <0>
col [4] : value = <ZZZ_3_4 >, indicator = <0>
col [5] : value = < >, indicator = <-1>
BREAK-1403
FINISH
//------------------- Running Results : END --------------- //######################################################### //------------------- Environment -------------------------- === Oracle 8.0.5
//--------------------------------------------------------- //#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Sun Oct 17 1999 - 08:25:10 CDT
![]() |
![]() |