ETL application: How to implement file extraction using Pro*c

Source: Internet
Author: User

/************************************************ Function:* * * * * Extract database records ****************************************** *******/intExtract_data (Char*efilename,Const Char*sqlname) {FILE*Fpwrite;     EXEC SQL BEGIN DECLARE section; varchar v_str_sql[ the+1];/*SQL statements*/varchar Vc_expcol[maxlen];  EXEC SQL END DECLARE section; /**/strcpy ((Char*) v_str_sql.arr,sqlname); V_str_sql.len=strlen ((Char*), #ifdef DEBUG printf (v_str_sql.arr)"SQL statement%s.\n", V_str_sql.arr);#endifEXEC SQL whenever SQLERROR GOTO prepare_exp_error; if(Fpwrite = fopen (Efilename,"w+")) ==NULL) {fprintf (stderr,"cannot open data file%s\n", Efilename); Exit (1); }   /*declaring how cursors are handled*/EXEC SQL PREPARE sqlstmt from:v_str_sql;      EXEC SQL DECLARE extract_cur CURSOR for sqlstmt;   EXEC SQL OPEN extract_cur;  for(;;) {          /*Extracting Data*/EXEC SQL FETCH extract_cur into:vc_expcol; if(Sqlca.sqlcode = =1403) {fprintf (stderr,"data has been extracted or there are no qualifying data!\n");  Break; } Vc_expcol.arr[vc_expcol.len]=' /'; /*log output data to a file*/fprintf (Fpwrite,"%s\n", Vc_expcol.arr); }   /*Close File*/fclose (Fpwrite); /*Close Cursors*/EXEC SQL CLOSE extract_cur; returnSuccess;prepare_exp_error:/*Log error Messages*/fprintf (stderr,"\n%70s\n", SQLCA.SQLERRM.SQLERRMC); fprintf (stderr,"Database operation Error! Exit! "); returnFailuer;}

ETL application: How to implement file extraction using Pro*c

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.