标签:declare uri 改变 leo 游标对象 复制 dup 次方 日期格式
create
or
replace
procedure t_p(l_in in
out
number)
is
begin
l_in := 5;
end;
@Test
public void test() throws SQLException
{
DataSource ds = DataSourceGen.getDataSourceFromXML();
Connection conn = ds.getConnection();
int inValue = 0;
CallableStatement cs = conn.prepareCall("{call t_p(?)}");//注意有大括号
cs.setInt(1, inValue);//设置传入的值 下标从1开始
cs.registerOutParameter(1, Types.INTEGER);//注册传出的值
cs.executeUpdate();//执行
int outValue = cs.getInt(1);//获取输出
System.out.println(inValue);//输出0
System.out.println(outValue);//输出5
conn.close();
}
create
or
replace
function t_f(l_in in
out
number)
return
number
is
l_c number;
begin
l_in := 5;
l_c := 2;
return l_c;
end;
@Test
public void test() throws SQLException
{
DataSource ds = DataSourceGen.getDataSourceFromXML();
Connection conn = ds.getConnection();
int inValue = 0;
CallableStatement cs = conn.prepareCall("{? = call t_f(?)}");
cs.setInt(2, inValue);//设置传入的值
cs.registerOutParameter(1, Types.INTEGER);//注册传出的值-通过return返回值
cs.registerOutParameter(2, Types.INTEGER);//注册传出的值-通过参数返回值
cs.executeUpdate();
int outValue1 = cs.getInt(1);
int outValue2 = cs.getInt(2);
System.out.println(inValue);//输出0
System.out.println(outValue1);//输出2
System.out.println(outValue2);//输出5
conn.close();
}
也可以通过select t_f(1) from dual;调用,但是具有out参数的函数不可以通过sql调用。
g_globle number;
procedure set_globle(number_in in number);
end scope_demo;
create or replace package body scope_demo is
procedure set_globle(number_in in number) is
l_count pls_integer;
l_name varchar2(10) := ‘北京‘;
begin
<<localscope>>--标签 为匿名块命名
declare
l_use char(1) := ‘1‘;
begin
select count(1)
into set_globle.l_count
from pub_organ o
where o.organ_name like set_globle.l_name || ‘%‘
and o.in_use = localscope.l_use;
dbms_output.put_line(set_globle.l_count);
end localscope;
scope_demo.g_globle := set_globle.number_in;
end set_globle;
end scope_demo;
begin
scope_demo.set_globle(2);
dbms_output.put_line(scope_demo.g_globle);
end;
procedure local_precedure is
begin
dbms_output.put_line(‘dd‘);
end local_precedure;
begin
for i in 1..10
loop
local_precedure();
end loop;
end;
l_c char(1);
begin
l_c := ‘‘;
if (l_c is null) then
dbms_output.put_line(1);
elsif (l_c = ‘ ‘) then
dbms_output.put_line(2);--输出2 因为自动填满了 而在sql中不会自动填满
end if;
end;
l_n number := ‘10‘;
begin
if(l_n in (‘10‘,‘20‘))
then dbms_output.put_line(‘in‘);
end if;
if(l_n like ‘10%‘)
then dbms_output.put_line(‘like‘);
end if;
end;
l_c pls_integer;
begin
l_c := 0;
loop
--exit when l_c > 10;
if (l_c > 10) then
exit;
end if;
dbms_output.put_line(l_c);
l_c := l_c + 1;
end loop;
end;
declare
l_c pls_integer;
begin
l_c := 0;
while l_c <= 10 loop —while的条件可以加括号 也可以不加
dbms_output.put_line(l_c);
l_c := l_c + 1;
end loop;
end;
只有数值型for循环和游标型(可以是游标,也可以直接是sql查询)for循环,这两种循环都要有in字句。遍历的变量不用声明,系统会自动生成。
begin
for l_c in 0 .. 10 loop –不能加括号
dbms_output.put_line(l_c);
end loop;
end;
begin
for l_organ in (select * from pub_organ o where o.organ_name like ‘北京%‘) loop –查询必须用括号括起来
dbms_output.put_line(l_organ.organ_name);
end loop;
end ;
i pls_integer := 0;
j pls_integer := 0;
begin
<<outerloop>>
loop
dbms_output.put_line(i);
exit when i > 10;
j := 0;
<<innerloop>>
loop
dbms_output.put_line(‘ ‘ || j);
exit when j > 10;
exit outerloop when(j = 5 and i = 5);
j := j + 1;
end loop innerloop;
i := i + 1;
end loop outerloop;
end;
when others then
null;
3、
create
or
replace
procedure t_pp as
l_n number;
begin
update pub_organ o set o.organ_name = ‘dddd444ddd‘ where o.organ_id = ‘O50649821‘;
l_n := ‘ddd‘;--此处出错 本层未捕捉 自动抛出异常到上层
end;
begin
t_pp();--此处会捕捉到下层抛出的异常
exception
when others then
rollback;--回滚
commit;
end;
l_ex1 exception;
l_ex2 exception;
begin
begin
raise l_ex1;
end;
exception
when l_ex2
then dbms_output.put_line(‘l_ex1‘);
end;
l_ex1 exception;
l_ex2 exception;
pragma exception_init(l_ex1,-20111);
pragma exception_init(l_ex2,-20111);
begin
begin
raise l_ex1;
end;
exception
when l_ex2
then dbms_output.put_line(‘l_ex1‘);--此处将成功打印
end;
l_organ_id varchar2(32);
l_organ_name varchar2(500);
begin
l_organ_id := ‘222‘;
select o.organ_name into l_organ_name from pub_organ o where o.organ_id = l_organ_id;
end;
declare
l_organ_id varchar2(32);
l_organ_name varchar2(500);
err_no_organ_1403 exception;
pragma exception_init(err_no_organ_1403, -1403);
begin
l_organ_id := ‘222‘;
select o.organ_name
into l_organ_name
from pub_organ o
where o.organ_id = l_organ_id;
exception
when err_no_organ_1403 then
dbms_output.put_line(‘err_no_organ_1403‘);
end;
declare
l_organ_id varchar2(32);
l_organ_name varchar2(500);
err_no_organ_100 exception;
pragma exception_init(err_no_organ_100, 100);
begin
l_organ_id := ‘222‘;
select o.organ_name
into l_organ_name
from pub_organ o
where o.organ_id = l_organ_id;
exception
when err_no_organ_100 then
dbms_output.put_line(‘err_no_organ_100‘);--成功打印
end;
l_ex1 exception;
pragma exception_init(l_ex1, -20111);
begin
begin
raise_application_error(-20111, ‘ddd‘);
end;
exception
when l_ex1 then
dbms_output.put_line(‘l_ex1‘); --此处将成功打印"l_ex1"
dbms_output.put_line(sqlerrm); --此处将成功打印"ORA-20111: ddd"
end;
l_ex1 exception;
pragma exception_init(l_ex1, -20111);
begin
p_num := 10;
raise_application_error(-20111, ‘ddd‘);
end;
declare
l_num number := 0;
begin
t_pp(l_num);
exception
when others then
null;
dbms_output.put_line(l_num);--输出0
end;
create
or
replace
procedure t_pp as
l_n number;
begin
update pub_organ o set o.organ_name = ‘dddd444ddd‘ where o.organ_id = ‘O50649821‘;
update pub_organ o set o.organ_name = ‘‘ where o.organ_id = ‘O50649831‘;
end;
begin
t_pp();--此处会捕捉到下层抛出的异常
exception
when others then
dbms_output.put_line(dbms_utility.format_error_stack);
dbms_output.put_line(‘..................................‘);
dbms_output.put_line(dbms_utility.format_error_backtrace);
end;
最终打印为:
ORA-01407: 无法更新 ("YJKHECC"."PUB_ORGAN"."ORGAN_NAME") 为 NULL
..................................
ORA-06512: 在 "YJKHECC.T_PP", line 5
ORA-06512: 在 line 2
my_exception exception;
pragma exception_init(my_exception, -20111);
end;
begin
raise_application_error(-20111, ‘ddd‘);
exception
when p_errors.my_exception then
dbms_output.put_line(‘-20111‘);
end;
subtype id_type is varchar(32);
emp_id id_type;
begin
select o.organ_id
into emp_id
from pub_organ o
where o.organ_name = ‘江西省德兴市供电有限责任公司‘;
dbms_output.put_line(emp_id);
exception
when no_data_found then
dbms_output.put_line(‘no_data_found‘);
when too_many_rows then
dbms_output.put_line(‘too_many_rows‘);
when others then
dbms_output.put_line(‘others exception happen‘);
end;
包子类型:
create or replace package scope_demo is
g_globle number := 0;
procedure set_globle(number_in in number);
subtype id_type is varchar(32);
end scope_demo;
declare
emp_id scope_demo.id_type;
begin
select o.organ_id
into emp_id
from pub_organ o
where o.organ_name = ‘江西省德兴市供电有限责任公司‘;
dbms_output.put_line(emp_id);
exception
when no_data_found then
dbms_output.put_line(‘no_data_found‘);
when too_many_rows then
dbms_output.put_line(‘too_many_rows‘);
when others then
dbms_output.put_line(‘others exception happen‘);
end;
type t_names is table of varchar(200);
type t_org_names is table of varchar(200);
l_names t_names;
l_org_names t_org_names;
begin
l_names := t_names(‘1‘, ‘2‘);
for l_name in (select column_value orgName
from table(cast(l_names as t_org_names))) loop
dbms_output.put_line(l_name.orgName);
end loop;
end;
但是,如果使用下面代码,将会成功。
create
type t_names is
table
of
varchar(200);
create type t_org_names is table of varchar(200);
cast不能转换record和object。
(
name VARCHAR2(32 CHAR)
)
plsql中:
declare
l_name VARCHAR2(2 CHAR);
begin
l_name := ‘中文‘;
end;
如果没有设置byte和char,默认值是根据系统参数NLS_LENGTH_SEMANTICS来配置的。
dbms_output.put_line(0.95f);--binary_float 9.49999988E-001
dbms_output.put_line(0.95d);--binary_double 9.4999999999999996E-001
dbms_output.put_line(0.95);--number .95
end;
create or replace package p_records is
type organ is record(
organ_id varchar2(30),
organ_name varchar2(80)
);
type obj is record (
obj_id varchar2(30),
obj_name varchar2(80)
);
end p_records;
declare
l_organ p_records.organ;
l_organ1 p_records.organ;
l_obj p_records.obj;
begin
--对记录赋值 不能new 也没有构造函数 只能逐个属性进行赋值
l_organ.organ_id := ‘01‘;
l_organ.organ_name := ‘国家电网‘;
l_organ1.organ_id := ‘01‘;
l_organ1.organ_name := ‘国家电网‘;
l_obj.obj_id := ‘01‘;
l_obj.obj_name := ‘01‘;
dbms_output.put_line(l_obj.obj_name);
--失败 赋值类型不一致
--l_obj := l_organ;
--成功
l_organ := l_organ1;
/*
--失败 不能对整个record比较
if (l_organ = l_organ1) then
dbms_output.put_line(‘equal‘);
end if;
*/
end;
--对记录进行赋值
declare
type ee is record(
id1 VARCHAR2(2000),
dataid VARCHAR2(255),
fieldname VARCHAR2(40),
content LONG RAW);
l_e ee;
l_d editdata%rowtype;
begin
--into不要求字段类型一摸一样 可以转换即可
--定义的字段长度不一样也可以执行 如果执行时实际长度不够会报错
select * into l_e from editdata t;
l_d := l_e;
l_d.id := ‘newid‘;
if (l_d.id = l_e.id1) then
dbms_output.put_line(‘赋值操作是赋值引用‘);--不打印
else
dbms_output.put_line(‘赋值操作是赋值值‘);--打印
end if;
--插入整个记录 按照字段声明顺序 不是根据名称
insert into editdata values l_d;
--可以对记录赋null 结果就会把所有字段置null
l_d := null;
dbms_output.put_line(l_d.fieldname); --输出空字符串
--不可以对记录判断为空 只能对记录的字段逐个判断 下面注释会报错
--if(l_d is null)
-- then dbms_output.put_line(‘null‘);
--end if;
end;
create table file_test (
file_id varchar2(32),
file_name varchar2(100),
file_path varchar2(200),
file_large number
);
insert into FILE_TEST
(FILE_ID, FILE_NAME, FILE_PATH, FILE_LARGE)
values
(‘1‘, ‘1.txt‘, ‘e:/1.txt‘, 121);
declare
type my_file is record(
file_id varchar2(32),
file_name varchar2(100),
file_path varchar2(200),
file_large number);
type my_image is record(
image_id varchar2(32),
image_name varchar2(100),
image_path varchar2(200),
image_large number);
l_file my_file;
l_image my_image;
l_file_rowtype file_test%rowtype;
begin
--select into的操作 只要字段类型可以匹配即可
--即使记录字段长度与表中的字段长度不一致也可以执行 如果实际插入时的长度不够会报错
select * into l_file from file_test t;
dbms_output.put_line(l_file.file_name);
select * into l_image from file_test t;
dbms_output.put_line(l_image.image_name);
select * into l_file_rowtype from file_test t;
--记录赋值 要求记录的类型是一样的(不是记录的字段的类型)
--例外:rowtype类型的"伪记录" 可以像into一样的赋值
--l_file := l_image;--报错
l_file := l_file_rowtype;
l_image := l_file_rowtype;
for l_filetemp in (select * from file_test) loop
l_file := l_filetemp;
l_image := l_filetemp;
end loop;
dbms_output.put_line(l_file.file_name);
dbms_output.put_line(l_image.image_name);
end;
--不严格要求记录必须是%rowtype 只要record字段与表字段匹配即可
declare
type t_unit is record(
organid VARCHAR2(32),
unit_type VARCHAR2(2),
senddept1 VARCHAR2(32),
ifsend1 CHAR(1));
l_unit t_unit;
l_unit1 t_unit;
begin
l_unit.organid := ‘111‘;
l_unit.unit_type := ‘1‘;
insert into org_unit t values l_unit;
--使用row关键字update
update org_unit t
set row = l_unit
where t.organid = ‘11O000000000000000000000000000‘;
delete from org_unit t
where t.organid = ‘29O000000000000000000000000000‘
returning t.organid, t.unit_type, t.senddept, t.ifsend into l_unit1; --可以returning到记录
dbms_output.put_line(l_unit1.senddept1);
end;
--限制:关联数组只能在declare中声明 不能全局create
--限制:关联数组的index by只能是pls_integer或者varchar2
type t_name is table of varchar2(100) index by pls_integer;
l_t_name t_name;
begin
--不需要构造方法来声明 也不需要extend 直接通过下标插入数据
l_t_name(0) := ‘a‘;
l_t_name(5) := ‘b‘;
l_t_name(9) := ‘c‘;
l_t_name(1000) := ‘d‘;
--对关联数组进行遍历 因为是稀疏的 所以不能使用下标++的方式遍历
declare
l_index pls_integer;
begin
--在oracle中 对于方法或者存储过程的调用可以不加括号 表示不传入参数
l_index := l_t_name.first;
while (l_index is not null) loop
dbms_output.put_line(l_t_name(l_index));
l_index := l_t_name.next(l_index);
end loop;
end;
end;
declare
--必须通过构造函数初始化才能使用(初始化不用new关键字)
family t_names := t_names();
children t_names := t_names();
parents t_names := t_names();
begin
--先extend 在根据下标插入数据 oracle下标从1开始
family.extend(5);
--extend之后默认为null
--不论是嵌套表还是关联数组 VARRAY,对于非法下标的访问都会报no_data_found的错误 extend之后就不是非法的了
if (family(3) is null) then
dbms_output.put_line(‘extend之后默认为null‘);
end if;
family(1) := ‘zjf‘;
family(2) := ‘zcx‘;
family(3) := ‘zdw‘;
family(4) := ‘zsy‘;
family(5) := ‘mcw‘;
--extend默认参数是1
parents.extend;
parents(1) := ‘zsy‘;
parents.extend;
parents(2) := ‘mcw‘;
--只有嵌套表可以使用集合方法
children := family multiset except parents;
--此时还是紧凑的 可以这样遍历
for l_index in children.first .. children.last loop
dbms_output.put_line(children(l_index));
end loop;
end;
create or replace type t_names_v is varray(3) of varchar2(100);
declare
--初始化
l_names t_names_v := t_names_v();
begin
l_names.extend(2);
dbms_output.put_line(l_names.count); --输出2
--为了保持紧凑 delete只能全部删除(不传参数)
l_names.delete;
dbms_output.put_line(l_names.count); --输出0
l_names.extend(2);
--使用trim从尾部删除也能保持紧凑
l_names.trim;
dbms_output.put_line(l_names.count); --输出1
end;
TYPE NumList IS TABLE OF INTEGER;
n NumList := NumList(1, 3, 5, 7);
BEGIN
n.DELETE(2); -- Delete the second element
IF n.EXISTS(1) THEN
DBMS_OUTPUT.PUT_LINE(‘OK, element #1 exists.‘);
END IF;
IF n.EXISTS(2) = FALSE THEN
DBMS_OUTPUT.PUT_LINE(‘OK, element #2 has been deleted.‘);
END IF;
IF n.EXISTS(99) = FALSE THEN
DBMS_OUTPUT.PUT_LINE(‘OK, element #99 does not exist at all.‘);
END IF;
END;
If you want to remove all elements, use DELETE without parameters.
This procedure has various forms:
TYPE last_name_typ IS VARRAY(3) OF VARCHAR2(64);
TYPE surname_typ IS VARRAY(3) OF VARCHAR2(64);
-- These first two variables have the same datatype.
group1 last_name_typ := last_name_typ(‘Jones‘, ‘Wong‘, ‘Marceau‘);
group2 last_name_typ := last_name_typ(‘Klein‘, ‘Patsos‘, ‘Singh‘);
-- This third variable has a similar declaration, but is not the same type.
group3 surname_typ := surname_typ(‘Trevisi‘, ‘Macleod‘, ‘Marquez‘);
-- Allowed because they have the same datatype
-- Not allowed because they have different datatypes
-- group3 := group2; -- raises an error
type t_organ is table of pub_organ%rowtype;
l_organs t_organ := t_organ();
where o.organ_id = ‘O50649765‘;
dbms_output.put_line(l_organs(1).organ_name);
for l_organ in (select * from pub_organ o where o.organ_id = ‘O50649765‘) loop
dbms_output.put_line(l_organs(1).organ_name);
--至今为止 对于集合 record 集合的一行 等的赋值都是值赋值 不是引用赋值
l_organ.organ_name := ‘organ1‘;
l_organ.organ_name := ‘organ2‘;
dbms_output.put_line(l_organ.organ_name); --organ2
dbms_output.put_line(l_organs(1).organ_name); --organ1
CREATE TABLE cust_short (custno NUMBER, name VARCHAR2(31));
CREATE TABLE states (state_id NUMBER, addresses address_array_t);
CAST(MULTISET(SELECT ca.street_address,
type t_nested is table of varchar2(30);
type t_associative is table of varchar2(30) index by pls_integer;
type t_varray is varray(10) of varchar2(30);
dbms_output.put_line(‘nested table is automatic null!‘); --成功打印
if (l_associative is null) then
dbms_output.put_line(‘associative array is automatic null!‘); --不打印 因为关联数组不需要通过构造函数初始化 默认不是null
dbms_output.put_line(‘ varray is automatic null!‘); --成功打印
dbms_output.put_line(‘nested table is automatic null!‘); --不打印
dbms_output.put_line(‘nested table is automatic null!‘); --打印
TYPE dnames_tab IS TABLE OF VARCHAR2(30);
dept_names1 dnames_tab := dnames_tab(‘Shipping‘,‘Sales‘,‘Finance‘,‘Payroll‘);
dept_names2 dnames_tab := dnames_tab(‘Sales‘,‘Finance‘,‘Shipping‘,‘Payroll‘);
dept_names3 dnames_tab := dnames_tab(‘Sales‘,‘Finance‘,‘Payroll‘);
-- We can use = or !=, but not < or >.
-- Notice that these 2 are equal even though the members are in different order.
IF dept_names1 = dept_names2 THEN
DBMS_OUTPUT.PUT_LINE(‘dept_names1 and dept_names2 have the same members.‘);
IF dept_names2 != dept_names3 THEN
DBMS_OUTPUT.PUT_LINE(‘dept_names2 and dept_names3 have different members.‘);
TYPE nested_typ IS TABLE OF NUMBER;
nt1 nested_typ := nested_typ(1,2,3);
nt2 nested_typ := nested_typ(3,2,1);
nt3 nested_typ := nested_typ(2,3,1,3);
nt4 nested_typ := nested_typ(1,2,4);
PROCEDURE testify(truth BOOLEAN DEFAULT NULL, quantity NUMBER DEFAULT NULL) IS
DBMS_OUTPUT.PUT_LINE(CASE truth WHEN TRUE THEN ‘True‘ WHEN FALSE THEN ‘False‘ END);
DBMS_OUTPUT.PUT_LINE(quantity);
answer := nt1 IN (nt2,nt3,nt4); -- true, nt1 matches nt2
answer := nt1 SUBMULTISET OF nt3; -- true, all elements match
answer := nt1 NOT SUBMULTISET OF nt4; -- also true
howmany := CARDINALITY(nt3); -- number of elements in nt3
howmany := CARDINALITY(SET(nt3)); -- number of distinct elements
answer := 4 MEMBER OF nt1; -- false, no element matches
answer := nt3 IS A SET; -- false, nt3 has duplicates
answer := nt3 IS NOT A SET; -- true, nt3 has duplicates
answer := nt1 IS EMPTY; -- false, nt1 has some members
on commit delete rows; --数据只在实务内部有效 不加这句代码 是在session内部有效
解释:oracle为每个事物分配单独的块来存储数据 在事物结束的时候 直接把块清除 也就是说 删除的速度很快 插入时候也不会跟其他事物冲突 两个事物的同一个临时表的操作 相当于两张单独的表
type t_names is table of varchar2(200);
--select o.organ_name into l_names from pub_organ o;
l_organid pub_organ.organ_id%type;
l_organname pub_organ.organ_name%type;
set o.organ_name = ‘new organ‘
where o.organ_id = ‘O50649765‘
returning o.organ_id, o.organ_name into l_organid, l_organname; --返回修改后的信息
dbms_output.put_line(l_organid);
dbms_output.put_line(l_organname); --new organ
delete from pub_stru s where s.organ_id = ‘O50649765‘;
where o.organ_id = ‘O50649765‘
returning o.organ_id, o.organ_name into l_organid, l_organname; --返回删除前的信息
dbms_output.put_line(l_organid);
dbms_output.put_line(l_organname); --new organ
--没有的情况下 将不执行into操作 也不报错 这和select into 不一样
set o.organ_name = ‘new organ‘
returning o.organ_id, o.organ_name into l_organid, l_organname;
dbms_output.put_line(l_organid); --newID
dbms_output.put_line(l_organname); --newName
dbms_output.put_line(sql%rowcount); --0
public void test() throws SQLException
DataSource ds = DataSourceGen.getDataSourceFromXML();
Connection conn = ds.getConnection();
//这句代码报错 报错后数据库会自动回滚当前出错的代码 但是上一条的代码不会自动回滚 等待commit或者rollback代码来处理
ps = conn.prepareStatement("update pub_organ o set o.in_use = ‘11‘ where o.organ_id = ‘O50649765‘");
// TODO Auto-generated catch block
//close会触发commit 所以这里第一条语句执行成功 第二条执行失败
where o.organ_id = ‘O50649765‘;
update pub_organ o set o.in_use = ‘11‘ where o.organ_id = ‘O50649765‘;
where o.organ_id = ‘O50649765‘;
所以,如果是存储过程,应该将异常在存储过程内部处理掉,不要抛出到应用层,应该返回错误信息给应用层。
where o.organ_id = ‘O50649765‘;
update pub_organ o set o.in_use = ‘11‘ where o.organ_id = ‘O50649765‘;
where o.organ_id = ‘O50649765‘;
游标并不是指向数据库表的指针,而是指向虚拟表的,这张虚拟表只在查询期间存在,为了满足读一致性。游标的结果集是游标打开那个时间点的有效数据。不是fetch时的实时数据。
type cur_organ is ref cursor return pub_organ%rowtype;
--也可以使用下面代码 至今为止 所有的into操作不强制要求类型是%rowtype
select * from pub_organ o where o.organ_id = ‘O50649765‘;
where o.organ_id = ‘O50649765‘;
--输出"江西省全南县供电有限责任公司" 不是newname 符合读一致性
dbms_output.put_line(l_organ.organ_name);
type cur_organ is ref cursor return pub_organ%rowtype;
select * from pub_organ o where o.organ_id = ‘O50649765‘;
select * from pub_organ o where o.organ_id = ‘O50649773‘;
dbms_output.put_line(l_organ.organ_name);
如果是隐式游标,那么应该在查询代码之后即可执行游标的相关属性,因为中间执行了其他查询后,sql%的信息就是新查询的了。
create or replace package p_cursors is
select * from pub_organ o where rownum < 100;
l_organ p_cursors.cur_organ%rowtype;
exit when p_cursors.cur_organ%notfound;
dbms_output.put_line(l_organ.organ_name);
execute immediate ‘select * from pub_organ o where o.organ_id = :organ_id‘
dbms_output.put_line(l_organ.organ_name);
execute immediate ‘create table pub_organ_‘ || to_char(sysdate, ‘DD‘);
execute immediate ‘begin proc_name_‘ || to_char(sysdate, ‘DD‘) || ‘ end;‘;
open l_cur for ‘select /* zjf_flag100 */ * from pub_organ o where o.organ_name like :oname‘
dbms_output.put_line(l_organ.organ_name);
l_organ_name pub_organ.organ_name%type;
using ‘newname‘, ‘O50649765‘, out l_organ_name;
dbms_output.put_line(l_organ_name);
create or replace package p_globle is
create or replace function f_package_test return number is
create or replace procedure p_package_test is
public static void main(String[] args) {
DataSource ds = DataSourceGen.getDataSourceFromXML();
CallableStatement cs = conn.prepareCall("{call p_package_test()}");
cs = conn.prepareCall("{? = call f_package_test()}");
cs.registerOutParameter(1, Types.NUMERIC);
System.out.println(cs.getDouble(1));//还是那个connection 输出1
conn = ds.getConnection();//重新建立一个连接
cs = conn.prepareCall("{? = call f_package_test()}");
cs.registerOutParameter(1, Types.NUMERIC);
System.out.println(cs.getDouble(1));//输出0
标签:declare uri 改变 leo 游标对象 复制 dup 次方 日期格式
原文地址:http://www.cnblogs.com/xiaolang8762400/p/7078687.html