I'm following a tutorial from Oracle, and in the last step I'm trying to execute a SQL script where I get the errors from DECLARE and end-of-file. Any idea where I went wrong? The following is the script:
create or replace
PROCEDURE ENQUEUE_TEXT(
payload IN VARCHAR2 )
AS
enqueue_options DBMS_AQ.enqueue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW (16);
user_prop_array SYS.aq$_jms_userproparray;
AGENT SYS.aq$_agent;
header SYS.aq$_jms_header;
MESSAGE SYS.aq$_jms_message;
BEGIN
AGENT := SYS.aq$_agent ('', NULL, 0);
AGENT.protocol := 0;
user_prop_array := SYS.aq$_jms_userproparray ();
header := SYS.aq$_jms_header (AGENT, '', 'aq1', '', '', '', user_prop_array);
MESSAGE := SYS.aq$_jms_message.construct (0);
MESSAGE.set_text (payload);
MESSAGE.set_userid ('Userid_if_reqd');
MESSAGE.set_string_property ('JMS_OracleDeliveryMode', 2);
--(header, length(message_text), message_text, null);
DBMS_AQ.enqueue (queue_name => 'userQueue', enqueue_options => enqueue_options,
message_properties => message_properties, payload => MESSAGE, msgid => message_handle );
COMMIT;
END ENQUEUE_TEXT;
DECLARE
PAYLOAD varchar2(200);
BEGIN
PAYLOAD := 'Hello from AQ !';
ENQUEUE_TEXT(PAYLOAD => PAYLOAD);
END;
You have to put a / after the proc creation.
....
message_properties => message_properties, payload => MESSAGE, msgid => message_handle );
COMMIT;
END ENQUEUE_TEXT;
/
--COMMIT;
--/
DECLARE
PAYLOAD varchar2(200);
BEGIN
PAYLOAD := 'Hello from AQ !';
ENQUEUE_TEXT(PAYLOAD => PAYLOAD);
END;
And maybe a COMMIT; is missing.
Related
I would like to ask how can I loop the value of a return in 'url_next' variable into url varible so that I can use the function until the all users imported from the api call .
so the value returned from 'url_next'
into
url := 'https://dev-9466225.okta.com/api/v1/users';
l_http_request := utl_http.begin_request(apex_string.format( url , 'GET', 'HTTP/1.1'));
create or replace function OKTA_API_X
(url IN VARCHAR2)
return varchar2
IS
v_username VARCHAR2(50);
v_email VARCHAR2(50);
v_firstname VARCHAR2(50);
v_last_name VARCHAR2(50);
l_http_request utl_http.req;
l_http_response utl_http.resp;
l_text VARCHAR2(32767);
resp CLOB := '';
l_json_obj json_object_t;
l_json_in json_array_t;
name VARCHAR2(2560);
value VARCHAR2(2024);
url_next VARCHAR2(100);
url VARCHAR2(50);
BEGIN
url := 'https://dev-9466225.okta.com/api/v1/users';
l_http_request := utl_http.begin_request(apex_string.format( url , 'GET', 'HTTP/1.1'));
utl_http.set_wallet('file:c:/okta_wallet_base/', NULL);
utl_http.set_header(l_http_request, 'content-type', 'application/json');
utl_http.set_header(l_http_request, 'authorization', 'SSWS 00mz6_ost-rfegVu5K5I6dEs33JLIFSmcBO8VxzI');
utl_http.set_header(l_http_request, 'Accept', 'application/json');
l_http_response := utl_http.get_response(l_http_request);
-- dbms_output.put_line('HTTP response status code =>' || l_http_response.status_code);
-- dbms_output.put_line('HTTP response reason phrase => ' || l_http_response.reason_phrase);
BEGIN
LOOP
utl_http.read_text(l_http_response, l_text,32766)
resp := resp || l_text;
END LOOP;
END;
--- JASON PARSING
l_json_in := json_array_t(resp);
FOR indx IN 0..l_json_in.get_size - 1 LOOP
l_json_obj := TREAT(l_json_in.get(indx) AS json_object_t);
--GET JSON OBJECT AND STRINGS FROM RESPONSE
v_firstname := l_json_obj.get_object('profile').get_string('firstName');
v_last_name := l_json_obj.get_object('profile').get_string('lastName');
v_email := l_json_obj.get_object('profile').get_string('email');
v_username := l_json_obj.get_object('profile').get_string('login');
-------------------------------
dbms_output.put_line(v_firstname);
--dbms_output.put_line(v_EMAIL);
END LOOP;
---------------------------------------------------------------------------- FOR i IN 1..
utl_http.get_header_count(l_http_response) LOOP
utl_http.get_header(l_http_response, i, name, value);
IF
name = 'link'
AND value LIKE '%rel="next"'
THEN
url_next := ( trim(TRAILING '>' FROM regexp_substr(value, 'http[^>]+>')) );
END IF;
END LOOP;
BEGIN
WHILE url_next IS NOT NULL LOOP
IF url_next <> url THEN
url := url_next;
ELSE
NULL;
END IF;
END LOOP;
END;
EXCEPTION
WHEN OTHERS THEN
BEGIN
utl_http.end_response(l_http_response);
dbms_output.put_line('ERROR →' || sqlerrm);
END;
END;
Using Delphi 2010
Can anyone tell me what I am doing wrong here with my code. The comments show the errors that I receive with the particular methods that I tried to pass parameters to my ADOQuery
procedure CreateAdminLogin(const APasswd: string);
var
qry: TADOQuery;
//P1, P2: TParameter;
begin
qry := TADOQuery.Create(nil);
try
qry.Connection := frmDataModule.conMain;
qry.SQL.Text := 'INSERT INTO Users (User_Id, Password) VALUES (:u, :p)';
//Syntax error in INTO statement
qry.Parameters.ParamByName('u').Value:= 'Admin';
qry.Parameters.ParamByName('p').Value:= GetMd5(APasswd);
//invalid variant operation
{qry.Parameters.ParamByName('u').Value.AsString:= 'Admin';
qry.Parameters.ParamByName('p').Value.AsString:= GetMd5(APasswd);}
//invalid variant operation
{P1:= qry.Parameters.ParamByName('u');
P1.Value.asString:= 'Admin';
P2:= qry.Parameters.ParamByName('p');
P2.Value.asString:= GetMd5(APasswd);}
qry.Prepared := True;
qry.ExecSQL;
finally
qry.Free;
end;
end;
NOTE: GetMD5 is declared as follows
function GetMd5(const Value: String): string;
var
hash: MessageDigest_5.IMD5;
fingerprint: string;
begin
hash := MessageDigest_5.GetMd5();
hash.Update(Value);
fingerprint := hash.AsString();
Result := fingerprint;
end;
Thankx
This works fine for me, using the DBDemos.MDB file that shipped with Delphi (C:\Users\Public\Documents\RAD Studio\9.0\Samples\Data\dbdemos.mdb by the default installation)
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('INSERT INTO Country (Name, Capital, Continent, Area, Population)');
ADOQuery1.SQL.Add('VALUES (:Name, :Capital, :Continent, :Area, :Population)');
ADOQuery1.Parameters.ParamByName('Name').Value := 'SomePlace';
ADOQuery1.Parameters.ParamByName('Capital').Value := 'Pitsville';
ADOQuery1.Parameters.ParamByName('Continent').Value := 'Floating';
ADOQuery1.Parameters.ParamByName('Area').Value := 1234;
ADOQuery1.Parameters.ParamByName('Population').Value := 56;
ADOQuery1.ExecSQL;
ADOQuery1.Close;
// Open it to read the data back
ADOQuery1.SQL.Text := 'SELECT * FROM Country WHERE Name = :Name';
ADOQuery1.Parameters.ParamByName('Name').Value := 'SomePlace';
ADOQuery1.Open;
ShowMessage(ADOQuery1.FieldByName('Name').AsString);
For using like extra thing to know:
Datasource SQL like this
select * from Table where Phone like :param
DataModule.findQuery.Parameters.ParamByName('param').Value:= '%%'+yourEdit.Text + '%%';
You should create parameters first:
procedure CreateAdminLogin(const APasswd: string);
var
qry: TADOQuery;
begin
qry := TADOQuery.Create(nil);
try
// this part is missed in your code
with qry.Parameters.AddParameter do
begin
Name := 'u';
DataType := ftString;
end;
with qry.Parameters.AddParameter do
begin
Name := 'p';
DataType := ftString;
end;
qry.Connection := frmDataModule.conMain;
qry.SQL.Text := 'INSERT INTO Users (User_Id, Password) VALUES (:u, :p)';
// Now it will be ok!
qry.Parameters.ParamByName('u').Value:= 'Admin';
qry.Parameters.ParamByName('p').Value:= GetMd5(APasswd);
qry.Prepared := True;
qry.ExecSQL;
finally
qry.Free;
end;
end;
Im trying to insert a row into a firebird database (embedded), but geting an exception when calling:
datamodule1.IBQuery1.prepare
Project xyz.exe raised exception class EIBInterBaseError with message
'Dynamic SQL Error SQL error code = -206 Column unknown INDEX_ At
line, column 25'.
with datamodule1.IBQuery1 do
begin
close;
With SQL do
begin
clear;
Add( 'INSERT INTO MST_EVENTS (eventindex, state_, event_, param_, date_, time_, devID_, gateway_)' );
Add( 'VALUES (:eventindex, :state_, :event_, :param_, :date_, :time_, :devid_, :gateway_') );
end;
//
GeneratorField.Field := 'Nr_';
GeneratorField.Generator := 'GEN_MST_EVENTS_ID';
//
Params[0].AsInteger := FMst.EventRecordIndex;
Params[1].AsSmallInt := FMst.EventRecordState;
Params[2].AsString := eventToStr(FMst.EventRecordEvent);
Params[3].AsSmallInt := 0;
Params[4].AsDate := FMst.EventRecordDate;
Params[5].AsTime := FMst.EventRecordTime;
Params[6].AsLongWord := FMst.EventRecordDevID;
Params[7].AsString := FMst.EventRecordIP;
//
if ( prepared = false ) then
prepare; //Throws an exception here (SOLVED)
execSQL; //Now getting exception here
end;
I have the following components tied together:
IBDatabase
IBTransaction
DataSource
IBQuery
Above problem solved - Edit >>
Ok, i have changed
Add( 'INSERT INTO MST_EVENTS (eventindex, state_, event_, param_, date_, time_, devID_, gateway_)' );
to
Add( 'INSERT INTO MST_EVENTS ("eventindex", "state_", "event_", "param_", "date_", "time_", "devID_", "gateway_")' );
... (so im using quotation marks) and now it finds the fields, but get another exception at line:
IBQuery1.execSQL:
Exception class EIBClientError with message 'Unsupported feature'
My fields are:
Nr_ : INTEGER
eventindex : INTEGER
state_ : SMALLINT
event_ : VARCHAR(50)
param_ : SMALLINT
date_ : DATE
time_ : TIME
devID_ : BIGINT
gateway_ : VARCHAR(50)
Firebird version is 2.5 embedded 32bit
I took out all the string and date/time parameters, yet i get the exception.
Using IBExpert and the same client/server .dll i can insert the row flawlessly (using all the values).
The solution was changing line
Params[6].AsLongWord := FMst.EventRecordDevID;
to
Params[6].AsLargeInt := FMst.EventRecordDevID;
But please how to auto-increment the field 'Nr_'?
with datamodule1.IBQuery1 do
begin
close;
With SQL do
begin
clear;
Add( 'INSERT INTO MST_EVENTS (eventindex, state_, event_, param_, date_, time_, devID_, gateway_)' );
Add( 'VALUES (:eventindex, :state_, :event_, :param_, :date_, :time_, :devid_, :gateway_') );
end;
//
GeneratorField.Field := 'Nr_';
GeneratorField.Generator := 'GEN_MST_EVENTS_ID';
//
Params[0].AsInteger := FMst.EventRecordIndex;
Params[1].AsSmallInt := FMst.EventRecordState;
Params[2].AsString := eventToStr(FMst.EventRecordEvent);
Params[3].AsSmallInt := 0;
Params[4].AsDate := FMst.EventRecordDate;
Params[5].AsTime := FMst.EventRecordTime;
Params[6].AsLargeInt := FMst.EventRecordDevID;
Params[7].AsString := FMst.EventRecordIP;
//
if ( prepared = false ) then
prepare; //Throws an exception here (SOLVED)
execSQL; //Now getting exception here
end;
I made the generator in flamerobin.
But getting exception (at calling 'execSQL'):
EDIT >>
I set up a generator and a BEFORE INSERT trigger in IBExpert:
And now its ok.
I am trying to send an XML as a URL parameter from PL/SQL.
But when I try to send it the error "ORA:06052" occurs. Below is the PL/SQL code
CREATE OR REPLACE FUNCTION EMASDB.ESIGN(TY IN VARCHAR2,DATA1 IN CLOB,DATA2 IN CLOB) RETURN clob
IS
XML CLOB;
v_data_post CLOB;
resp utl_http.resp;
req utl_http.req;
v_txt CLOB;
BEGIN
IF TY='REGISTER' THEN
XML:='<register><uniqueid>'||DATA2||'</uniqueid><DATA1>'||DATA1||'</DATA1><userEnable>true</userEnable><originalContent>'||DATA2||'</originalContent></register>';
ELSIF TY='AUTHENTICATE' THEN
XML :='<AuthenticateDet><uniqueId>'||DATA2||'</uniqueId><DATA1>'||DATA1||'</DATA1><originalContent>'||DATA2||'</originalContent><referenceNo></referenceNo></AuthenticateDet>';
ELSE
XML :='<verifyDet><dataType>pkcs7</dataType><DATA1>'||DATA1||'</DATA1><originalContent>'||DATA2||'</originalContent><responseFormat>plain</responseFormat></verifyDet>';
DBMS_OUTPUT.PUT_LINE('A');
END IF;
req := UTL_HTTP.begin_request ('url','POST','HTTP/1.1');
utl_http.set_header(req, 'Content-Type', 'application/x-www-form-urlencoded');
utl_http.set_header(req, 'Content-Length', length(XML));
v_data_post :='xml='||XML;
/*utl_http.write_text(req, v_data_post);
resp := UTL_HTTP.get_response(req);
utl_http.read_text(resp,v_txt);
utl_http.end_response(resp);
RETURN v_txt;*/
RETURN 'done';
END;
/
When you need write (and read) more than 32k in utl_http, it done a bit differently.
For example:
l_data := 'fill with some sample piece of text';
http_req := utl_http.begin_request(url => 'http://example.com', method => 'POST');
utl_http.set_header (http_req, 'Content-Length', length(l_data));
utl_http.set_header (http_req, 'Content-Type', 'text/xml;charset=UTF-8');
utl_http.set_header (http_req, 'Transfer-Encoding', 'chunked');
loop
l_chunkData := null;
l_chunkData := substr(l_data, l_chunkStart, l_chunkLength);
utl_http.write_text(http_req, l_chunkData);
if (length(l_chunkData) < l_chunkLength) then exit; end if;
l_chunkStart := l_chunkStart + l_chunkLength;
end loop;
See: http://www.kurzhals.info/2012/03/using-chunked-transfer-with-plsql-utl_http-write_text.html
And for a clob example see: http://blog.optiosys.com/?p=246
You should NEVER send Transfer-Encoding: chunked , alongside Content-Length , its either the one of the other. –
Jelman
Jan 21, 2020 at 13:54
helped me!
For all of you who are struggling with similar issues, this solution also resolved the following Oracle errors:
Error: ORA-29273: fallo de la solicitud HTTP
ORA-12547: TNS:contacto perdido
for those who still need it, you can try this way :
begin
declare
v_req utl_http.req;
v_res utl_http.resp;
vn_tam_clob PLS_INTEGER;
vn_tam_buffer PLS_INTEGER;
vn_pos_inicial PLS_INTEGER;
v_buffer varchar2(32000);
v_body clob := va_content_clob; -- Your JSON (XML)
begin
-- Set connection.
vn_tam_clob := DBMS_LOB.GETLENGTH(va_content_clob);
v_req := utl_http.begin_request('http://your.api/operation', 'POST');
utl_http.set_authentication(v_req, 'your_username','your_password');
utl_http.set_header(v_req, 'content-type', 'application/json');
utl_http.set_header(v_req, 'Content-Length', vn_tam_clob);
-- Set error to exception
utl_http.set_response_error_check(true);
-- Invoke REST API.
vn_pos_inicial := 1;
vn_tam_buffer := 32000;
while vn_pos_inicial <= vn_tam_clob -- least( vn_tam_clob, vn_tam_buffer ) )
loop
utl_http.write_text( v_req, dbms_lob.substr( v_body, vn_tam_buffer, vn_pos_inicial ) );
vn_pos_inicial := vn_pos_inicial + vn_tam_buffer ;
end loop;
-- Get response para retorno OK ou analise do problema.
v_res := utl_http.get_response(v_req);
-- if you don't set : utl_http.set_response_error_check(true);
-- you can get the return structure
-- IF (v_res.status_code = 202) THEN
-- dbms_output.put_line('v_response is okay');
-- ELSE
-- dbms_output.put_line('v_resPONSE CODE IS '||v_res.status_code);
--
-- begin
-- loop
-- utl_http.read_line(v_res, v_buffer);
--
-- -- display or log in table v_buffer;
--
--
-- end loop;
-- utl_http.end_response(v_res);
-- exception
-- when utl_http.end_of_body then
-- utl_http.end_response(v_res);
-- end;
--
-- END IF;
END;
EXCEPTION
WHEN OTHERS THEN
utl_http.end_response(v_res);
RAISE;
END;
I am trying to execute the following query in PL/SQL developer:
DECLARE
P_FILENAME VARCHAR2(200):= 'file1.csv';
P_DIRECTORY VARCHAR2(200):= 'ORA_DIR';
P_IGNORE_HEADERLINES NUMBER := 1;
BEGIN
Load_file( P_FILENAME => P_FILENAME, P_DIRECTORY => P_DIRECTORY, P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES );
END
I get the error :
ORA-06550: line 9, column 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.
Where am I going wrong here.
you are missing a semi colon on the end statement:
DECLARE
P_FILENAME VARCHAR2(200):= 'file1.csv';
P_DIRECTORY VARCHAR2(200):= 'ORA_DIR';
P_IGNORE_HEADERLINES NUMBER := 1;
BEGIN
Load_file( P_FILENAME => P_FILENAME, P_DIRECTORY => P_DIRECTORY,
P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES );
END;
/