DB

工作相关的代码整理

工具

发送邮件 cux_fnd_sendmail_pkg

多个附件
DECLARE
l_attachment_table cux_fnd_sendmail_pkg.t_attach_blob_table;
...
BEGIN
...
--添加到附件表
l_attachment_table(1).t_name := l_attach_file_name;
l_attachment_table(1).t_ddl := g_zipped_blob;
l_attachment_table(1).t_ext := 'zip';
l_attachment_table(1).t_content_type := 'multipart/alternative';
...
l_attachment_table(2).t_name := l_attach_file_name;
l_attachment_table(2).t_ddl := cux_fnd_xls_pkg.finish;
l_attachment_table(2).t_ext := 'xlsx';
l_attachment_table(2).t_content_type := 'multipart/alternative';
...
cux_fnd_sendmail_pkg.send_mail_attach_blob_t_c(p_from_email => 'erp@oracle.com',
p_receiver_address => l_receiver_address,
p_receive_name => l_receiver_address,
p_email_subject => l_email_subject,
p_email_body => l_email_body,
p_cc_name => l_cc_address,
p_attachment_table => l_attachment_table);
END;
图文
cux_fnd_sendmail_pkg.send_mail_with_image(p_from_email => v_sender_email,
p_receiver_address => c_per.email_address,
p_receive_name => c_per.last_name,
p_email_subject => v_mail_title,
p_email_body => v_mail_body,
p_cc_name => v_cc_email,
p_attachment_table => v_attach_blob_table);

markdown cux_fnd_markdown_pkg

cux_pay_tax_plan_pkg.report

汉字转拼音 cux_fnd_pinyin_pkg

SELECT cux_fnd_pinyin_pkg.gethzfullpy('程宣峰') FROM dual

读取excel的内容 cux_fnd_read_xlsx_pkg

/* 不建临时表使用excel上传文件. */
cux_per_upload_email_pkg

创建excel cux_fnd_xls_pkg

// 创建excel报表
cux_hcm_abs_deduct_pkg.report

导入文本文件csv

配置导入的form
  1. 配置导入的功能, 表单为:CUX:上传本地数据. 参数为: APPL=”CUX” PROGRAME=”CUXPERUPLOADEMAIL”
  2. 读取文本的API: cux_import_interface_api
DECLARE
des cux_import_interface_api.descriptor_t;
cells cux_import_interface_api.row_t;
BEGIN
des := cux_import_interface_api.open(p_file_id, --fnd_lobs
p_file_cs, --字符集
p_delimiter, --分隔符
p_processing_id,
11); -- 11列
IF (cux_import_interface_api.is_empty(des) = TRUE) THEN
raise_application_error(-20001, 'File is empty');
END IF;
-- 略过标题
cux_import_interface_api.next_line(des);
IF (cux_import_interface_api.is_end_of_file(des) = TRUE) THEN
raise_application_error(-20001, 'File is empty');
END IF;
cux_import_interface_api.next_line(des);
WHILE (cux_import_interface_api.is_end_of_file(des) = FALSE) LOOP
-- 取当前行的所有列
cux_import_interface_api.get_cell_set(des, cells);
dbms_output.put_line(cells(1)); -- 打印第一列
dbms_output.put_line(cells(2)); -- 打印第二列
-- 读取下一行
cux_import_interface_api.next_line(des);
END LOOP;
END;

压缩文件

DECLARE
g_zipped_blob BLOB;
BEGIN
FOR rec IN csr LOOP
cux_fnd_xls_pkg.add1file(g_zipped_blob,
rec.file_name,
rec.attachment_content);
cux_fnd_xls_pkg.finish_zip(g_zipped_blob, '');
END LOOP;
END;

BPM 流程

// 启动流程
cux_bpm_utility_pkg.create_process
// 启动空流程
cux_bpm_utility_pkg.create_notify
// 撤回
cux_bpm_utility_pkg.abort_process
// 审批通过
cux_bpm_utility_pkg.approve_process
// 拒绝
cux_bpm_utility_pkg.reject_process
// 当前审批人
cux_bpm_common_pkg.get_uuap_username
// 当前审批节点
cux_bpm_utility_pkg.get_current_task_val

MQ 数据同步

hcm_common_pkg.call_plsql_main_json(p_plsql_api => 'cux_hcm_bo_pkg.get_pay_lines',
p_msg_json => l_msg,
p_http_apex => 'APEX',
o_errcode => o_errcode,
o_errmsg => o_errmsg);

百度hi通知接口

待整理

调用波塞冬的服务

bp_databus_api_pkg.start_di_flow(p_di_request_id => -1,
p_di_channel_code => 'PN_DC_UNFIN_PERMISSION',
p_di_transformation_code => 'APPLAT_UNFIN_PERMISSION',
p_di_job_codes => 'UNFIN_PERMISSION_USERINFO,UNFIN_PERMISSION_DUTY,UNFIN_PERMISSION_USERDUTY',
p_di_business_batch_num => 'p_di_business_batch_num',
p_di_operator => 'p_di_operator',
p_di_batch_num => '1,1,1',
p_di_batch_sizes => l_di_batch_size,
o_ret_code => l_error_code,
o_ret_msg => l_error_msg);

FYI小熊通知

主库小熊通知表: cux_ext_notifications_pub.create_fyi_msg
分库小熊通知表: cux_ext_polar_fyi_pub.create_fyi_msg

MD5加密

SELECT utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string => 'chengxuanfeng')) FROM dual;

对url进行编码和解码

BEGIN
dbms_output.put_line(utl_url.escape('http://www.baidu.com/参数/=+/',TRUE,'UTF8'));
dbms_output.put_line(utl_url.escape('http://www.baidu.com/参数/=+/',false,'UTF8'));
dbms_output.put_line( utl_url.unescape('http%3A%2F%2Fwww.baidu.com%2F%E5%8F%82%E6%95%B0%2F%3D%2B%2F','UTF8'));
END;

调用web请求

FUNCTION get_audio(p_text IN VARCHAR2) RETURN BLOB IS
l_req_blob BLOB;
l_res_blob BLOB;
l_url VARCHAR2(32767) := get_tts_url();
l_cuid VARCHAR2(32767);
l_req utl_http.req;
l_res utl_http.resp;
BEGIN
SELECT instance || '-' || '-' || userenv('sessionid')
INTO l_cuid
FROM v$thread;
l_url := REPLACE(l_url, '#text#', p_text || chr(38));
l_url := REPLACE(l_url, '#token#', get_access_token);
l_url := REPLACE(l_url, '#cuid#', l_cuid);
log(l_url);
l_req := utl_http.begin_request(l_url, 'GET');
dbms_lob.createtemporary(lob_loc => l_req_blob, cache => FALSE);
utl_http.write_raw(l_req, l_req_blob);
l_res := utl_http.get_response(l_req);
dbms_output.put_line('Response> status_code: "' || l_res.status_code || '"');
dbms_output.put_line('Response> reason_phrase: "' ||
l_res.reason_phrase || '"');
dbms_output.put_line('Response> http_version: "' || l_res.http_version || '"');
DECLARE
l_raw_data RAW(512);
--chunk_size CONSTANT INTEGER := 512;
BEGIN
dbms_lob.createtemporary(l_res_blob, FALSE);
LOOP
BEGIN
utl_http.read_raw(l_res, l_raw_data);
IF l_raw_data IS NOT NULL THEN
dbms_lob.writeappend(l_res_blob,
utl_raw.length(l_raw_data),
l_raw_data);
END IF;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(l_res);
EXIT;
END;
END LOOP;
END;
IF l_req.private_hndl IS NOT NULL THEN
utl_http.end_request(l_req);
END IF;
IF l_res.private_hndl IS NOT NULL THEN
utl_http.end_response(l_res);
END IF;
--dbms_lob.freetemporary(l_res_blob);
RETURN l_res_blob;
END;
--发送hi, 默认文本.
PROCEDURE hi(p_message_type IN VARCHAR2 := 'text',
p_hi_number IN VARCHAR2,
p_content IN VARCHAR2) IS
l_response_text VARCHAR2(2000);
l_url VARCHAR2(32767) := get_hi_service();
l_payload CLOB := get_hi_payload();
BEGIN
l_payload := REPLACE(l_payload, '#MESSAGE_TYPE#', p_message_type);
l_payload := REPLACE(l_payload, '#HI_NUMBER#', p_hi_number);
l_payload := REPLACE(l_payload, '#CONTENT#', p_content);
--
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).value := 'application/x-www-form-urlencoded';
l_response_text := apex_web_service.make_rest_request(p_url => l_url,
p_http_method => 'POST',
p_body => l_payload);
log(l_response_text);
END;
分享到