I have this function :
CREATE OR REPLACE FUNCTION checkLiveSoccerOdd (p_FIXID VARCHAR2,
p_TYPE VARCHAR2,
p_RES VARCHAR2)
RETURN NUMBER
IS
odd NUMBER;
BEGIN
SELECT O.Odd
INTO odd
FROM LIVE M, ODDS O
WHERE M.FIXID = O.FIXID(+)
AND M.FIXID = p_FIXID
AND O.TYPE = p_TYPE
AND O.RES = p_RES;
RETURN odd;
END;
Now i need to get more columns in query, for example:
Select M.*, O.*
I tried with cursor but I don't get results.
Can anyone help me with this?
Try this:
CREATE OR REPLACE FUNCTION checkLiveSoccerOdd (p_FIXID VARCHAR2,
p_TYPE VARCHAR2,
p_RES VARCHAR2)
RETURN SYS_REFCURSOR
IS
COL SYS_REFCURSOR;
BEGIN
OPEN COL FOR
SELECT M.*,O.*
FROM LIVE M, ODDS O
WHERE M.FIXID = O.FIXID(+)
AND M.FIXID = p_FIXID
AND O.TYPE = p_TYPE
AND O.RES = p_RES;
RETURN COL;
END;
Related
I have a pipe line function like below. if I want to delete some rows from the fetched output, how should I do that.
I tried myObjectFormat.delete after the END LOOP in below code.
but it didn't work.
Please let me know what I am doing wrong;
CREATE OR REPLACE TYPE myObjectFormat AS OBJECT
(
A INT,
B DATE,
C VARCHAR2 (25)
)
/
CREATE OR REPLACE TYPE myTableType AS TABLE OF myObjectFormat
/
CREATE OR REPLACE FUNCTION SB360.test_func (P_ID VARCHAR2)
RETURN myTableType
PIPELINED
IS
v_obj myObjectFormat := myObjectFormat (NULL, NULL, NULL);
v_cur SYS_REFCURSOR;
QUERY_STMT VARCHAR2 (32767);
A INT;
B DATE;
C VARCHAR2 (25);
BEGIN
QUERY_STMT := 'select a,b,c from test where id=' || P_ID;
OPEN V_CUR FOR QUERY_STMT;
LOOP
FETCH V_CUR INTO a, b, c;
EXIT WHEN V_CUR%NOTFOUND;
v_obj.A := A;
v_obj.b := b;
v_obj.c := c;
PIPE ROW (v_obj);
END LOOP;
RETURN;
END;
/
I have this procedure into a package, and I need to return the count of a table, but I don't know how do this. I have this and it doesn't work.
PROCEDURE OBTENER_TOTALCAMPAĆA(TOTAL OUT NUMBER)
IS
row_count number;
BEGIN
SELECT COUNT(*) AS TOTAL_CARTERA INTO row_count FROM CLIENTE
RETURNING row_count INTO TOTAL;
END;
Try this. You don't need to say returning in this case. Returning is typically used in inserts that you need to get the id from after the row is inserted. In your case, just fill the output param with the select ... INTO from ....
PROCEDURE OBTENER_TOTALCAMPAĆA(TOTAL OUT NUMBER)
IS
BEGIN
SELECT COUNT(*) AS TOTAL_CARTERA INTO TOTAL FROM CLIENTE;
END;
Buena suerte
try this. it works for me. create oracle package
create or replace PACKAGE LEVEL_CRUD AS
PROCEDURE INSERT_LEVEL_DATA (
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
P_LEVEL_NAME IN APP_LEVEL_MASTER.LEVEL_NAME%TYPE,
P_CREATED_BY IN APP_LEVEL_MASTER.CREATED_BY%TYPE,
P_CREATE_DATE IN VARCHAR2,
P_UPDATE_DATE IN VARCHAR2
);
PROCEDURE FETCH_LEVEL_DATA (
LEVEL_C OUT SYS_REFCURSOR
);
PROCEDURE UPDATE_LEVEL_DATA (
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
P_LEVEL_NAME IN APP_LEVEL_MASTER.LEVEL_NAME%TYPE,
P_CREATED_BY IN APP_LEVEL_MASTER.CREATED_BY%TYPE,
P_CREATE_DATE IN APP_LEVEL_MASTER.CREATE_DATE%TYPE,
P_UPDATE_DATE IN varchar2,
P_UPDATE_COUNT OUT NUMBER
);
PROCEDURE GET_LEVEL_RECORD_ID_WISE(
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
LEVEL_C OUT SYS_REFCURSOR
);
PROCEDURE DELETE_LEVEL_DATA(
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
DELETE_C OUT NUMBER
);
END LEVEL_CRUD;
create package body where actual procedure is available and sql query will return count and data
create or replace PACKAGE BODY LEVEL_CRUD AS
PROCEDURE INSERT_LEVEL_DATA (
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
P_LEVEL_NAME IN APP_LEVEL_MASTER.LEVEL_NAME%TYPE,
P_CREATED_BY IN APP_LEVEL_MASTER.CREATED_BY%TYPE,
P_CREATE_DATE IN VARCHAR2,
P_UPDATE_DATE IN VARCHAR2
) AS
BEGIN
INSERT INTO APP_LEVEL_MASTER
( LEVEL_ID,LEVEL_NAME,CREATED_BY,CREATE_DATE,UPDATE_DATE,STATUS)
VALUES ( ESC_LEVEL_ID.NEXTVAL,P_LEVEL_NAME,P_CREATED_BY,SYSDATE,SYSDATE,1);
END INSERT_LEVEL_DATA;
PROCEDURE FETCH_LEVEL_DATA (
LEVEL_C OUT SYS_REFCURSOR
) AS
BEGIN
open LEVEL_C FOR
SELECT * FROM APP_LEVEL_MASTER where STATUS = 1;
END FETCH_LEVEL_DATA;
PROCEDURE UPDATE_LEVEL_DATA (
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
P_LEVEL_NAME IN APP_LEVEL_MASTER.LEVEL_NAME%TYPE,
P_CREATED_BY IN APP_LEVEL_MASTER.CREATED_BY%TYPE,
P_CREATE_DATE IN APP_LEVEL_MASTER.CREATE_DATE%TYPE,
P_UPDATE_DATE IN varchar2,
P_UPDATE_COUNT OUT NUMBER
) AS
BEGIN
UPDATE APP_LEVEL_MASTER AUM
SET
AUM.LEVEL_NAME = P_LEVEL_NAME,
AUM.CREATED_BY = P_CREATED_BY,
AUM.CREATE_DATE= TO_DATE(P_CREATE_DATE,'DD/MM/YYYY'),
AUM.UPDATE_DATE=TO_DATE(sysdate)
WHERE AUM.LEVEL_ID = P_LEVEL_ID;
P_UPDATE_COUNT:=SQL%ROWCOUNT;
END UPDATE_LEVEL_DATA;
PROCEDURE GET_LEVEL_RECORD_ID_WISE(
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
LEVEL_C OUT SYS_REFCURSOR
)AS
BEGIN
OPEN LEVEL_C FOR
SELECT * FROM APP_LEVEL_MASTER WHERE LEVEL_ID=P_LEVEL_ID;
END GET_LEVEL_RECORD_ID_WISE;
PROCEDURE DELETE_LEVEL_DATA(
P_LEVEL_ID IN APP_LEVEL_MASTER.LEVEL_ID%TYPE,
DELETE_C OUT NUMBER
)AS
BEGIN
UPDATE APP_LEVEL_MASTER SET STATUS='0' WHERE LEVEL_ID=P_LEVEL_ID;
DELETE_C:=SQL%ROWcOUNT;
END DELETE_LEVEL_DATA;
END LEVEL_CRUD;
I have an Oracle function which accepts few IN parameters of number and varchar2 datatype and also it return a number datatype. Within the function, I'm selecting from a table with the IN parameters are applied in the 'WHERE' clause. By doing this, this filters is not applied to the select query instead it is skipping that condition. I need to explicitly declare a variables to store the values from IN parameter and then I need to use these variables in the WHERE clause. Not sure why this is required. Could you please help to resolve this without using the additional variables.
Below is the function, which I am using.
create or replace FUNCTION AGG_NC8B_FN (
FACTORY_ID NUMBER,
REPORTING_PERIOD NUMBER,
GRANULARITY_TYPE_TXT VARCHAR2,
GRANULAROTY_LEVEL_TXT VARCHAR2,
CONDITION_ID NUMBER)
RETURN NUMBER
IS
CAL_VALUE OCT_DMA_MOMIS.FCT_KSTACK_AGGREGATION.AGGREGATE_VALUE_DEC%TYPE;
-- temporary variables --not sure why this is required?
A number;
B number;
C varchar2(100);
D varchar2(100);
E number;
BEGIN
A:=FACTORY_ID;
B:=REPORTING_PERIOD;
C:=GRANULARITY_TYPE_TXT;
D:=GRANULAROTY_LEVEL_TXT;
E:=CONDITION_ID;
SELECT DECODE(B.AGGREGATE_VALUE_DEC,0,0,((A.AGGREGATE_VALUE_DEC/B.AGGREGATE_VALUE_DEC)*100))
INTO CAL_VALUE
FROM (SELECT AGGREGATE_VALUE_DEC
FROM OCT_DMA_MOMIS.FCT_KSTACK_AGGREGATION
WHERE FK_FIGURE_ID =30121
AND FK_FACTORY_ID =A
AND LK_REPORTING_PERIOD =B
AND GRANULARITY_TYPE_TXT=C
AND GRANULAROTY_LEVEL_TXT=D
AND FK_CONDITION_ID =E) A ,
(SELECT AGGREGATE_VALUE_DEC
FROM OCT_DMA_MOMIS.FCT_KSTACK_AGGREGATION
WHERE FK_FIGURE_ID =30122
AND FK_FACTORY_ID =A
AND LK_REPORTING_PERIOD =B
AND GRANULARITY_TYPE_TXT=C
AND GRANULAROTY_LEVEL_TXT=D
AND FK_CONDITION_ID =E
) B ;
RETURN CAL_VALUE;
END AGG_NC8B_FN;
Your function parameters and columns have same names (GRANULARITY_TYPE_TXT for example). Use different names or qualify function parameters with the name of the function:
-- wrong:
declare
function f(object_name in varchar2) return number is
l_id number;
begin
select object_id
into l_id
from all_objects
where object_name = object_name -- equals to (object name is not null)
and object_type = 'VIEW';
return l_id;
end;
begin
dbms_output.put_line(f('USER_OBJECTS'));
end;
> ORA-01422: exact fetch returns more than requested number of rows
-- right way:
declare
function f(object_name in varchar2) return number is
l_id number;
begin
select object_id
into l_id
from all_objects
where object_name = f.object_name -- subprogram_name.parameter_name
and object_type = 'VIEW';
return l_id;
end;
begin
dbms_output.put_line(f('USER_OBJECTS'));
end;
> 12345
Why this procedure doesn't work?
I tried to get by cursor the rows of the table: AF_EMPLOYEE, and this will order with ASC/DESC (according to the case).
Create or Replace Procedure return_rows_EMPLOYEE (in_order in number,
in_sorting in VARCHAR2, in_job in VARCHAR2, out_cursor OUT SYS_REFCURSOR) As
Begin
OPEN out_cursor for
select * from AF_EMPLOYEE
WHERE EMPL_JOB_TITLE = in_job
ORDER BY in_sorting
CASE in_order
WHEN 1 THEN ASC
ELSE DESC
END
End;
If the sort column is numeric, you can use case to negate it, but it's not good code!
CREATE OR REPLACE PROCEDURE return_rows_EMPLOYEE (in_order in number,
in_sorting in VARCHAR2, in_job in VARCHAR2, out_cursor OUT SYS_REFCURSOR) As
Begin
OPEN out_cursor for
select * from AF_EMPLOYEE
WHERE EMPL_JOB_TITLE = in_job
ORDER BY
CASE in_sorting WHEN 'ASC' THEN sort_column
WHEN 'DESC' THEN -sort_column
END;
END;
/
Create or Replace Procedure return_rows_EMPLOYEE (in_order in number,
in_sorting in VARCHAR2, in_job in VARCHAR2, out_cursor OUT SYS_REFCURSOR) As
Begin
if in_order = 1 THEN
OPEN out_cursor for
select * from AF_EMPLOYEE
WHERE EMPL_JOB_TITLE = in_job
ORDER BY in_sorting ASC
else
OPEN out_cursor for
select * from AF_EMPLOYEE
WHERE EMPL_JOB_TITLE = in_job
ORDER BY in_sorting DESC
end if;
End;
Update
try this:
Create or Replace Procedure return_rows_EMPLOYEE (in_order in number,
in_sorting in VARCHAR2, in_job in VARCHAR2, out_cursor OUT SYS_REFCURSOR) As
Begin
OPEN out_cursor for
select * from AF_EMPLOYEE
WHERE EMPL_JOB_TITLE = in_job
ORDER BY
case when in_order = 1 then
in_sorting
end,
case when in_order <> 1 then
in_sorting
end desc;
End;
I have problem with calling for my procedure. Oracle scrams
PLS-00306 Error: Wrong number of types of arguments in call to procedure.
With my type declaration procedure has exact the same declaration like in header below. If I run it as separate procedure it works, when i work in ODCI interface for extensible index creation, it throws PLS-00306.
MEMBER PROCEDURE FILL_TREE_LVL
(target_column VARCHAR2, cur_lvl NUMBER, max_lvl NUMBER,
parent_rect NUMBER,start_x NUMBER, start_y NUMBER,
end_x NUMBER, end_y NUMBER)
IS
stmt VARCHAR2(2000);
rect_id NUMBER;
diff_x NUMBER;
diff_y NUMBER;
new_start_x NUMBER;
new_end_x NUMBER;
i NUMBER;
j NUMBER;
BEGIN
{...}
END FILL_TREE_LVL;
STATIC FUNCTION ODCIINDEXCREATE
(ia SYS.ODCIINDEXINFO, parms VARCHAR2, env SYS.ODCIEnv) RETURN NUMBER
IS
stmt VARCHAR2(2000);
stmt2 VARCHAR2(2000);
min_x NUMBER;
max_x NUMBER;
min_y NUMBER;
max_y NUMBER;
lvl NUMBER;
rect_id NUMBER;
pt_tab VARCHAR2(50);
rect_tab VARCHAR2(50);
cnum NUMBER;
TYPE point_rect is RECORD(
point_id NUMBER,
rect_id NUMBER
);
TYPE point_rect_tab IS TABLE OF point_rect;
pr_table point_rect_tab;
BEGIN
{...}
FILL_TREE_LVL('any string', 0, lvl,0, min_x, min_y, max_x, max_y);
{...}
END;
I have no experience in PL/SQL OOP, but I guess the problem occurs because you try to call a member procedure from a static function. A member procedure always needs an object context, which is lacking in the call.
Looks like you're missing a parameter, probably parent_rect I'm guessing:
FILL_TREE_LVL(target_column VARCHAR2,
cur_lvl NUMBER,
max_lvl NUMBER,
parent_rect NUMBER,
start_x NUMBER,
start_y NUMBER,
end_x NUMBER,
end_y NUMBER)
FILL_TREE_LVL('any string', --target_column
0, --cur_lvl
lvl, --max_lvl
min_x, --parent_rect
min_y, --start_x
max_x, --start_y
max_y --end_x
--end_y ???
);