實際開發中,什麼時候會用到儲存過程,像網上說的簡單求和?我覺得不是,那樣簡單的例子根本就不能拿來學習儲存過程,那是一條sql就能搞定的事,沒必要動儲存過程大駕,當我們開發的過程中,遇到很複雜的業務邏輯時,而我們只想傳些引數進去,想動態的得到返回結果,在儲存過程裡面去寫好實際的業務問題,動態的拼sql,執行得到結果.
下面舉個mybatis中用到儲存過程的例子:
儲存過程:
create or replace procedure getuserinfos(iname in varchar,cur_arg out sys_refcursor)
is--vsql varchar2(2000);
begin
open cur_arg for select * from userinfo t where t.name like '%'||iname||'%';
end;
我在拼上面sql時,總是執行報錯,||連線的必須是字元,但又不是在select前面開始加字元
以下以介面方式執行sql
public
inte***ce
userdao
type="user"
id="getuserlists">
column="id"
property="id" />
column="name"
property="name" />
resultmap>
id="getuserbyproc"
statementtype="callable"
parametertype="map" >
,#)}
select>
上面的jdbctype的值必須為大寫.
測試**:
**出自
private
static
void
selectoneuserbyproc
(sqlsession sqlsession, userdao userdao)
}
使用游標 引數游標
參游標是指帶有引數的游標。在定義了引數游標之後,當使用不同引數值多次開啟游標時,可以生成不同的結果集。定義引數游標的語法如下 cursor cursor name parameter name datetype is select statement 注意,當定義引數游標時,游標引數只能指定資料型別...
使用游標 游標FOR迴圈
游標for迴圈是在pl sql塊中使用游標最簡單的方式,它簡化了對游標的處理。當使用游標for迴圈時,oracle會隱含的開啟游標,提取游標資料並關閉游標。例子 顯示emp表所有雇員名及其工資 declare cursor emp cursor isselect ename,sal from emp...
MYSQL使用游標
一 使用游標 一 宣告游標。delare cursor name cursor for select statement 解釋 cursor name是游標的名字 select statement表示select語句。因為游標需要遍歷結果集的每一行,增加了伺服器的負擔,導致游標的效率並不高效,如果使...