In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to use non-scrolling cursors in Oracle. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
/ * function: demonstrated the Oracle non-scrolling cursor operation when defining cursors: 1. DECLARE CURSOR statement must be the first statement to use cursors 2. The cursor name is an identifier, not a host variable, and its length is arbitrary, but only the first 31 characters are valid. The SELECT statement corresponding to the cursor cannot contain the INTO clause 4. Cursor statements (DECLARE,OPEN,FETCH,CLOSE) must be in the same precompiled unit * / # include # pragma comment (lib, "orasql10.lib") int connect (); void cursor (); void sql_error (); void main () {EXEC SQL WHENEVER SQLERROR DO sql_error (); / / install error handler if (connect () = = 0) {cursor () EXEC SQL COMMIT RELEASE;} else printf ("connection failed\ n");} int connect () / / connect to oracle database {char username [10], password [10], server [10]; strcpy (username, "scott"); strcpy (password, "zzb888888") Strcpy (server, "orcl"); EXEC SQL CONNECT: username IDENTIFIED BY: password USING: server; if (sqlca.sqlcode = = 0) return 0; else return sqlca.sqlcode;} void sql_error () / / print error infomation {printf ("%. * s\ n", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc) } void cursor () / / cursor operation {int dno, eno; / / define host variable char name [10]; float salary; printf ("enter department number:"); scanf ("% d", & dno) EXEC SQL DECLARE emp_cursor CURSOR FOR Select empno, ename, sal from emp where deptno=:dno; / / define cursor EXEC SQL OPEN emp_cursor; / / Open cursor EXEC SQL WHENEVER NOT FOUND DO break; / / exit loop for (; {EXEC SQL FETCH emp_cursor into: eno,: name,: salary after cursor data extraction is finished / / cycle to extract data printf ("name =% s (% d), salary =% .2f\ n", name, strlen (name), salary);} EXEC SQL CLOSE emp_cursor; / / close cursor printf ("sqlca.sqlerrd [2] =% d\ n", sqlca.sqlerrd [2]); / / sqlca.sqlerrd [2] stores the number of rows where the Select statement acts
Running result:
Enter department number: 20
Name = SMITH (9), salary = 800.00
Name = JONES (9), salary = 2975.00
Name = SCOTT (9), salary = 3000.00
Name = ADAMS (9), salary = 1100.00
Name = FORD (9), salary = 3000.00
Sqlca.sqlerrd [2] = 5
On how to use non-scrolling cursors in Oracle to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.