Oracle 스토리지 프로세스 동적 SQL 바인딩 변수
create or replace procedure proc_generate_demand_note
(
totalTaxNo in varchar2,
userId in varchar2,
dpCode in varchar2,
ifTaxation in varchar2,
invalidFlag in varchar2,
payCompany in varchar2,
taxBillType in varchar2,
personalEntryId in varchar2,
taxNo in varchar2,
logisticsNo in varchar2,
ifPrint in varchar2,
totalTaxBegin in number,
totalTaxEnd in number,
declareDateBegin in varchar2,
declareDateEnd in varchar2,
execMsg out varchar2
)
as
select_sql varchar2(2000);
v_cursor integer;
v_count integer;
v_tax_no varchar2(18);
v_quantity number(10,5);
v_dutypaid_price number(10,5);
v_actual_tax number(10,5);
v_decl_tm Date;
v_head_id number(19);
v_cbecbill_no varchar2(20);
v_temp varchar2(100);
some_kinds_of_err EXCEPTION;
begin
/* */
if totalTaxNo is null then
v_temp := ' !';
raise some_kinds_of_err;
end if;
if userId is null then
v_temp := ' !';
raise some_kinds_of_err;
end if;
if dpCode is null then
v_temp := ' !';
raise some_kinds_of_err;
end if;
if ifTaxation is null then
v_temp := ' !';
raise some_kinds_of_err;
end if;
if invalidFlag is null then
v_temp := ' !';
raise some_kinds_of_err;
end if;
--
v_cursor := dbms_sql.open_cursor;
/* */
select_sql := 'select t1.TAX_NO, t2.QUALITYS, t2.DUTYPAID_PRICES, t1.TOTAL_TAX, t1.DECL_TM, t1.HEAD_ID, t1.CBECBILL_NO ';
select_sql := select_sql || 'from TB_B_TAX t1, (select a.TAX_NO, sum(c.QUALITY) QUALITYS, sum(c.DUTYPAID_PRICE) DUTYPAID_PRICES ';
select_sql := select_sql || 'from TB_B_TAX a, TB_IE_MINIFEST_HEAD b, TB_B_TAX_DETAIL c ';
select_sql := select_sql || 'where a.HEAD_ID = b.ID and a.TAX_NO = c.TAX_NO ';
-- SQL
select_sql := select_sql || 'and a.DP_CODE = :DP_CODE ';
select_sql := select_sql || 'and a.IF_TAXATION = :IF_TAXATION ';
select_sql := select_sql || 'and a.INVALID_FLAG = :INVALID_FLAG ';
if payCompany is not null then
select_sql := select_sql || 'and a.PAY_COMPANY = :PAY_COMPANY ';
end if;
if taxBillType is not null then
select_sql := select_sql || 'and a.TAX_BILL_TYPE = :TAX_BILL_TYPE ';
end if;
if personalEntryId is not null then
select_sql := select_sql || 'and b.PERSONAL_ENTRY_ID like :PERSONAL_ENTRY_ID ';
end if;
if taxNo is not null then
select_sql := select_sql || 'and a.TAX_NO like :TAX_NO ';
end if;
if logisticsNo is not null then
select_sql := select_sql || 'and b.LOGISTICS_NO like :LOGISTICS_NO ';
end if;
if ifPrint is not null then
select_sql := select_sql || 'and a.IF_PRINT = :IF_PRINT ';
end if;
if totalTaxBegin is not null then
select_sql := select_sql || 'and a.TOTAL_TAX >= :TOTAL_TAX_BEGIN ';
end if;
if totalTaxEnd is not null then
select_sql := select_sql || 'and a.TOTAL_TAX <= :TOTAL_TAX_END ';
end if;
if declareDateBegin is not null then
select_sql := select_sql || 'and b.DECLARE_DATE >= to_date(:DECLARE_DATE_BEGIN, ''yyyy-mm-dd hh24:mi:ss'') ';
end if;
if declareDateEnd is not null then
select_sql := select_sql || 'and b.DECLARE_DATE <= to_date(:DECLARE_DATE_END, ''yyyy-mm-dd hh24:mi:ss'') ';
end if;
select_sql := select_sql || 'and (sysdate - b.discharge_date) > 14 ';
select_sql := select_sql || 'group by a.TAX_NO) t2 where t1.TAX_NO = t2.TAX_NO ';
-- SQL
dbms_sql.parse(v_cursor, select_sql, dbms_sql.native);
--
dbms_sql.bind_variable(v_cursor, ':DP_CODE', dpCode);
dbms_sql.bind_variable(v_cursor, ':IF_TAXATION', ifTaxation);
dbms_sql.bind_variable(v_cursor, ':INVALID_FLAG', invalidFlag);
if payCompany is not null then
dbms_sql.bind_variable(v_cursor, ':PAY_COMPANY', payCompany);
end if;
if taxBillType is not null then
dbms_sql.bind_variable(v_cursor, ':TAX_BILL_TYPE', taxBillType);
end if;
if personalEntryId is not null then
dbms_sql.bind_variable(v_cursor, ':PERSONAL_ENTRY_ID', personalEntryId);
end if;
if taxNo is not null then
dbms_sql.bind_variable(v_cursor, ':TAX_NO', taxNo);
end if;
if logisticsNo is not null then
dbms_sql.bind_variable(v_cursor, ':LOGISTICS_NO', logisticsNo);
end if;
if ifPrint is not null then
dbms_sql.bind_variable(v_cursor, ':IF_PRINT', ifPrint);
end if;
if totalTaxBegin is not null then
dbms_sql.bind_variable(v_cursor, ':TOTAL_TAX_BEGIN', totalTaxBegin);
end if;
if totalTaxEnd is not null then
dbms_sql.bind_variable(v_cursor, ':TOTAL_TAX_END', totalTaxEnd);
end if;
if declareDateBegin is not null then
dbms_sql.bind_variable(v_cursor, ':DECLARE_DATE_BEGIN', declareDateBegin);
end if;
if declareDateEnd is not null then
dbms_sql.bind_variable(v_cursor, ':DECLARE_DATE_END', declareDateEnd);
end if;
-- v_cursor select
dbms_sql.define_column(v_cursor, 1, v_tax_no, 20);
dbms_sql.define_column(v_cursor, 2, v_quantity);
dbms_sql.define_column(v_cursor, 3, v_dutypaid_price);
dbms_sql.define_column(v_cursor, 4, v_actual_tax);
dbms_sql.define_column(v_cursor, 5, v_decl_tm);
dbms_sql.define_column(v_cursor, 6, v_head_id);
dbms_sql.define_column(v_cursor, 7, v_cbecbill_no, 20);
-- SQL
v_count := dbms_sql.execute(v_cursor);
loop
exit when dbms_sql.fetch_rows(v_cursor) <= 0;
--
dbms_sql.column_value(v_cursor, 1, v_tax_no);
dbms_sql.column_value(v_cursor, 2, v_quantity);
dbms_sql.column_value(v_cursor, 3, v_dutypaid_price);
dbms_sql.column_value(v_cursor, 4, v_actual_tax);
dbms_sql.column_value(v_cursor, 5, v_decl_tm);
dbms_sql.column_value(v_cursor, 6, v_head_id);
dbms_sql.column_value(v_cursor, 7, v_cbecbill_no);
/* */
insert into tb_b_meger_tax_detail (ID, TOTAL_TAX_NO, TAX_NO, CBECBILL_NO, ACTUAL_TAX, DECL_TM, QUANTITY, DUTYPAID_PRICE, HEAD_ID)
values (I_MEGER_TAX_DETAIL_SQC.nextval, totalTaxNo, v_tax_no, v_cbecbill_no,
v_actual_tax, v_decl_tm, v_quantity, v_dutypaid_price, v_head_id);
/* */
update TB_B_TAX t set t.TOTAL_TAX_NO = totalTaxNo, t.STATUS = '2' where t.TAX_NO = v_tax_no;
/* */
insert into TB_B_TAX_OPERATE (ID, OPRATOR, OPRATE_TM, TAX_NO, OPERATE_TYPE, OPERATE_REASON)
values (SEQ_B_TAX_OPERATE.nextval, userId, sysdate, v_tax_no, '4', ' ');
end loop;
--
dbms_sql.close_cursor(v_cursor);
--
commit;
execMsg := ' !';
--
exception
when some_kinds_of_err then
execMsg := ' ,' || v_temp;
when others then
rollback;
execMsg := ' !';
end proc_generate_demand_note;
2. JAVA 프로그램 호출 방법
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public String generateDemandNote(final QueryCondition qc) {
return jdbcTemplate.execute(new CallableStatementCreator() {
@Override
public CallableStatement createCallableStatement(Connection conn) throws SQLException {
String storeProc = "{ call proc_generate_demand_note(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }";
CallableStatement cs = conn.prepareCall(storeProc);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cs.setString(1, qc.getTotalTaxNo());
cs.setString(2, StringUtils.isNotEmpty(qc.getOperator()) ? qc.getOperator() : null);
cs.setString(3, StringUtils.isNotEmpty(qc.getDpCode()) ? qc.getDpCode() : null);
cs.setString(4, qc.getIfTaxation() != null ? String.valueOf(qc.getIfTaxation()) : null);
cs.setString(5, qc.getInvalidFlag() != null ? String.valueOf(qc.getInvalidFlag()) : null);
cs.setString(6, StringUtils.isNotEmpty(qc.getPayCompany()) ? qc.getPayCompany() : null);
cs.setString(7, StringUtils.isNotEmpty(qc.getTaxBillType()) ? qc.getTaxBillType() : null);
cs.setString(8, StringUtils.isNotEmpty(qc.getCbecbillNo()) ? qc.getCbecbillNo() : null);
cs.setString(9, StringUtils.isNotEmpty(qc.getTaxNo()) ? qc.getTaxNo() : null);
cs.setString(10, StringUtils.isNotEmpty(qc.getBillNo()) ? qc.getBillNo() : null);
cs.setString(11, qc.getIfPrint() != null ? String.valueOf(qc.getIfPrint()) : null);
cs.setString(12, qc.getTotalTaxFrom() != null ? String.valueOf(qc.getTotalTaxFrom()) : null);
cs.setString(13, qc.getTotalTaxTo() != null ? String.valueOf(qc.getTotalTaxTo()) : null);
cs.setString(14, qc.getDeclareDateFrom() != null ? sdf.format(qc.getDeclareDateFrom()) : null);
cs.setString(15, qc.getDeclareDateTo() != null ? sdf.format(qc.getDeclareDateTo()) : null);
cs.registerOutParameter(16, OracleTypes.VARCHAR);
return cs;
}
}, new CallableStatementCallback<String>() {
@Override
public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
cs.execute();
return cs.getString(16);
}
});
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.