Pascal Max_Heapify - max-heap

I did these in pascal.
Proceure Max_Heapify(a:Table;i:longint);
var tmp,l,r,k:longint;
begin
l:=2*i;
r:=2*i+1;
if (heapsize>=l)and(a[i]<a[l]) then k:=l else k:=i;
if (heapsize>=r)and(a[i]<a[r]) then k:=r;
if k<>i then
begin
swap(a[i],a[k]);
Max_Heapify(a,k);
end;
end;
I wrote this procedure in pascal, but it seems not working and I can't figure out what's wrong can somebody help me ? Thanks

You misspelled PROCEDURE.
a:Table - Table is not a data type.

Related

Get Ref Cursor from dbms_sql.open_cursor

I have been asked to try to fix some existing PL/SQL code at work and I am new to PL/SQL. I am sorry if this is a stupid question.
Is there a way to take the cursor id returned by dbms_sql.open_cursor and get a REF CURSOR? Something like this:
procedure DoSomething (po_cursor out REF CURSOR) is
lv_cursorid integer;
begin
lv_cursorid := DBMS_SQL.open_cursor;
po_cursor := get_cursor_by_id(lv_cursorid);
end;
Per the docs, dbms_sql.to_refcursor(lv_cursorid) should do it

Calling multiple procedures in one procedure

I have three procedures that I need to call in specific order in one procedure. How can I do that?
Lets say that one procedure is called proc_log. Other three procedures that must be called in proc_log are: insert_header, insert_mapping, insert_item (strictly in that order).
Could someone give a code sample on how to do this?
Sure; one after another.
create or replace procedure proc_log is
begin
insert_header;
insert_mapping;
insert_time;
end;
/
You can do this as shown below:
CREATE OR REPLACE PROCEDURE proc_log
AS
BEGIN
BEGIN
insert_header ();
EXCEPTION
WHEN OTHERS THEN
raise_application_error( -20001,'In insert_header' );
END;
BEGIN
insert_mapping ();
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20002,'In insert_mapping');
END;
BEGIN
insert_item ();
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20003,'In insert_item');
END;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'In proc_log');
END;

PLSQL Procedure to return result set without a refcursor

So Im going trough an oracle database course and I have a homework where I have to create a procedure and "return" (I guess return) the resultset without using a refcursor, but all the examples I find make use of it.
So lets say I have this:
CREATE OR REPLACE PROCEDURE get_all_inventory() AS
BEGIN
SELECT * FROM Inventory;
END;
/
How do I make the procedure return the resultset without using refcursor?
is this even possible?
Thanks.
EDIT: If someone know a way of returning the result set in json that will be just awesome!
Aside from using JSON, you can also use collections as a return value. You have to create a package first for your procedure. Here's a sample code:
create OR REPLACE package get_all_inventory_package is
type arrayofrec is table of Inventory%rowtype index by pls_integer;
procedure get_all_inventory (o_return_variable OUT arrayofrec);
end;
/
create OR REPLACE package BODY get_all_inventory_package is
procedure get_all_inventory (o_return_variable OUT arrayofrec)is
return_variable arrayofrec;
begin
select * bulk collect into o_return_variable from Inventory;
end;
END;
/
declare
v_receiver get_all_inventory_package.arrayofrec;
begin
get_all_inventory_package.get_all_inventory(v_receiver);
for a in 1..v_receiver.count loop
dbms_output.put_line(v_receiver(a).Inventory_column);
end loop;
end;

PL/SQL numeric or value error when converting to number

I'm busy with a little PL/SQL program and i got stuck when i got the error "numeric or value error"
I'm trying to convert a varchar2 that consists of only numbers to a number using TO_NUMBER().
I'm relatively new to PL/SQL, so i'm thinking it's something really dumb :)
This is my code:
set serveroutput on
DECLARE
vRearranged varchar(50);
iNumber number(38);
BEGIN
vRearranged := 3214282912345698765432161100;
iNumber := To_Number(vRearranged, 50);
dbms_output.put_line(iNumber);
END;
could anyone help me?
The second argument of To_number() is the format picture, which should be a string.
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions211.htm#SQLRF06140
DECLARE
vRearranged varchar2(50);
iNumber number(38);
BEGIN
vRearranged := 3214282912345698765432161100;
iNumber := To_Number(vRearranged);
dbms_output.put_line(iNumber);
END;

What is the syntax to define an Oracle procedure within an another stored procedure?

After many Google and SO searches, I cannot find a definitive answer to this simple question:
How can I define a procedure inside of another procedure to use?
I know that there are nested blocks and nested procedures, but I haven't seen the exact syntax for what I want. i.e.
create or replace
PROCEDURE TOP_PROCEDURE
(...)
IS
-- nested procedure here?
BEGIN
NULL;
END;
create or replace
PROCEDURE TOP_PROCEDURE
(...)
IS
variable NUMBER;
PROCEDURE nested_procedure (...)
IS
BEGIN
NULL;
END;
PROCEDURE another_nested_procedure (...)
IS
BEGIN
NULL;
END;
BEGIN
NULL;
END;
Local procedures must be declared after anything else (e.g. variables).

Resources