- 浏览: 59129 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (42)
- 良好的开发习惯 (3)
- Tomcat question (3)
- mysql (1)
- strus2 (3)
- hibinet的递归实现 (1)
- Eclipse 的jre加载问题 (2)
- cmd netstat (1)
- 配置maven环境 (1)
- server (1)
- jquery 简单操作! (1)
- Oracle (2)
- oracle 函数用法 (2)
- java (3)
- sqlserver (2)
- web (1)
- CMD (2)
- Oracle数据库备份 (1)
- 压力测试 (1)
- nginx (1)
- 语义化版本 2.0.0 (1)
- scp (1)
- 有关 for continue 和 break却别 (1)
function
function 语法中本地调用用 测试用
SELECT TO_DATE('2006-05', 'YYYY-MM') FROM DUAL
-------------------------
create or replace function getmonthfunction(yearandmonth varchar,paten varchar)
return varchar
as
v_sal varchar;
begin
select to_char(add_months(TO_DATE('2014-5', 'YYYY-MM'),-1), 'mm') v_sal from dual ;
return v_sal;
end ;
drop function getmonthfunction;
select getmonthfunction(2014-11,mm) from dual;
select getmonthFunc('2014-12',-5) from dual;
CREATE OR REPLACE FUNCTION getmonthFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
month VARCHAR2(100);
cmonth VARCHAR2(100);
BEGIN
month:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'mm');
if month=1
THEN
cmonth:='AMOUNTJANUARY';
end if;
if month=2
THEN
cmonth:='AMOUNTFEBRUARY';
end if;
if month=3
THEN
cmonth:='AMOUNTMARCH';
end if;
if month=4
THEN
cmonth:='AMOUNTAPRIL';
end if;
if month=5
THEN
cmonth:='AMOUNTMAY';
end if;
if month=6
THEN
cmonth:='AMOUNTJUNE';
end if;
if month=7
THEN
cmonth:='AMOUNTJULY';
end if;
if month=8
THEN
cmonth:='AMOUNTAUGUST';
end if;
if month=9
THEN
cmonth:='AMOUNTSEPTEMBER';
end if;
if month=10
THEN
cmonth:='AMOUNTOCTOBER';
end if;
if month=11
THEN
cmonth:='AMOUNTNOVEMBER';
end if;
if month=12
THEN
cmonth:='AMOUNTDECEMBER';
end if;
RETURN cmonth;
END getmonthFunc;
drop function getmonthFunc
------------------------------------------------------------------------------------------------
select getmonthforNumFunc('2014-12',-5) from dual;
CREATE OR REPLACE FUNCTION getmonthforNumFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
month VARCHAR2(100);
BEGIN
month:=to_number(to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'mm'));
RETURN month;
END getmonthforNumFunc;
select getyearforNumFunc('2014-12',0) from dual;
CREATE OR REPLACE FUNCTION getyearforNumFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
year VARCHAR2(100);
BEGIN
year:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'YYYY');
RETURN year;
END getyearforNumFunc;
==================================================
select getskuassessmenntFunc('2014-12',-3) from dual;
CREATE OR REPLACE FUNCTION getskuassessmenntFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
msg VARCHAR2(100);
num VARCHAR2(100);
BEGIN
num:=substr(num2,2,1);
msg:='skuassessmennt'||num ;
RETURN msg;
END getskuassessmenntFunc;
============================================================
select getskuassessmenntLvFunc('2014-12',-1,'8a8ad0a038d53d3a0138d58b16cf006b','297e57f448a1a8220148a56095613717') from dual;
CREATE OR REPLACE FUNCTION getskuassessmenntLvFunc (yearandmonth IN varchar, num2 IN varchar,departmentid IN varchar,checkty IN varchar )
RETURN VARCHAR2
IS
msg VARCHAR2(100);
num VARCHAR2(100);
Result varchar2(50);
y VARCHAR2(100);
BEGIN
num:=substr(num2,2,1);
msg:='skuassessmennt'||num ;
y:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'YYYY');
if num=1
THEN
select skuassessmennt1 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
if num=2
THEN
select skuassessmennt2 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
if num=3
THEN
select skuassessmennt3 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
RETURN Result;
END getskuassessmenntLvFunc;
===============================================================================
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR;
END TESTPACKAGE;
CREATE OR REPLACE PROCEDURE test2(typestring IN VARCHAR2) IS
BEGIN
INSERT INTO B_ID_temp ( I_ID ,I_NAME)VALUES SELECT I_ID ,I_NAME FROM B_ID
END test2
CREATE OR REPLACE PROCEDURE Proc_Insert(P_CURSOR OUT TESTPACKAGE.TEST_CURSOR,
yearandmonth IN VARCHAR2,
checktypeid IN VARCHAR2,
departmentid IN VARCHAR2,
curtuerid IN VARCHAR2)
IS
str_sql varchar2(4000):='';
amountmonth varchar2(400):='';
amountmonth2 varchar2(400):='';
amountmonth3 varchar2(400):='';
BEGIN
amountmonth:=getmonthFunc(''||yearandmonth||'',-1);
amountmonth2:=getmonthFunc(''||yearandmonth||'',-2);
amountmonth3:=getmonthFunc(''||yearandmonth||'',-3);
str_sql:='INSERT INTO UF_MONTHASSESSMENTTEMPORARY
(id,
department,
province,
area,
customercode,
customer,
productcode,
product,
price,
amountexpect,
amounthistory,
departmentcn,
provincecn,
areacn,
year,
month,
isaccord,
currentUserId
)
SELECT aa.id,
aa.DEPARTMENT,
aa.PROVINCE,
aa.AREA,
aa.CUSTOMERCODE,
aa.CUSTOMER,
aa.PRODUCTCODE,
aa.PRODUCT,
aa.PRICE,
aa.AMOUNTEXPECT,
aa.AMOUNTHISTORY,
aa.DEPARTMENTCN,
aa.PROVINCECN,
aa.AREACN,
aa.YEARBUDGET,
aa.monthbudget,
aa.ISACCORD,
'''||curtuerid||'''currentUserId from (
SELECT zz.id,
zz.DEPARTMENT,
zz.PROVINCE,
zz.AREA,
zz.CUSTOMERCODE,
zz.CUSTOMER,
zz.PRODUCTCODE,
zz.PRODUCT,
zz.PRICE,
zz.AMOUNTEXPECT,
zz.AMOUNTHISTORY,
zz.DEPARTMENTCN,
zz.PROVINCECN,
zz.AREACN,
zz.YEARBUDGET,
zz.monthbudget,
CASE when zz.lv between zz.startlv and zz.endlv then 1 else 0 end as ISACCORD from (
SELECT
uf1.id,
uf1.DEPARTMENT,
uf1.PROVINCE,
uf1.AREA,
uf1.CUSTOMERCODE,
uf1.CUSTOMER,
uf1.PRODUCTCODE,
uf1.PRODUCT,
uf1.PRICE,
uf1.monthprice1 AMOUNTEXPECT,
uf2.'||amountmonth||' AMOUNTHISTORY,
uf1.DEPARTMENTCN,
uf1.PROVINCECN,
uf1.AREACN,
uf1.YEARBUDGET,
uf1.monthbudget,
1 as ISACCORD,
cc.startlv,
cc.endlv,
CASE NVL(UF2.'||amountmonth||',0) WHEN ''0'' THEN 0 ELSE round(NVL(NVL(UF1.monthprice1, 0) / NVL(UF2.'||amountmonth||', 0)*100, 0),2) END lv
FROM UF_MONTHINCOMETEST UF1
LEFT JOIN UF_MIDTBMONTHLICBUDGET UF2
ON UF1.DEPARTMENT = UF2.DEPARTMENT
AND UF1.PRODUCTCODE = UF1.PRODUCTCODE
and uf1.customer=uf2.customercode
AND UF1.PROVINCE = UF2.PROVINCE
AND UF1.AREA = UF2.AREA
AND UF2.YEAR = getyearforNumFunc('''||yearandmonth||''',0)-1
left join (select (100-(100-getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||'''))) startlv,(100+(100-getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||'''))) endlv, getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||''') ,year, department from uf_accuracyparameters ) cc
on uf1.YEARBUDGET=cc.year and uf1.department=cc.department
WHERE UF1.DEPARTMENT = '''||departmentid||'''
AND UF1.YEARBUDGET =getyearforNumFunc('''||yearandmonth||''',-1)
and uf1.monthbudget=getmonthforNumFunc('''||yearandmonth||''',-1) ) zz
) aa';
execute immediate str_sql;
OPEN P_CURSOR FOR
SELECT * FROM UF_MONTHASSESSMENTTEMPORARY;
END Proc_Insert;
DROP TABLE B_ID_temp
DROP PROCEDURE TESTC
EXEC TESTC
SELECT COUNT(*) FROM UF_MONTHASSESSMENTTEMPORARY
DELETE FROM UF_MONTHASSESSMENTTEMPORARY
create global temporary table mytesttemp(id VARCHAR2(32 CHAR) not null,
requestid VARCHAR2(32 CHAR),
nodeid VARCHAR2(32 CHAR),
rowindex VARCHAR2(100 CHAR),
productcode VARCHAR2(256 CHAR),
product VARCHAR2(256 CHAR),
year VARCHAR2(32 CHAR),
updatedate VARCHAR2(32 CHAR),
isdelete INTEGER default 0 not null,
department VARCHAR2(256 CHAR),
province VARCHAR2(256 CHAR),
area VARCHAR2(256 CHAR),
departmentcn VARCHAR2(256 CHAR),
provincecn VARCHAR2(256 CHAR),
areacn VARCHAR2(256 CHAR),
isaccord VARCHAR2(256 CHAR),
currentuserid VARCHAR2(256 CHAR),
preprepremonthaccuracy VARCHAR2(256 CHAR),
preprepremonthscore VARCHAR2(256 CHAR),
prepremonthaccuracy VARCHAR2(256 CHAR),
prepremonthscore VARCHAR2(256 CHAR),
premonthaccuracy VARCHAR2(256 CHAR),
premonthscore VARCHAR2(256 CHAR),
countscore VARCHAR2(256 CHAR),
checktypecn VARCHAR2(256 CHAR),
checktype VARCHAR2(256 CHAR),
recoder VARCHAR2(256 CHAR),
recodercn VARCHAR2(256 CHAR),
month VARCHAR2(256 CHAR)
)
on commit preserve rows
SELECT * FROM mytesttemp
select * into mytesttemp from UF_ASSESSMENTHISTORY
CREATE TABLE UF_ASSESSMENTHISTORY2 AS SELECT * from UF_ASSESSMENTHISTORY
SELECT * FROM UF_ASSESSMENTHISTORY2
CREATE OR REPLACE PROCEDURE getdatefromtable
============================================================
CREATE TABLE SFZ_TEST_MANAGER_XG(
yxgh VARCHAR2(100),
ygxm VARCHAR2(100),
position_name VARCHAR2(100)
);
insert into SFZ_TEST_MANAGER_XG values ('abc1','bcd1','cde1');
insert into SFZ_TEST_MANAGER_XG values ('abc2','bcd2','cde2');
insert into SFZ_TEST_MANAGER_XG values ('abc3','bcd3','cde3');
insert into SFZ_TEST_MANAGER_XG values ('abc4','bcd4','cde4');
SELECT * FROM SFZ_TEST_MANAGER_XG
DROP TABLE SFZ_TEST_MANAGER_XG;
CREATE GLOBAL TEMPORARY TABLE SFZ_TEMP_MANAGER_XG(
yxgh VARCHAR2(100),
ygxm VARCHAR2(100),
position_name VARCHAR2(100)
)ON COMMIT PRESERVE ROWS;
DROP TABLE SFZ_TEMP_MANAGER_XG;
select * from SFZ_TEST_MANAGER_XG;
SFZ_TEMP_MANAGER_XG
select count(*) from SFZ_TEST_MANAGER_XG;
SELECT * FROM SFZ_TEMP_MANAGER_XG
create or replace package sfz_obj
as
type sfz_cursor is ref cursor;
procedure proc_sfz_proc_test(user_yxgh IN VARCHAR2,v_table out sfz_cursor);
end sfz_obj;
create or replace package body sfz_obj as
procedure proc_sfz_proc_test(user_yxgh IN VARCHAR2,v_table out sfz_cursor)
is
BEGIN
INSERT INTO SFZ_TEMP_MANAGER_XG(YXGH,YGXM,POSITION_NAME) SELECT YXGH,YGXM,POSITION_NAME FROM SFZ_TEST_MANAGER_XG;
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
open v_table for select * from SFZ_TEMP_MANAGER_XG;
end proc_sfz_proc_test;
end sfz_obj;
SELECT * FROM SFZ_TEMP_MANAGER_XG
select * from product_component_version;
create or replace procedure area
is
num number ;
v_areaRecord dual%ROWTYPE;
begin
select 12345 into num from dual;
end area;
begin
commit;
end;
CREATE OR REPLACE PROCEDURE Proc_Insert2(P_CURSOR OUT TESTPACKAGE.TEST_CURSOR,
yearandmonth IN VARCHAR2,
checktypeid IN VARCHAR2,
departmentid IN VARCHAR2,
curtuerid IN VARCHAR2)
IS
str_sql varchar2(4000):='';
amountmonth varchar2(400):='';
amountmonth2 varchar2(400):='';
amountmonth3 varchar2(400):='';
BEGIN
amountmonth:=getmonthFunc(''||yearandmonth||'',-1);
amountmonth2:=getmonthFunc(''||yearandmonth||'',-2);
amountmonth3:=getmonthFunc(''||yearandmonth||'',-3);
str_sql:='INSERT INTO UF_MONTHASSESSMENTTEMPORARY
(id,
department,
province,
area,
customercode,
customer,
productcode,
product,
price,
amountexpect,
amounthistory,
departmentcn,
provincecn,
areacn,
year,
month,
isaccord,
currentUserId
)
SELECT aa.id,
aa.DEPARTMENT,
aa.PROVINCE,
aa.AREA,
aa.CUSTOMERCODE,
aa.CUSTOMER,
aa.PRODUCTCODE,
aa.PRODUCT,
aa.PRICE,
aa.AMOUNTEXPECT,
aa.AMOUNTHISTORY,
aa.DEPARTMENTCN,
aa.PROVINCECN,
aa.AREACN,
aa.YEARBUDGET,
aa.monthbudget,
aa.ISACCORD,
'''||curtuerid||'''currentUserId from (
SELECT zz.id,
zz.DEPARTMENT,
zz.PROVINCE,
zz.AREA,
zz.CUSTOMERCODE,
zz.CUSTOMER,
zz.PRODUCTCODE,
zz.PRODUCT,
zz.PRICE,
zz.AMOUNTEXPECT,
zz.AMOUNTHISTORY,
zz.DEPARTMENTCN,
zz.PROVINCECN,
zz.AREACN,
zz.YEARBUDGET,
zz.monthbudget,
CASE when zz.lv between zz.startlv and zz.endlv then 1 else 0 end as ISACCORD from (
SELECT
uf1.id,
uf1.DEPARTMENT,
uf1.PROVINCE,
uf1.AREA,
uf1.CUSTOMERCODE,
uf1.CUSTOMER,
uf1.PRODUCTCODE,
uf1.PRODUCT,
uf1.PRICE,
uf1.monthprice1 AMOUNTEXPECT,
uf2.'||amountmonth2||' AMOUNTHISTORY,
uf1.DEPARTMENTCN,
uf1.PROVINCECN,
uf1.AREACN,
uf1.YEARBUDGET,
uf1.monthbudget,
1 as ISACCORD,
cc.startlv,
cc.endlv,
CASE NVL(UF2.'||amountmonth2||',0) WHEN ''0'' THEN 0 ELSE round(NVL(NVL(UF1.monthprice2, 0) / NVL(UF2.'||amountmonth2||', 0)*100, 0),2) END lv
FROM UF_MONTHINCOMETEST UF1
LEFT JOIN UF_MIDTBMONTHLICBUDGET UF2
ON UF1.DEPARTMENT = UF2.DEPARTMENT
AND UF1.PRODUCTCODE = UF1.PRODUCTCODE
and uf1.customer=uf2.customercode
AND UF1.PROVINCE = UF2.PROVINCE
AND UF1.AREA = UF2.AREA
AND UF2.YEAR = getyearforNumFunc('''||yearandmonth||''',0)-1
left join (select (100-(100-getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||'''))) startlv,(100+(100-getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||'''))) endlv, getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||''') ,year, department from uf_accuracyparameters ) cc
on uf1.YEARBUDGET=cc.year and uf1.department=cc.department
WHERE UF1.DEPARTMENT = '''||departmentid||'''
AND UF1.YEARBUDGET =getyearforNumFunc('''||yearandmonth||''',-2)
and uf1.monthbudget=getmonthforNumFunc('''||yearandmonth||''',-2) ) zz
) aa';
execute immediate str_sql;
OPEN P_CURSOR FOR
SELECT * FROM UF_MONTHASSESSMENTTEMPORARY;
END Proc_Insert2;
调用:
begin
Proc_Insert3('2014-11','297e57f448a1a8220148a56095613717','8a8ad0a038d53d3a0138d58b16cf006b','111111');
commit;
end;
PROCEDURE 和 function 区别:
1.procedure 中调用 function 时 function 变量 用''||XXXX||'', 然而produre中则用'''||||'''
2.function sql 查询字段的话 字段不可以拼变量
========================================
DROP TABLE UF_MONTHASSESSMENTTEMPORARY
create table UF_MONTHASSESSMENTTEMPORARY
(
id VARCHAR2(32 CHAR) not null,
requestid VARCHAR2(32 CHAR),
nodeid VARCHAR2(32 CHAR),
rowindex VARCHAR2(100 CHAR),
customer VARCHAR2(256 CHAR),
customercode VARCHAR2(256 CHAR),
productcode VARCHAR2(256 CHAR),
product VARCHAR2(256 CHAR),
year VARCHAR2(32 CHAR),
updatedate VARCHAR2(32 CHAR),
isdelete INTEGER default 0,
department VARCHAR2(256 CHAR),
province VARCHAR2(256 CHAR),
area VARCHAR2(256 CHAR),
price VARCHAR2(256 CHAR),
numbers VARCHAR2(256 CHAR),
amountexpect VARCHAR2(256 CHAR),
amounthistory VARCHAR2(256 CHAR),
month VARCHAR2(256 CHAR),
departmentcn VARCHAR2(256 CHAR),
provincecn VARCHAR2(256 CHAR),
areacn VARCHAR2(256 CHAR),
isaccord VARCHAR2(256 CHAR),
currentuserid VARCHAR2(256 CHAR),
recodercn VARCHAR2(256 CHAR),
recoder VARCHAR2(256 CHAR)
)
;
alter table UF_MONTHASSESSMENTTEMPORARY
add primary key (ID);
function 语法中本地调用用 测试用
SELECT TO_DATE('2006-05', 'YYYY-MM') FROM DUAL
-------------------------
create or replace function getmonthfunction(yearandmonth varchar,paten varchar)
return varchar
as
v_sal varchar;
begin
select to_char(add_months(TO_DATE('2014-5', 'YYYY-MM'),-1), 'mm') v_sal from dual ;
return v_sal;
end ;
drop function getmonthfunction;
select getmonthfunction(2014-11,mm) from dual;
select getmonthFunc('2014-12',-5) from dual;
CREATE OR REPLACE FUNCTION getmonthFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
month VARCHAR2(100);
cmonth VARCHAR2(100);
BEGIN
month:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'mm');
if month=1
THEN
cmonth:='AMOUNTJANUARY';
end if;
if month=2
THEN
cmonth:='AMOUNTFEBRUARY';
end if;
if month=3
THEN
cmonth:='AMOUNTMARCH';
end if;
if month=4
THEN
cmonth:='AMOUNTAPRIL';
end if;
if month=5
THEN
cmonth:='AMOUNTMAY';
end if;
if month=6
THEN
cmonth:='AMOUNTJUNE';
end if;
if month=7
THEN
cmonth:='AMOUNTJULY';
end if;
if month=8
THEN
cmonth:='AMOUNTAUGUST';
end if;
if month=9
THEN
cmonth:='AMOUNTSEPTEMBER';
end if;
if month=10
THEN
cmonth:='AMOUNTOCTOBER';
end if;
if month=11
THEN
cmonth:='AMOUNTNOVEMBER';
end if;
if month=12
THEN
cmonth:='AMOUNTDECEMBER';
end if;
RETURN cmonth;
END getmonthFunc;
drop function getmonthFunc
------------------------------------------------------------------------------------------------
select getmonthforNumFunc('2014-12',-5) from dual;
CREATE OR REPLACE FUNCTION getmonthforNumFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
month VARCHAR2(100);
BEGIN
month:=to_number(to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'mm'));
RETURN month;
END getmonthforNumFunc;
select getyearforNumFunc('2014-12',0) from dual;
CREATE OR REPLACE FUNCTION getyearforNumFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
year VARCHAR2(100);
BEGIN
year:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'YYYY');
RETURN year;
END getyearforNumFunc;
==================================================
select getskuassessmenntFunc('2014-12',-3) from dual;
CREATE OR REPLACE FUNCTION getskuassessmenntFunc (yearandmonth IN varchar, num2 IN varchar)
RETURN VARCHAR2
IS
msg VARCHAR2(100);
num VARCHAR2(100);
BEGIN
num:=substr(num2,2,1);
msg:='skuassessmennt'||num ;
RETURN msg;
END getskuassessmenntFunc;
============================================================
select getskuassessmenntLvFunc('2014-12',-1,'8a8ad0a038d53d3a0138d58b16cf006b','297e57f448a1a8220148a56095613717') from dual;
CREATE OR REPLACE FUNCTION getskuassessmenntLvFunc (yearandmonth IN varchar, num2 IN varchar,departmentid IN varchar,checkty IN varchar )
RETURN VARCHAR2
IS
msg VARCHAR2(100);
num VARCHAR2(100);
Result varchar2(50);
y VARCHAR2(100);
BEGIN
num:=substr(num2,2,1);
msg:='skuassessmennt'||num ;
y:=to_char(add_months(TO_DATE(yearandmonth, 'YYYY-MM'),num2), 'YYYY');
if num=1
THEN
select skuassessmennt1 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
if num=2
THEN
select skuassessmennt2 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
if num=3
THEN
select skuassessmennt3 into Result from uf_accuracyparameters where year=y and department=departmentid and checktype=checkty;
end if;
RETURN Result;
END getskuassessmenntLvFunc;
===============================================================================
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR;
END TESTPACKAGE;
CREATE OR REPLACE PROCEDURE test2(typestring IN VARCHAR2) IS
BEGIN
INSERT INTO B_ID_temp ( I_ID ,I_NAME)VALUES SELECT I_ID ,I_NAME FROM B_ID
END test2
CREATE OR REPLACE PROCEDURE Proc_Insert(P_CURSOR OUT TESTPACKAGE.TEST_CURSOR,
yearandmonth IN VARCHAR2,
checktypeid IN VARCHAR2,
departmentid IN VARCHAR2,
curtuerid IN VARCHAR2)
IS
str_sql varchar2(4000):='';
amountmonth varchar2(400):='';
amountmonth2 varchar2(400):='';
amountmonth3 varchar2(400):='';
BEGIN
amountmonth:=getmonthFunc(''||yearandmonth||'',-1);
amountmonth2:=getmonthFunc(''||yearandmonth||'',-2);
amountmonth3:=getmonthFunc(''||yearandmonth||'',-3);
str_sql:='INSERT INTO UF_MONTHASSESSMENTTEMPORARY
(id,
department,
province,
area,
customercode,
customer,
productcode,
product,
price,
amountexpect,
amounthistory,
departmentcn,
provincecn,
areacn,
year,
month,
isaccord,
currentUserId
)
SELECT aa.id,
aa.DEPARTMENT,
aa.PROVINCE,
aa.AREA,
aa.CUSTOMERCODE,
aa.CUSTOMER,
aa.PRODUCTCODE,
aa.PRODUCT,
aa.PRICE,
aa.AMOUNTEXPECT,
aa.AMOUNTHISTORY,
aa.DEPARTMENTCN,
aa.PROVINCECN,
aa.AREACN,
aa.YEARBUDGET,
aa.monthbudget,
aa.ISACCORD,
'''||curtuerid||'''currentUserId from (
SELECT zz.id,
zz.DEPARTMENT,
zz.PROVINCE,
zz.AREA,
zz.CUSTOMERCODE,
zz.CUSTOMER,
zz.PRODUCTCODE,
zz.PRODUCT,
zz.PRICE,
zz.AMOUNTEXPECT,
zz.AMOUNTHISTORY,
zz.DEPARTMENTCN,
zz.PROVINCECN,
zz.AREACN,
zz.YEARBUDGET,
zz.monthbudget,
CASE when zz.lv between zz.startlv and zz.endlv then 1 else 0 end as ISACCORD from (
SELECT
uf1.id,
uf1.DEPARTMENT,
uf1.PROVINCE,
uf1.AREA,
uf1.CUSTOMERCODE,
uf1.CUSTOMER,
uf1.PRODUCTCODE,
uf1.PRODUCT,
uf1.PRICE,
uf1.monthprice1 AMOUNTEXPECT,
uf2.'||amountmonth||' AMOUNTHISTORY,
uf1.DEPARTMENTCN,
uf1.PROVINCECN,
uf1.AREACN,
uf1.YEARBUDGET,
uf1.monthbudget,
1 as ISACCORD,
cc.startlv,
cc.endlv,
CASE NVL(UF2.'||amountmonth||',0) WHEN ''0'' THEN 0 ELSE round(NVL(NVL(UF1.monthprice1, 0) / NVL(UF2.'||amountmonth||', 0)*100, 0),2) END lv
FROM UF_MONTHINCOMETEST UF1
LEFT JOIN UF_MIDTBMONTHLICBUDGET UF2
ON UF1.DEPARTMENT = UF2.DEPARTMENT
AND UF1.PRODUCTCODE = UF1.PRODUCTCODE
and uf1.customer=uf2.customercode
AND UF1.PROVINCE = UF2.PROVINCE
AND UF1.AREA = UF2.AREA
AND UF2.YEAR = getyearforNumFunc('''||yearandmonth||''',0)-1
left join (select (100-(100-getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||'''))) startlv,(100+(100-getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||'''))) endlv, getskuassessmenntLvFunc('''||yearandmonth||''',-1,'''||departmentid||''','''||checktypeid||''') ,year, department from uf_accuracyparameters ) cc
on uf1.YEARBUDGET=cc.year and uf1.department=cc.department
WHERE UF1.DEPARTMENT = '''||departmentid||'''
AND UF1.YEARBUDGET =getyearforNumFunc('''||yearandmonth||''',-1)
and uf1.monthbudget=getmonthforNumFunc('''||yearandmonth||''',-1) ) zz
) aa';
execute immediate str_sql;
OPEN P_CURSOR FOR
SELECT * FROM UF_MONTHASSESSMENTTEMPORARY;
END Proc_Insert;
DROP TABLE B_ID_temp
DROP PROCEDURE TESTC
EXEC TESTC
SELECT COUNT(*) FROM UF_MONTHASSESSMENTTEMPORARY
DELETE FROM UF_MONTHASSESSMENTTEMPORARY
create global temporary table mytesttemp(id VARCHAR2(32 CHAR) not null,
requestid VARCHAR2(32 CHAR),
nodeid VARCHAR2(32 CHAR),
rowindex VARCHAR2(100 CHAR),
productcode VARCHAR2(256 CHAR),
product VARCHAR2(256 CHAR),
year VARCHAR2(32 CHAR),
updatedate VARCHAR2(32 CHAR),
isdelete INTEGER default 0 not null,
department VARCHAR2(256 CHAR),
province VARCHAR2(256 CHAR),
area VARCHAR2(256 CHAR),
departmentcn VARCHAR2(256 CHAR),
provincecn VARCHAR2(256 CHAR),
areacn VARCHAR2(256 CHAR),
isaccord VARCHAR2(256 CHAR),
currentuserid VARCHAR2(256 CHAR),
preprepremonthaccuracy VARCHAR2(256 CHAR),
preprepremonthscore VARCHAR2(256 CHAR),
prepremonthaccuracy VARCHAR2(256 CHAR),
prepremonthscore VARCHAR2(256 CHAR),
premonthaccuracy VARCHAR2(256 CHAR),
premonthscore VARCHAR2(256 CHAR),
countscore VARCHAR2(256 CHAR),
checktypecn VARCHAR2(256 CHAR),
checktype VARCHAR2(256 CHAR),
recoder VARCHAR2(256 CHAR),
recodercn VARCHAR2(256 CHAR),
month VARCHAR2(256 CHAR)
)
on commit preserve rows
SELECT * FROM mytesttemp
select * into mytesttemp from UF_ASSESSMENTHISTORY
CREATE TABLE UF_ASSESSMENTHISTORY2 AS SELECT * from UF_ASSESSMENTHISTORY
SELECT * FROM UF_ASSESSMENTHISTORY2
CREATE OR REPLACE PROCEDURE getdatefromtable
============================================================
CREATE TABLE SFZ_TEST_MANAGER_XG(
yxgh VARCHAR2(100),
ygxm VARCHAR2(100),
position_name VARCHAR2(100)
);
insert into SFZ_TEST_MANAGER_XG values ('abc1','bcd1','cde1');
insert into SFZ_TEST_MANAGER_XG values ('abc2','bcd2','cde2');
insert into SFZ_TEST_MANAGER_XG values ('abc3','bcd3','cde3');
insert into SFZ_TEST_MANAGER_XG values ('abc4','bcd4','cde4');
SELECT * FROM SFZ_TEST_MANAGER_XG
DROP TABLE SFZ_TEST_MANAGER_XG;
CREATE GLOBAL TEMPORARY TABLE SFZ_TEMP_MANAGER_XG(
yxgh VARCHAR2(100),
ygxm VARCHAR2(100),
position_name VARCHAR2(100)
)ON COMMIT PRESERVE ROWS;
DROP TABLE SFZ_TEMP_MANAGER_XG;
select * from SFZ_TEST_MANAGER_XG;
SFZ_TEMP_MANAGER_XG
select count(*) from SFZ_TEST_MANAGER_XG;
SELECT * FROM SFZ_TEMP_MANAGER_XG
create or replace package sfz_obj
as
type sfz_cursor is ref cursor;
procedure proc_sfz_proc_test(user_yxgh IN VARCHAR2,v_table out sfz_cursor);
end sfz_obj;
create or replace package body sfz_obj as
procedure proc_sfz_proc_test(user_yxgh IN VARCHAR2,v_table out sfz_cursor)
is
BEGIN
INSERT INTO SFZ_TEMP_MANAGER_XG(YXGH,YGXM,POSITION_NAME) SELECT YXGH,YGXM,POSITION_NAME FROM SFZ_TEST_MANAGER_XG;
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
--insert into SFZ_TEMP_MANAGER_XG values ('abc','bcd','cde');
open v_table for select * from SFZ_TEMP_MANAGER_XG;
end proc_sfz_proc_test;
end sfz_obj;
SELECT * FROM SFZ_TEMP_MANAGER_XG
select * from product_component_version;
create or replace procedure area
is
num number ;
v_areaRecord dual%ROWTYPE;
begin
select 12345 into num from dual;
end area;
begin
commit;
end;
CREATE OR REPLACE PROCEDURE Proc_Insert2(P_CURSOR OUT TESTPACKAGE.TEST_CURSOR,
yearandmonth IN VARCHAR2,
checktypeid IN VARCHAR2,
departmentid IN VARCHAR2,
curtuerid IN VARCHAR2)
IS
str_sql varchar2(4000):='';
amountmonth varchar2(400):='';
amountmonth2 varchar2(400):='';
amountmonth3 varchar2(400):='';
BEGIN
amountmonth:=getmonthFunc(''||yearandmonth||'',-1);
amountmonth2:=getmonthFunc(''||yearandmonth||'',-2);
amountmonth3:=getmonthFunc(''||yearandmonth||'',-3);
str_sql:='INSERT INTO UF_MONTHASSESSMENTTEMPORARY
(id,
department,
province,
area,
customercode,
customer,
productcode,
product,
price,
amountexpect,
amounthistory,
departmentcn,
provincecn,
areacn,
year,
month,
isaccord,
currentUserId
)
SELECT aa.id,
aa.DEPARTMENT,
aa.PROVINCE,
aa.AREA,
aa.CUSTOMERCODE,
aa.CUSTOMER,
aa.PRODUCTCODE,
aa.PRODUCT,
aa.PRICE,
aa.AMOUNTEXPECT,
aa.AMOUNTHISTORY,
aa.DEPARTMENTCN,
aa.PROVINCECN,
aa.AREACN,
aa.YEARBUDGET,
aa.monthbudget,
aa.ISACCORD,
'''||curtuerid||'''currentUserId from (
SELECT zz.id,
zz.DEPARTMENT,
zz.PROVINCE,
zz.AREA,
zz.CUSTOMERCODE,
zz.CUSTOMER,
zz.PRODUCTCODE,
zz.PRODUCT,
zz.PRICE,
zz.AMOUNTEXPECT,
zz.AMOUNTHISTORY,
zz.DEPARTMENTCN,
zz.PROVINCECN,
zz.AREACN,
zz.YEARBUDGET,
zz.monthbudget,
CASE when zz.lv between zz.startlv and zz.endlv then 1 else 0 end as ISACCORD from (
SELECT
uf1.id,
uf1.DEPARTMENT,
uf1.PROVINCE,
uf1.AREA,
uf1.CUSTOMERCODE,
uf1.CUSTOMER,
uf1.PRODUCTCODE,
uf1.PRODUCT,
uf1.PRICE,
uf1.monthprice1 AMOUNTEXPECT,
uf2.'||amountmonth2||' AMOUNTHISTORY,
uf1.DEPARTMENTCN,
uf1.PROVINCECN,
uf1.AREACN,
uf1.YEARBUDGET,
uf1.monthbudget,
1 as ISACCORD,
cc.startlv,
cc.endlv,
CASE NVL(UF2.'||amountmonth2||',0) WHEN ''0'' THEN 0 ELSE round(NVL(NVL(UF1.monthprice2, 0) / NVL(UF2.'||amountmonth2||', 0)*100, 0),2) END lv
FROM UF_MONTHINCOMETEST UF1
LEFT JOIN UF_MIDTBMONTHLICBUDGET UF2
ON UF1.DEPARTMENT = UF2.DEPARTMENT
AND UF1.PRODUCTCODE = UF1.PRODUCTCODE
and uf1.customer=uf2.customercode
AND UF1.PROVINCE = UF2.PROVINCE
AND UF1.AREA = UF2.AREA
AND UF2.YEAR = getyearforNumFunc('''||yearandmonth||''',0)-1
left join (select (100-(100-getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||'''))) startlv,(100+(100-getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||'''))) endlv, getskuassessmenntLvFunc('''||yearandmonth||''',-2,'''||departmentid||''','''||checktypeid||''') ,year, department from uf_accuracyparameters ) cc
on uf1.YEARBUDGET=cc.year and uf1.department=cc.department
WHERE UF1.DEPARTMENT = '''||departmentid||'''
AND UF1.YEARBUDGET =getyearforNumFunc('''||yearandmonth||''',-2)
and uf1.monthbudget=getmonthforNumFunc('''||yearandmonth||''',-2) ) zz
) aa';
execute immediate str_sql;
OPEN P_CURSOR FOR
SELECT * FROM UF_MONTHASSESSMENTTEMPORARY;
END Proc_Insert2;
调用:
begin
Proc_Insert3('2014-11','297e57f448a1a8220148a56095613717','8a8ad0a038d53d3a0138d58b16cf006b','111111');
commit;
end;
PROCEDURE 和 function 区别:
1.procedure 中调用 function 时 function 变量 用''||XXXX||'', 然而produre中则用'''||||'''
2.function sql 查询字段的话 字段不可以拼变量
========================================
DROP TABLE UF_MONTHASSESSMENTTEMPORARY
create table UF_MONTHASSESSMENTTEMPORARY
(
id VARCHAR2(32 CHAR) not null,
requestid VARCHAR2(32 CHAR),
nodeid VARCHAR2(32 CHAR),
rowindex VARCHAR2(100 CHAR),
customer VARCHAR2(256 CHAR),
customercode VARCHAR2(256 CHAR),
productcode VARCHAR2(256 CHAR),
product VARCHAR2(256 CHAR),
year VARCHAR2(32 CHAR),
updatedate VARCHAR2(32 CHAR),
isdelete INTEGER default 0,
department VARCHAR2(256 CHAR),
province VARCHAR2(256 CHAR),
area VARCHAR2(256 CHAR),
price VARCHAR2(256 CHAR),
numbers VARCHAR2(256 CHAR),
amountexpect VARCHAR2(256 CHAR),
amounthistory VARCHAR2(256 CHAR),
month VARCHAR2(256 CHAR),
departmentcn VARCHAR2(256 CHAR),
provincecn VARCHAR2(256 CHAR),
areacn VARCHAR2(256 CHAR),
isaccord VARCHAR2(256 CHAR),
currentuserid VARCHAR2(256 CHAR),
recodercn VARCHAR2(256 CHAR),
recoder VARCHAR2(256 CHAR)
)
;
alter table UF_MONTHASSESSMENTTEMPORARY
add primary key (ID);
相关推荐
本文主要介绍了Oracle存储过程的概念、创建和调用方法,以及如何使用DBLink实现跨库操作。存储过程提供了强大的数据库处理能力,而DBLink则使得不同数据库实例之间的交互变得更加方便和高效。掌握这些技术对于提高...
通过学习和实践这些Oracle存储过程和函数的实例,你可以更好地理解和掌握如何在实际项目中应用它们。Oracle 存储过程详解.doc文档可能包含了更多详细的步骤和示例,建议详细阅读,以深化对这一主题的理解。
以下是一个简单的示例,展示了如何调用一个不带参数的Oracle存储过程: ```java Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session....
### Oracle存储过程学习文档知识点详解 #### 一、Oracle存储过程概述 **1.1 存储过程定义:** ...通过这些知识点的学习,可以更好地理解和掌握Oracle存储过程的应用技巧,从而提高数据库应用程序的性能和安全性。
通过以上对Oracle存储过程、游标和函数的详细介绍,我们可以看到这些特性为Oracle数据库提供了一种强大而灵活的方式来处理数据。掌握这些技术对于开发高效的应用程序至关重要。在未来的学习和实践中,我们应该不断...
Oracle存储过程和函数是数据库管理中的重要组成部分,它们允许开发者创建复杂的业务逻辑和数据处理流程。在这个"Oracle存储过程函数生成DEMO"中,我们主要关注如何在Oracle数据库环境中设计、编写、测试以及调用存储...
### Oracle存储过程返回结果集详解 #### 一、概述 在Oracle数据库中,存储过程是一种重要的编程组件,它能够执行一系列SQL语句并处理复杂的业务逻辑。存储过程的一个常见应用场景是返回结果集(Record Set),这有...
以上就是Java调用Oracle存储过程或函数的主要知识点,实践中要根据具体情况进行适当的调整和优化。在处理过程中,参考Oracle的JDBC文档和官方示例,以及Java API文档,将有助于理解和解决问题。
### Oracle存储过程、函数和包的关键知识点 #### 1. 存储过程和函数的认识 - **定义**:存储过程和函数是特定类型的PL/SQL块,它们被存储在数据库中,作为命名的对象存在。 - **命名存储**:与普通的PL/SQL块不同,...
### Oracle到SQL Server存储过程...在进行数据库迁移时,开发者需要仔细分析现有的Oracle存储过程,然后根据SQL Server的语法特点进行相应的转换。此外,还应考虑到性能优化等问题,确保迁移后的应用程序能够高效运行。
第一章 oracle存储过程概述 2 1.1 存储过程基本结构(PROCEDURE) 3 1.1.1创建存储过程 3 1.1.2 存储过程删除 5 1.1.3 调用存储过程 5 1.2存储函数(FUNCTIONE) 6 1.2.1 创建存储函数 6 1.2.2 删除存储函数 7 1.3 包...
Oracle数据库中的存储过程和函数是PL/SQL编程的重要组成部分。它们是数据库中存储的命名块,可以通过调用其名称来执行预定义的任务。这些命名块有助于实现业务逻辑、企业规则,并允许在多个地方重用代码。本文档将...
在本例中,“Oracle存储过程实例使用显示游标”着重展示了如何在存储过程中调用函数,并通过游标来处理和更新数据。 首先,我们需要了解存储过程的基本结构。一个存储过程通常包含以下部分: 1. **声明部分**:在...
Oracle 存储过程的基本语法包括 PROCEDURE、FUNCTION 和 PACKAGE 等。PROCEDURE 是最基本的存储过程单元,FUNCTION 是带返回值的存储过程,而 PACKAGE 是一组相关的存储过程的集合。 三、 Oracle 存储过程的基本...
通过以上的介绍,我们可以了解到Oracle存储过程的定义、使用方法、变量的定义与声明、游标的使用、循环控制语句、过程控制语句、存储过程的创建和异常处理、触发器的概念与使用、JOB的管理以及SQL优化策略等多个方面...
MySQL与Oracle数据库在存储过程和Function方面的差异主要体现在创建语法、存储结构、参数定义以及包的使用上。下面将详细阐述这些差异。 1. **创建存储过程和函数的语句差异** - Oracle使用`CREATE OR REPLACE ...
### Oracle存储过程的基本语法 #### 3.1.1 基本结构 在Oracle数据库中,存储过程是一种可重复使用的数据库对象,用于封装一系列SQL命令或其他PL/SQL语句,以便于执行复杂的业务逻辑。存储过程的基本结构如下: ``...
在Oracle数据库中,**存储过程**是一组预编译的SQL语句和过程式PL/SQL代码块,存储在数据库服务器上,并作为一个单元执行。它能够接收输入参数、执行复杂的业务逻辑,并且可以返回多个输出值或影响数据库状态。 **...
Oracle存储过程是预编译的SQL语句集合,可以包含SQL查询、控制流语句以及PL/SQL块,提供了一种封装业务逻辑、提高性能和安全性的方法。 **1. JDBC基础知识** JDBC的核心是一组接口和类,它们位于java.sql包中。...
在PL/SQL(Procedural Language/Structured Query Language)环境中,Oracle存储过程集成了SQL和过程性编程语言的功能,提供了一种高效、安全的方式来管理数据。 1. **PL/SQL基础知识** - PL/SQL是由Oracle公司...