Oracle Sample Code Send SMS
Code for creating package body and procedure:
set define off;
CREATE OR REPLACE PACKAGE sms_api IS
FUNCTION send_sms(mobiles IN VARCHAR2,
message IN VARCHAR2,
sender IN VARCHAR2,
route IN PLS_INTEGER,
country IN PLS_INTEGER,
flash IN PLS_INTEGER,
unicode IN PLS_INTEGER,
schtime IN VARCHAR2,
campaign IN VARCHAR2,
response IN VARCHAR2 DEFAULT 'text',
authkey IN VARCHAR2 DEFAULT 'Your auth key')
RETURN VARCHAR2;
END sms_api;
/
CREATE OR REPLACE PACKAGE BODY sms_api IS
FUNCTION get_clobFromUrl(p_url VARCHAR2) RETURN CLOB IS
req utl_http.req;
resp utl_http.resp;
val VARCHAR2(32767);
l_result CLOB;
BEGIN
req := utl_http.begin_request(p_url);
resp := utl_http.get_response(req);
LOOP
utl_http.read_line(resp, val, TRUE);
l_result := l_result || val;
END LOOP;
utl_http.end_response(resp);
RETURN l_result;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
RETURN l_result;
WHEN OTHERS THEN
utl_http.end_response(resp);
RAISE;
END;
FUNCTION send_sms(mobiles IN VARCHAR2,
message IN VARCHAR2,
sender IN VARCHAR2,
route IN PLS_INTEGER,
country IN PLS_INTEGER,
flash IN PLS_INTEGER,
unicode IN PLS_INTEGER,
schtime IN VARCHAR2,
campaign IN VARCHAR2,
response IN VARCHAR2 DEFAULT 'text',
authkey IN VARCHAR2 DEFAULT 'Your auth key')
RETURN VARCHAR2 IS
l_url VARCHAR2(32000) := 'https://control.msg91.com/api/sendhttp.php';
l_result VARCHAR2(32000);
BEGIN
l_url := l_url || '?authkey=' || authkey;
l_url := l_url || '&mobiles=' || mobiles;
l_url := l_url || '&message=' || message;
l_url := l_url || '&sender=' || sender;
l_url := l_url || '&route=' || route;
l_url := l_url || '&country=' || country;
l_url := l_url || '&flash=' || flash;
l_url := l_url || '&unicode=' || unicode;
IF schtime IS NOT NULL THEN
l_url := l_url || '&schtime=' || schtime;
END IF;
l_url := l_url || '&response=' || response;
l_url := l_url || '&campaign=' || campaign;
l_url := utl_url.escape(l_url);
l_result := get_clobFromUrl(l_url);
RETURN l_result;
END;
END sms_api;
/
Run:
SELECT sms_api.send_sms('mobiles','message','senderId',route,country,flash,unicode,schtime,'campaign','response','Your auth key') FROM dual;
Example :
SELECT sms_api.send_sms('5656565656,8767876786','this is test msg','tester',4,91,0,0,NULL,'test','text','Your auth key') FROM dual;
Parameter name | Data type | Description |
---|---|---|
mobiles * | integer | Multiple numbers should be separated by comma (,) Ex : '5656565656,8767876786' |
message * | varchar | Message content to send |
senderId * | varchar | Receiver will see this as sender's ID. |
route * | varchar | If your operator supports multiple routes then give one route name. Eg: route=1 for promotional, route=4 for transactional SMS. |
country | numeric | 0 for international,1 for USA, 91 for India. |
flash | integer (0/1) | flash=1 (for flash SMS) |
unicode | integer (0/1) | unicode=1 (for unicode SMS) |
schtime | date and time | When you want to schedule the SMS to be sent. Time format will be Y-m-d h:i:s |
campaign | varchar | Campaign name you wish to create. |
response | varchar | By default you will get response in string format but you want to receive in other format (json,xml) then set this parameter. for example: &response=json or &response=xml |
authkey * | alphanumeric | Login authentication key (this key is unique for every user) |