Oracle query Stored Procedure Call example

Source: Internet
Author: User

Stored Procedure:

Create or replace procedure sp_test
(
Indthm in varchar,
Outfzr out varchar,
Outsjhm out varchar
)
Is

Begin
/* Obtain the first record of the returned result */
Select fzr, sjhm into outfzr, outsjhm from police where DTHM = indthm and rownum = 1;
End;

Procedure Call method:

I. SQL * Plus:

SQL> var A varchar2 (20 );
SQL> var B varchar2 (20 );
SQL> exec sp_test ('w2400001876 ',: A,: B );

PL/SQL procedure successfully completed
A
---------
Zhang San
B
---------
013688888888

 

Ii. PL/SQL:

 

SQL window
Declare fzr varchar2 (20 );
Sjhm varchar2 (20 );
Begin
Sp_test ('w243851876 ', fzr, sjhm );
Dbms_output.put_line (fzr );
Dbms_output.put_line (sjhm );
End;

Command window
SQL> var A varchar2 (20 );
SQL> var B varchar2 (20 );
SQL> exec sp_test ('w2400001876 ',: A,: B );

PL/SQL procedure successfully completed
A
---------
Zhang San
B
---------
013688888888

Iii. vb ado:

 

Gdbname = trim (txtdbname. Text)
Gdbuser = trim (txtuserid. Text)
Gdbpass = trim (txtpassid. Text)
Set adoconn = new ADODB. Connection
Adoconn. Open "provider = oraoledb. Oracle; Password =" + gdbpass + "; user id =" + gdbuser + "; Data Source =" + gdbname

If adoconn. State <> adstateopen then
Msgbox "database connection failed. Please reset the parameter! ", Vbexclamation," system prompt"
Exit sub
End if

Set adocommand = new ADODB. Command
Set adocommand. activeconnection = adoconn
Adocommand. commandtext = "sp_test"
Adocommand. commandtype = adw.storedproc

Adocommand. Parameters. append adocommand. createparameter ("indthm", advarchar, adparaminput, 20, trim (txtdthm. Text ))
Adocommand. Parameters. append adocommand. createparameter ("outfzr", advarchar, adparamoutput, 20)
Adocommand. Parameters. append adocommand. createparameter ("outsjhm", advarchar, adparamoutput, 20)

Adocommand. Execute
Txtfzr. Text = CSTR (adocommand ("outfzr "))
Txtsjhm. Text = CSTR (adocommand ("outsjhm "))

 

 

 

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.