In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to embed pl/sql blocks in Pro*C, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
/ * include C header file * /
# include
# include
# include
/ * include SQLCA header file * /
EXEC SQL INCLUDE sqlca
EXEC SQL INCLUDE sqlda
Int main ()
{
EXEC SQL BEGIN DECLARE SECTION
Int money
Char answerbuff [200]
Int flag
Char username [10], password [10], server [10]
EXEC SQL END DECLARE SECTION
/ *
* define input host variables: receive user name, password and network service name
*
, /
Strcpy (username, "data_center")
Strcpy (password, "data_center")
Strcpy (server, "oradf1"); / * the SID*/ of the database is entered here
/ * Connect to the database * /
EXEC SQL CONNECT: username IDENTIFIED BY: password USING: server
If (sqlca.sqlcode==0)
Printf ("connected successfully! / n")
Else
/ * Show connection error message * /
Printf ("%. * Spura", sqlca.sqlerrm.sqlerrml
Sqlca.sqlerrm.sqlerrmc)
/ * initialize * /
Money=0
Flag=0; / * use days to determine whether data is found * /
/ * execute plsql block * /
EXEC SQL EXECUTE
BEGIN
SELECT salary INTO: money FROM plsqltest WHERE name='ht'
: flag:=1
EXCEPTION
WHEN NO_DATA_FOUND THEN
: answerbuff:=' data was not found'
END
END-EXEC
/ * output result * /
If (flag==0)
Printf ("% SSPO", answerbuff)
Else
Printf ("Total salary is:% DPo", money)
}
=
Compilation method:
1. If a PL/SQL block is embedded in the PC source program, the SQLCHECK should either SEMANTICS or FULL
two。 When the value of SQLCHECK is SEMANTICS or FULL, USERID must be set
Proc PARSE=NONE include=-I/opt/oracle/product/10.2.0/precomp/public include=-I/opt/oracle/product/10.2.0/rdbms/public sqlcheck=fullUSERID=data_center/data_center@oradf1 iname=test.pc oname=test.c
Some of the options of gcc, without these, sometimes report errors.
Gcc-L/opt/oracle/product/10.2.0/lib-lclntsh-ldl-lm-lnsl-o test test.c
=
Create a table:
Create table PLSQLTEST
(
Salary NUMBER
NAME VARCHAR2 (10)
);
Insert into plsqltest (salary, NAME)
Values (1000, 'xym')
Insert into plsqltest (salary, NAME)
Values (2000, 'ht')
Commit
After reading the above, do you have any further understanding of how to embed pl/sql blocks in Pro*C? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.