Jeetu Alex - IT Software Professional specialized in developing high-end, customized business solutions using Coldfusion and Java.

Coldfusion
Java
JQuery

An online resource for latest web technologies like Coldfusion, JRun, Pro*C, JQuery, HTML5, PHP, W3C, Java, J2EE, C, C++, ORACLE, PL/SQL, MySql, Ajax, Coldbox, Fusebox, UNIX, JavaScript, NodeJS and much more...

Saturday, February 7, 2009

Calling a stored procedure in Pro*C

#include
#include

EXEC SQL INCLUDE sqlca.h;


typedef char asciz[20];
typedef char vc2_arr[11];

EXEC SQL BEGIN DECLARE SECTION;
/* User-defined type for null-terminated strings */
EXEC SQL TYPE asciz IS STRING(20) REFERENCE;

/* User-defined type for a VARCHAR array element. */
EXEC SQL TYPE vc2_arr IS VARCHAR2(11) REFERENCE;

asciz username;
asciz password;
int dept_no; /* which department to query? */
vc2_arr emp_name[10]; /* array of returned names */
vc2_arr job[10];
float salary[10];
int done_flag;
int array_size;
int num_ret; /* number of rows returned */
EXEC SQL END DECLARE SECTION;

long SQLCODE;



void print_rows(); /* produces program output */
void sql_error(); /* handles unrecoverable errors */



main()
{
int i;
char temp_buf[32];

/* Connect to ORACLE. */
EXEC SQL WHENEVER SQLERROR DO sql_error();
strcpy(username, "scott");
strcpy(password, "tiger");
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user: %s\n\n", username);
printf("Enter department number: ");
gets(temp_buf);
dept_no = atoi(temp_buf);/* Print column headers. */
printf("\n\n");
printf("%-10.10s%-10.10s%s\n", "Employee", "Job", "Salary");
printf("%-10.10s%-10.10s%s\n", "--------", "---", "------");

/* Set the array size. */
array_size = 10;

done_flag = 0;
num_ret = 0;

/* Array fetch loop.
* The loop continues until the OUT parameter done_flag is set.
* Pass in the department number, and the array size--
* get names, jobs, and salaries back.
*/
for (;;)
{
EXEC SQL EXECUTE
BEGIN calldemo.get_employees
(:dept_no, :array_size, :num_ret, :done_flag,
:emp_name, :job, :salary);
END;
END-EXEC;

print_rows(num_ret);

if (done_flag)
break;
}

/* Disconnect from the database. */
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}
void
print_rows(n)
int n;
{
int i;

if (n == 0)
{
printf("No rows retrieved.\n");
return;
}

for (i = 0; i < n; i++)
printf("%10.10s%10.10s%6.2f\n",
emp_name[i], job[i], salary[i]);
}

/* Handle errors. Exit on any error. */
void
sql_error()
{
char msg[512];
int buf_len, msg_len;


EXEC SQL WHENEVER SQLERROR CONTINUE;

buf_len = sizeof(msg);
sqlglm(msg, &buf_len, &msg_len);

printf("\nORACLE error detected:");
printf("\n%.*s \n", msg_len, msg);

EXEC SQL ROLLBACK WORK RELEASE;
exit(1);
}

29 comments :

rekha kommaka said...

understandable code,thanks for giving this.
Oracle Training in Chennai

Jamuna Pandy said...

Oracle is a relational database management system produced by oracle corporation. Nowadays most of the multinational companies used this oracle database for storing and managing their data's and programs. So learning Oracle Training is one of the best idea to make a bright career.

jack wilson said...

Nice post. PHP is one of the server side scripting language mainly used for designing website. So learning PHP Training in Chennai is really useful to make a better career.
Regards..
Html5 Training in Chennai

Jamuna Pandy said...

Nice information. Android is one of the most popular mobile operating system developed by Google. Learning Android Training Chennai is useful to make a wonderful future in mobile application development field.

savitha singh said...

Nice information. Salesforce is a most powerful CRM tool used for manage all customers including potential customers. Salesforce Training in Chennai offering this course with experienced professionals.

Anonymous said...

Really nice post. Unix is a multiuser and multi tasking operating system at the same time. Unix Training in Chennai offering real time Unix course at reasonable cost.

Amirtha rao said...

Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
Regards,
Oracle DBA Training in Chennai|Oracle Training Institute in Chennai|Best Oracle Training Institute in Chennai

Rose Angel said...

We are some sort of fond of image designing along with always keep seeking the revolutionary tips concerning this. thank you regarding discussing concerning this theme. Hold discussing.Buzz For Android

Nikshitha S said...

The strategy you have posted on the oracle hepled me to get into the next level of this technology and had lot of informations in it.
oracle training in chennai | oracle training institutes in chennai

Luckperson said...

Hi, I am initial learn of sql query. Your post is informative for me. Keep updating.
Oracle courses | DBA course

for IT the said...

great

prachi sara said...

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
Hadoop Training Institute In chennai

amilu B said...

Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 


python training in omr

python training in annanagar | python training in chennai

python training in marathahalli | python training in btm layout

python training in rajaji nagar | python training in jayanagar

simbu said...

This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.

java training in omr

java training in annanagar | java training in chennai

java training in marathahalli | java training in btm layout

java training in rajaji nagar | java training in jayanagar

Ram priya said...

Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore

digi mark said...

Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 


rpa training in Chennai

rpa training in pune

rpa online training

rpa training in bangalore

rpa training in Chennai

rpa training in Chennai

rpa training in velachery

rpa training in tambaram

sai said...

I found this informative and interesting blog so i think so its very useful and knowledge able.I would like to thank you for the efforts you have made in writing this article.
python training in rajajinagar
Python training in btm
Python training in usa

gowsalya said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
DevOps online Training

Revathy A said...

This is good site and nice point of view.I learnt lots of useful information.

angularjs Training in chennai
angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

angularjs Training in chennai
angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

shethal said...

At this time, it seems like Word Press is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog? Great post, however, I was wondering if you could write a little more on this subject?
Best AWS Training in Marathahalli | AWS Training in Marathahalli
Amazon Web Services Training in Anna Nagar, Chennai |Best AWS Training in Anna Nagar, Chennai

vijay antony said...


Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
Amazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai
Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai

ajay prakash said...

Very nice blog, Thank you for providing good information.
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
aviation training in chennai
cabin crew training institute in chennai
airlines training chennai
airport ground staff training in chennai

anusha said...


Full Stack Development Training in Chennai Searching for Full Stack Development training in chennai ? Bita Academy is the No 1 Training Institute in Chennai. Call for more details.

William Damian said...

Thankfulness to my dad who informed me relating to this blog, this website is really amazing.
www.telephonecodes.org

rose said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

Microsoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training


sasitamil said...

This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
angularjs online training

apache spark online training

informatica mdm online training

devops online training

aws online training

kiruthika said...

Thank you so much for providing information on this. It was very useful.
Aviation Courses in Chennai
air hostess course in Chennai
airport courses in Chennai
Ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai

Eleanor Eiland said...

Thankfulness to my dad who informed me relating to this blog, this website is really amazing.
www.telephonecodes.org

Unknown said...

I'd like to take the power of thanking you for that specialized guidance I've constantly enjoyed viewing your blog.
www.telephonecodes.org

Post a Comment