In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
It is believed that many inexperienced people have no idea about how to use scroll cursors in Oracle. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
/ * function: demonstrated the Oracle scroll 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; / / commit transaction, disconnect} 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 eno / / define host variables char name [10], action; float salary; EXEC SQL DECLARE emp_cursor SCROLL CURSOR FOR Select empno, ename, sal from emp; / / define cursor EXEC SQL OPEN emp_cursor; / / Open cursor EXEC SQL WHENEVER NOT FOUND DO BREAK / / exit loop for (; {printf ("\ nF: first line, P: previous line, N: next line, L: last line\ n") after cursor data extraction; printf ("C: current line, X: exit\ nPlease enter specific action:"); scanf ("% c", & action) Fflush (stdin); switch (action) {case'Falls: case 'f': EXEC SQL FETCH FIRST emp_cursor into: eno,: name,: salary; break Case'Pack: case 'p': EXEC SQL FETCH PRIOR emp_cursor into: eno,: name,: salary; break; case'Night: case' n': EXEC SQL FETCH NEXT emp_cursor into: eno,: name,: salary Break; case'Little: case 'l': EXEC SQL FETCH LAST emp_cursor into: eno,: name,: salary; break Case'Clearing: case 'c': EXEC SQL FETCH CURRENT emp_cursor into: eno,: name,: salary; break; case' Xerox: case 'x': EXEC SQL CLOSE emp_cursor; return } printf ("name =% s (% d), salary =% .2f\ n", name, strlen (name), salary);} printf ("sqlca.sqlerrd [2] =% d\ n", sqlca.sqlerrd [2]) / / sqlca.sqlerrd [2] the number of lines used by the Select statement} after reading the above, have you mastered how to use scrolling cursors in Oracle? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.