refcursor in package
HelloCan I use REFCURSOR in the package.
If not why?
Yes...
see the example.
CREATE OR REPLACE PACKAGE CURSPKG AS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
IO_CURSOR IN OUT T_CURSOR);
PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
DEPTCURSOR OUT T_CURSOR);
END CURSPKG;
CREATE OR REPLACE PACKAGE BODY CURSPKG AS
PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
IO_CURSOR IN OUT T_CURSOR)
IS
V_CURSOR T_CURSOR;
BEGIN
IF N_EMPNO <> 0
THEN
OPEN V_CURSOR FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO
AND EMP.EMPNO = N_EMPNO;
ELSE
OPEN V_CURSOR FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;
END IF;
IO_CURSOR := V_CURSOR;
END OPEN_ONE_CURSOR;
PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
DEPTCURSOR OUT T_CURSOR)
IS
V_CURSOR1 T_CURSOR;
V_CURSOR2 T_CURSOR;
BEGIN
OPEN V_CURSOR1 FOR SELECT * FROM EMP;
OPEN V_CURSOR2 FOR SELECT * FROM DEPT;
EMPCURSOR := V_CURSOR1;
DEPTCURSOR := V_CURSOR2;
END OPEN_TWO_CURSORS;
END CURSPKG;
Mezaber
Tags: Database
Similar Questions
-
Hi all
There will be no effect in performance if we declare refcurosr with suspicion NOCOPY parameter in a Stored procedure procedure/package?
AFAIK variable refcursor who will make reference to the calling environment will hold just pointer not data and so avoid a NOCOPY effect.
Thank you!!
DS says:
One of my senior team members asked me to NOCOPY in all existing procedures where refcursor is returned as a parameter in my output project.
I told him that this will not add any performance improvement and has no effect.
I did it, because I was forced to do so.
Want to just check and take the advice from here in this forum.
I still have the document (in e-mails and in the procedure itself at the top) all these changes so that the future code-reviewers know EXACTLY why this change has been made and who authorized it. Probably you are asking your "senior" you say the reasons to support the change that they requested; You should document those as well.
Sounds like your "senior" team member is not so superior after all. You can use this as a topic of discussion in your dev group.
See the doc of the PL/SQL language.
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i48500
Calls to PL/SQL Tuning subprogramme with NOCOPY hint
By default,
OUT
andIN
OUT
parameters are passed by value. The values of aIN
OUT
settings are copied before the delivery of the subprogramme. During the execution of the subprogramme, temporary variables to maintain the output parameter values. If the subprogram exits normally, these values are copied to the actual parameters. If the subprogram exits with an unhandled exception, the original settings are unchanged.When the parameters represent structures of large data such as collections, records and instances of object types, this reproduction slows down execution and uses memory. In particular, this overload applies to each call to a method of the object: temporary copies are made of all attributes, so that any changes made by the method are only apply if the method ends normally.
To avoid this overload, you can specify the
NOCOPY
trick, which allows the PL/SQL compiler to passOUT
andIN
OUT
parameters by reference. If the subprogram exits normally, the action is the same as usual. If the subprogramme leaves at the beginning with an exception, the values ofOUT
andIN
OUT
parameters (or the attributes of the object) can still change. To use this technique, check that the subroutine handles all exceptions.Note the reference to the "large data structures. As you already know a REFCURSOR isn't a large data structure, so will not use NOCOPY.
The most important side effect is that, as noted in the last paragraph above, the characteristics of the 'exit' are modified if you use NOCOPY.
Point out that the last clause in your "senior": ENSURE THAT THE subprogram MANAGES all THE EXCEPTIONS.
Normally (i.e. without using NOCOPY) a REFCURSOR lucifera is a parameter OUT will NOT have a value if the procedure stops with an exception if the caller is unable to use it eventually. Maybe this isn't the case if you use NOCOPY.
Generally however, the use of NOCOPY would simply be an amendment unnecessary, but harmless.
-
execution of the procedure with refcursor as output parameter
Hi I have the package following a procedure with parameter as refcursor OUT.
Here is an example of sample with the same structure with name in the other table, handling exceptions in my dev environment
When I try to execute this procedure with the followig blockCREATE OR REPLACE PACKAGE TEST_PACK IS Type refCursor is REF CURSOR; PROCEDURE TEST_PROC (out_data out refCursor); END; CREATE OR REPLACE PACKAGE BODY TEST_PACK IS Procedure test_proc ( out_data out refCursor ) is -- v_sql varchar2(4000); -- begin v_sql := 'select * from emp'; DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql ); open out_data for v_sql; Exception when others then DBMS_OUTPUT.PUT_LINE ( 'Error '|| SQLCODE ||','||SQLERRM ); END; end ;
I get the following errorDECLARE TYPE my_newcursor IS REF CURSOR; test_cur my_newcursor; out_text VARCHAR2 (4000); BEGIN TEST_PACK.test_proc(TEST_CUR) ; LOOP FETCH test_cur INTO out_text; EXIT WHEN test_cur%NOTFOUND; dbms_output.put_line('Value of refcur is:'||out_text); END LOOP; CLOSE test_cur; END;
Could you please help me where I am doing wrongORA-00932: inconsistent datatypes: expected - got - ORA-06512: at line 8
Thank youYou must extract your data to an appropriate data type.
(and note there is no need to declare your own ref cursor type as Oracle provides sys_refcursor at the end)
for example
SQL> set serverout on SQL> SQL> create or replace procedure test_proc(out_data out sys_refcursor) is 2 v_sql varchar2(4000); 3 begin 4 v_sql := 'select * from emp'; 5 DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql ); 6 open out_data for v_sql; 7 end; 8 / Procedure created. SQL> SQL> declare 2 rc sys_refcursor; 3 empRec emp%rowtype; 4 begin 5 test_proc(rc); 6 loop 7 fetch rc into empRec; 8 exit when rc%notfound; 9 dbms_output.put_line('Employee: '||empRec.empno||' - '||empRec.ename); 10 end loop; 11 close rc; 12 end; 13 / Select Query is: select * from emp Employee: 7369 - SMITH Employee: 7499 - ALLEN Employee: 7521 - WARD Employee: 7566 - JONES Employee: 7654 - MARTIN Employee: 7698 - BLAKE Employee: 7782 - CLARK Employee: 7788 - SCOTT Employee: 7839 - KING Employee: 7844 - TURNER Employee: 7876 - ADAMS Employee: 7900 - JAMES Employee: 7902 - FORD Employee: 7934 - MILLER PL/SQL procedure successfully completed. SQL>
Why do you use a slider ref anyway?
{: identifier of the thread = 886365}
-
Disadvantages of using REFCURSORs of JDBC
Hello
Normally, I write my SQL inside Java (for example PreparedStatements) statements.
I am studying on the establishment of the PL/SQL Packages, providing the procedures and methods, I can call Java using CallableStatements. I understand the benefits of having a layer/API on the database side.
For example: extract some records in a table. (the PL/SQL function getCustomers returns a REFCURSOR)
-PreparedStatement (select... from... where...)->-> loop ResultSet executeQuery
-CallableStatement ("start?: = getCustomers();") end; ")-> cast getObject() to ResultSet-> loop ResultSet
---
What are the disadvantages of using the CallableStatement (REFCURSOR)?
Thank you, best regards, Stephan>
I was thinking about the extraction of the differences of lines (line single OR multiple rows per round trip to the DB).If I understand correctly, I can set the size of Fetch on a CallableStatement (Oracle), so to get several lines of the REFCURSOR per round trip ticket to the DB.
>
Recovery of data from an Oracle database using cursors: no exceptions.The JDBC layer is what includes the "batch processing" feature that you describe and the feature is independent of the source of the cursor. If you use Oracle extensions, so you can take advantage of automated dosing of Oracle.
Using a REF CURSOR is how preferred and recommended to provide data from the database to an external client.
1. it minimizes dependencies between the DB and the customer. The function/procedure that provides REF CURSOR is the only dependency.
2. it maximizes the security of the data. Responsibility to secure data is based only on the side DB through the function/procedure. It is simply not possible for the Client software to access the data not authorized unless the function/procedure he has. The customer has NO access to the data, except by the REF CURSOR.
3. it maximizes the security of the database. Access to the database itself is easier to control. Customers only need to access an account that has extremely limited privileges: privilege to EXECUTE the function/procedure. Customers should not any table, view, or other privileges to do their job.
4. it minimizes the probability of error by the customer. It is impossible for the client to access the bad table/view or data. Customers don't need to know how to join tables or even know what are the name of the table or where the data resides.
5. it minimizes the knowledge and skills that the client developer needs to do their work. The client developer can focus on their two main issues: 1) what data do I need for my application, 2) what do I do with this data.
6. the risk of 'performance' (or sentence) is if the procedure/function is misspelled or uses wrong written queries to get the data.
In short use a REF CURSOR allows the developer to DB deal with the best way to provide the data and the developer client side withj records how to consume these data.
Use of any solution other than a REF CURSOR should be the EXCEPTION rather than the rule.
-
Statement of the type of cursor in package/sp
Hello
I use the package with sp than using slider as below:
--#1============================ PACKAGE
{THE PACKAGE AS ORA_PK_TR2
Type CURS_01 IS REF CURSOR; -return RYBB. T_COLLECT % rowtype;
Procedure ORA_SP_CUST (present in date_exp,
END
--#2============================ BODY
create or replace
PACKAGE ORA_PK_TR2 BODY as
Procedure ORA_SP_CUST (present in date_exp,
open_CURS_01 OUT CURS_01) IS
BEGIN
SQL_string = "(select * de RYBB.)" T_COLLECT where col =' | DATE_EXP)"
Open_CURS_01 OPEN FOR SQL_STRING;
END;
-3 # = RUN_PORTION
DECLARE
DATE_EXP DATE;
OPEN_CURS_01 RYBB. ORA_PK_TR2. CURS_01;
TYPE_IN RYBB. T_COLLECT % ROWTYPE; -/ * < = go to the package
BEGIN
Date_exp: = 10-seven.-10';
RYBB. ORA_PK_TR2. () ORA_SP_CUST
Date_exp = > date_exp.
OPEN_CURS_01 = > OPEN_CURS_01
);
LOOP
Look FOR open_CURS_01 IN TYPE_IN;
EXIT WHEN open_CURS_01% NOTFOUND;
DBMS_OUTPUT. PUT_LINE (TYPE_IN. COL1 | » '|| TYPE_IN. COL2); -/ sample
END LOOP;
END ;}
I need to put TYPE_IN declation of cursor inside the packaging, so the user who will run this pack/sp deals with this structure. How I can do this,
I tried to use < return RYBB. T_COLLECT % rowtype; > in the package but then I get:
Error (122,6): PLS-00455: cursor 'open_CURS_01' cannot be used in a dynamic OPEN SQL statement.
Not sure I can somehow in the BODY and make it available to the user?
Help you enjoy.
Best
Trent
Published by: trento on 13 Sep, 2010 14:36Hello
Slider strong Ref (with a return type) cannot be used with dynamic SQL
because the compiler cannot check dynamic SQL return type during compilation.
String ref cursor can be used only with static SQL.
Dynamic SQL can be used only with the low (untyped) cursor variables.You can use static SQL in your procedure, look at this example:
create or replace PACKAGE TEST AS TYPE CURS_01 IS REF CURSOR RETURN SCOTT.EMP%ROWTYPE; Procedure ORA_SP_CUST (EXP_DATE IN date, open_CURS_01 IN OUT CURS_01 ); END TEST; / CREATE OR REPLACE PACKAGE BODY TEST AS PROCEDURE ORA_SP_CUST (EXP_DATE IN DATE, OPEN_CURS_01 IN OUT CURS_01 ) AS BEGIN OPEN OPEN_CURS_01 FOR SELECT * FROM SCOTT.EMP WHERE SCOTT.EMP.HIREDATE = EXP_DATE; END ORA_SP_CUST; END TEST; / VARIABLE CR REFCURSOR; BEGIN test.ORA_SP_CUST (TO_DATE('1981/12/03', 'yyyy/mm/dd'), :cr ); END; / print :cr CR --------------------------------------------------------------------------------------------------------------------------------------------------------------- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------------------- ---------- --------- ---------------------- ------------------------- ---------------------- ---------------------- ---------------------- 7900 JAMES CLERK 7698 1981/12/03 950 30 7902 FORD ANALYST 7566 1981/12/03 3000 20
-
problem with the collection and refcursor
I have the 'ServerDisconnect2' function below. It should return as 'ref_cursor' on the parameter that is a data container of deleted rows slider, Java developers insist on using this type of data/collection. I don't know how to code to return the values of ID removed as 'ref_cursor '. See commented "open pDeleteList" - sentence, it is commented as does not compile.
Is it possible to convert the variable 'vDeleteList' in ref_cursor?CREATE OR REPLACE PACKAGE oe_ctx AS TYPE gIntegerTable IS TABLE OF INTEGER INDEX BY BINARY_INTEGER; TYPE cursor_type IS REF CURSOR; .... PROCEDURE ServerDisconnect2(pCasinoCode NUMERIC, pCasinoServerCode NUMERIC, pChannelServerCode CurrentLogins.ChannelServerCode%TYPE, pDeleteList OUT cursor_type) IS vDeleteList oe_ctx.gIntegerTable; BEGIN DELETE FROM ( SELECT cl.* FROM CurrentLogins cl, Accounts a WHERE cl.CasinoCode = pCasinoCode AND cl.CasinoServerCode = pCasinoServerCode AND cl.ChannelServerCode = pChannelServerCode AND cl.Code = a.code AND a.Type = 'lplayer' ORDER BY a.code ) RETURNING Code BULK COLLECT INTO vDeleteList; /* OPEN pDeleteList FOR SELECT * FROM TABLE(vDeleteList);*/ COMMIT; END ServerDisconnect2;
So my only solution would be to open the ref_cursor BEFORE delete-clause with the same query delete clause has. But I'm afraid that then after opening the instant cursor after a milliseconds the deletion clause removes different lines and the procedure would be data incorrect in pDeleteList.
Published by: CharlesRoos on August 26, 2010 06:10You need a collection of sql (created with CREATE TYPE...):
I'll use the predefined collection sys.odcivarchar2list demonstation purposes:
SQL> var cur refcursor SQL> declare ret_coll sys.odcivarchar2list; begin delete from emp returning ename bulk collect into ret_coll; open :cur for select * from table (ret_coll); end; / PL/SQL procedure successfully completed. SQL> print COLUMN_VALUE ----------------------------------------------------------------------------------------------------------------------------- SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER 14 rows selected.
-
2 refcursors within the same procedure using
Hello
Can we use 2 refcursors within the same procedure. This may seem strange. But I have a script to do so - one to dynamically check for some validations and another to return a result set.Yes, pass by the example below.
CREATE OR REPLACE PACKAGE CURSPKG AS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE (EMPCURSOR ON T_CURSOR OPEN_TWO_CURSORS,
DEPTCURSOR ON T_CURSOR);
END CURSPKG;
/
CREATE OR REPLACE PACKAGE BODY CURSPKG AS
PROCEDURE (EMPCURSOR ON T_CURSOR OPEN_TWO_CURSORS,
DEPTCURSOR ON T_CURSOR)
IS
V_CURSOR1 T_CURSOR;
V_CURSOR2 T_CURSOR;
BEGIN
V_CURSOR1 OPEN FOR SELECT * FROM EMP;
V_CURSOR2 OPEN FOR SELECT * FROM THE DEPARTMENT;
EMPCURSOR: = V_CURSOR1;
DEPTCURSOR: = V_CURSOR2;
END OPEN_TWO_CURSORS;
END CURSPKG;
/I hope that it would be useful.
-
PLS-00304: cannot compile <; package >; body without its specification
Hi all
When compiling the below pasted together, I got the following error msg.
But me, which forfeit and ppackage specification of the body properly. Please could someone help me find the errorPL/SQL: Compilation unit analysis terminated PLS-00304: cannot compile body of 'EDR_RPT_CLASS_BY_TAWT_PACKAGE' without its specification PLS-00905: object HDOT.EDR_RPT_CLASS_BY_TAWT_PACKAGE is invalid
CREATE OR REPLACE PACKAGE edr_rpt_class_by_tawt_package AS PROCEDURE edr_rpt_gen_class_by_tawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ); PROCEDURE edr_rpt_gen_class_by_fawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ); PROCEDURE edr_rpt_gen_class_by_sawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ); PROCEDURE edr_rpt_gen_class_by_triawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ); PROCEDURE edr_rpt_gen_class_by_qawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ); FUNCTION class_count ( in_lane_id edr_rpt_by_ranges_output.lane_id%TYPE, in_direction_id edr_rpt_by_ranges_output.direction_id%TYPE, in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE, in_interval_end_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE, in_axle_wt_min edr_cls_by_tawt_report_data.group_weight%TYPE, iin_axle_wt_max edr_cls_by_tawt_report_data.group_weight%TYPE, in_class_min edr_cls_by_tawt_report_data.vehicle_class%TYPE, in_class_max edr_cls_by_tawt_report_data.vehicle_class%TYPE ) RETURN VARCHAR2; END edr_rpt_class_by_tawt_package; / CREATE OR REPLACE PACKAGE BODY edr_rpt_class_by_tawt_package AS c_front_axle_only CONSTANT axle_class.group_type%TYPE := -1; c_axle_single_group_type CONSTANT axle_class.group_type%TYPE := 1; c_axle_tandem_group_type CONSTANT axle_class.group_type%TYPE := 2; c_axle_tridem_group_type CONSTANT axle_class.group_type%TYPE := 3; c_axle_quadrem_group_type CONSTANT axle_class.group_type%TYPE := 4; c_kips_conversion_unit_id CONSTANT units.unit_id%TYPE := 8; v_report_axle_group_type axle_class.group_type%TYPE := 0; FUNCTION class_count ( in_lane_id edr_rpt_by_ranges_output.lane_id%TYPE, in_direction_id edr_rpt_by_ranges_output.direction_id%TYPE, in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE, in_interval_end_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE, in_axle_wt_min edr_cls_by_tawt_report_data.group_weight%TYPE, in_axle_wt_max edr_cls_by_tawt_report_data.group_weight%TYPE, in_class_min edr_cls_by_tawt_report_data.vehicle_class%TYPE, in_class_max edr_cls_by_tawt_report_data.vehicle_class%TYPE ) RETURN NUMBER IS my_count_result NUMBER(18); BEGIN SELECT NVL(SUM(vehicle_count), 0 ) INTO my_count_result FROM ( SELECT site_lane_id FROM edr_rpt_tmp_report_lanes WHERE edr_rpt_tmp_report_lanes.output_lane_id = in_lane_id AND edr_rpt_tmp_report_lanes.output_direction_id = in_direction_id ) report_lanes JOIN edr_cls_by_tawt_report_data ON edr_cls_by_tawt_report_data.site_lane_id = report_lanes.site_lane_id WHERE edr_cls_by_tawt_report_data.bin_start_date_time >= in_interval_start_date_time AND edr_cls_by_tawt_report_data.bin_start_date_time < in_interval_end_date_time AND edr_cls_by_tawt_report_data.group_weight >= in_axle_wt_min AND edr_cls_by_tawt_report_data.group_weight < in_axle_wt_max AND edr_cls_by_tawt_report_data.vehicle_class >= in_class_min AND edr_cls_by_tawt_report_data.vehicle_class <= in_class_max ; RETURN my_count_result; END; FUNCTION get_row_class_counts_text RETURN VARCHAR2 IS my_row_counts_text VARCHAR2(10000); my_row_counts_entry VARCHAR2(10000); CURSOR row_counts_text IS SELECT 'edr_rpt_class_by_tawt_package.class_count(' ||'lane_id, ' ||'direction_id, ' ||'interval_start_date_time, ' ||'interval_end_date_time, ' ||'range_low, ' ||'range_high, ' || class_id || ', ' || class_id || ') "'|| class_id || '"' FROM edr_rpt_tmp_report_classes ORDER BY class_id; BEGIN my_row_counts_text := ''; my_row_counts_entry := ''; -- generate the speed ranges function calls OPEN row_counts_text; LOOP FETCH row_counts_text INTO my_row_counts_entry; EXIT WHEN row_counts_text%NOTFOUND; my_row_counts_text := my_row_counts_text || ', ' || my_row_counts_entry; END LOOP; CLOSE row_counts_text; RETURN my_row_counts_text; END; FUNCTION get_row_totals_text RETURN VARCHAR2 IS my_row_count_total_text VARCHAR2(10000); BEGIN my_row_count_total_text := ''; -- generate the 'total' column function call SELECT 'edr_rpt_class_by_tawt_package.class_count(' ||'lane_id, ' ||'direction_id, ' ||'interval_start_date_time, ' ||'interval_end_date_time, ' ||'range_low, ' ||'range_high, ' || MIN(class_id) || ', ' || MAX(class_id) || ') " "' INTO my_row_count_total_text FROM edr_rpt_tmp_report_classes; RETURN ', ' || my_row_count_total_text; END; PROCEDURE apply_default_awt_ranges(in_report_parameter_id IN NUMBER) IS my_awt_ranges_count NUMBER(4); BEGIN SELECT nvl(count(1),0) INTO my_awt_ranges_count FROM report_range_parameters WHERE REPORT_PARAMETER_ID = in_report_parameter_id AND REPORT_PARAMETER_GROUP = 'AXLE_GROUP' AND REPORT_PARAMETER_NAME = 'AXLE_NAME'; IF ( my_awt_ranges_count = 0 ) THEN INSERT INTO report_range_parameters (REPORT_PARAMETER_ID, REPORT_PARAMETER_GROUP, REPORT_PARAMETER_NAME, REPORT_PARAMETER_MIN_VALUE, REPORT_PARAMETER_MAX_VALUE) VALUES (in_report_parameter_id, 'AXLE_GROUP', 'AXLE_NAME', '0', '2'); VALUES (in_report_parameter_id, 'AXLE_GROUP', 'AXLE_NAME', '30', '32'); END IF; END; PROCEDURE edr_class_by_tawt_use_per_veh ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, in_good_status_mask IN NUMBER ) IS max_axle_group_value NUMBER(12); BEGIN DELETE FROM edr_cls_by_tawt_report_data; COMMIT; INSERT INTO edr_cls_by_tawt_report_data ( site_id, site_lane_id, site_direction_id, site_direction_name, bin_start_date_time, group_weight, bin_id, bin_value ) SELECT site_id, site_lane_id, site_direction_id, site_direction_name, date_time, group_weight, vehicle_class, COUNT(vehicle_class) FROM ( SELECT edr_cls_by_tawt_per_veh_data.* FROM edr_cls_by_tawt_per_veh_data GROUP BY date_time, site_lane_id, group_weight, vehicle_class, site_id, site_direction_id, site_direction_name; END edr_class_by_tawt_use_per_veh; PROCEDURE edr_class_by_tawt_data_type ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, in_good_status_mask IN NUMBER, in_data_type IN VARCHAR2, out_data_type_used OUT VARCHAR2 ) IS my_bin_entry_count NUMBER(12,0); my_veh_entry_count NUMBER(12,0); BEGIN IF(UPPER(in_data_type) = 'BINNED') THEN -- Axle information can only be read from Per Vehicle data records -- - using bins-only is not a supported option RAISE_APPLICATION_ERROR(-20101,'Binned data cannot be used for this report.'); ELSIF (UPPER(in_data_type) = 'PERVEHICLE') OR (UPPER(in_data_type) = 'COMBINED') THEN out_data_type_used := 'Per Vehicle (All Vehicles)'; edr_class_by_tawt_use_per_veh( in_report_parameter_id, in_good_status_mask ); ELSE RAISE_APPLICATION_ERROR(-20101,'The data type specified is not recognized.'); END IF; END edr_class_by_tawt_data_type; PROCEDURE edr_class_by_tawt_get_veh_data ( in_report_parameter_id IN NUMBER, in_site_id IN NUMBER, in_start_date_time IN TIMESTAMP, in_end_date_time IN TIMESTAMP, in_report_level_min IN NUMBER, in_report_level_max IN NUMBER ) IS BEGIN DELETE FROM edr_cls_by_tawt_per_veh_data; INSERT INTO edr_cls_by_tawt_per_veh_data ( site_id, site_lane_id, site_direction_id, site_direction_name, record_id, date_time, group_weight, vehicle_class, group_number, vehicle_status, vehicle_error_count, axle_violations_count, group_type ) SELECT axle_info.site_id, axle_info.site_lane_id, axle_info.site_direction_id, axle_info.site_direction_name, axle_info.record_id, axle_info.datetime, axle_info.group_weight, axle_info.v_class, axle_info.group_number, NVL((SELECT SUM(status_code) FROM traffic_status WHERE traffic_status.record_id = axle_info.record_id), 0) vehicle_status, NVL((SELECT COUNT(error_code) FROM traffic_error WHERE traffic_error.record_id = axle_info.record_id), 0) vehicle_error_count, NVL((SELECT COUNT(1) FROM axle_weight_violation WHERE axle_weight_violation.record_id = axle_info.record_id), 0) axle_violations_count, axle_info.group_type FROM (SELECT site_to_data_source_lane_v.site_id, site_to_data_source_lane_v.site_lane_id, site_to_data_source_lane_v.site_direction_id, site_to_data_source_lane_v.site_direction_name, traffic_record.record_id, traffic_record.datetime, NVL(traffic_class.v_class, 0) v_class, NVL(axle_class.group_type, 0) group_type, NVL(axle_class.group_number, 0) group_number, NVL(TRUNC(sum(convert_units(axle.weight_unit_id, c_kips_conversion_unit_id, axle.axle_weight ) ) ), 0 ) group_weight FROM traffic_record JOIN site_to_data_source_lane_v ON traffic_record.data_source_id = site_to_data_source_lane_v.data_source_id AND traffic_record.lane = site_to_data_source_lane_v.data_source_lane_id GROUP BY site_to_data_source_lane_v.site_id, site_to_data_source_lane_v.site_lane_id, site_to_data_source_lane_v.site_direction_id, site_to_data_source_lane_v.site_direction_name, traffic_record.record_id, traffic_record.datetime, traffic_class.v_class, axle_class.group_type, axle_class.group_number ) axle_info END edr_class_by_tawt_get_veh_data; PROCEDURE gen_class_by_axle_type ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN apply_default_awt_ranges(in_report_parameter_id); my_date_format_mask := edr_rpt_generic_package.edr_rpt_get_date_format_mask(in_report_parameter_id); my_start_date_time := edr_rpt_generic_package.edr_rpt_get_start_date_time(in_report_parameter_id, my_date_format_mask); my_end_date_time := edr_rpt_generic_package.edr_rpt_get_end_date_time(in_report_parameter_id, my_date_format_mask); my_lane_grouping := edr_rpt_generic_package.edr_rpt_get_lane_grouping(in_report_parameter_id); my_site_id := edr_rpt_generic_package.edr_rpt_get_site_id(in_report_parameter_id); my_selected_data_type := edr_rpt_generic_package.edr_rpt_get_data_type(in_report_parameter_id); -- ensure selected classes and lanes temp tables have been populated edr_rpt_generic_package.edr_rpt_gen_tmp_lanes(in_report_parameter_id); edr_rpt_generic_package.edr_rpt_gen_tmp_classes(in_report_parameter_id); edr_rpt_generic_package.edr_rpt_gen_tmp_speed_ranges(in_report_parameter_id); my_good_weight_statuses_mask := edr_rpt_generic_package.get_good_weight_status_mask(in_report_parameter_id); edr_rpt_generic_package.edr_rpt_gen_inclusion_table ( in_report_parameter_id, my_date_format_mask, my_start_date_time, my_end_date_time ); edr_rpt_generic_package.edr_rpt_gen_grouping_table ( in_report_parameter_id, my_date_format_mask, my_start_date_time, my_end_date_time ); edr_class_by_tawt_get_veh_data ( in_report_parameter_id, my_site_id, my_start_date_time, my_end_date_time, 0, --Hardcoded until reclassification is supported. 0 --Hardcoded until reclassification is supported. ); edr_class_by_tawt_data_type ( in_report_parameter_id, my_good_weight_statuses_mask, my_selected_data_type, my_used_data_type ); edr_rpt_generic_package.gen_rpt_by_ranges_output_table ( in_report_parameter_id, 'AXLE_GROUP', 'AXLE_NAME' ); COMMIT; my_report_data_statement := ' SELECT rank "Rank", ' || ' row_type "Row Type", ' || ' interval_start_date_time "Date", ' || ' interval_start_date_time, ' || ' range_label "Chart X-Axis", ' || ' lane_id "Group Id" , ' || ' ''None'' "Group Name", ' || ' range_label "Speed (mph)" ' || get_row_class_counts_text || get_row_totals_text || ' FROM edr_rpt_by_ranges_output ' || ' ORDER BY lane_id, ' || ' direction_id, ' || ' interval_start_date_time, ' || ' range_high, ' || ' rank, ' || ' range_low' ; dbms_output.put_line('SQL start------------------------'); dbms_output.put_line(my_report_data_statement); dbms_output.put_line('SQL end--------------------------'); my_chart_data_statement := ' SELECT range_low "X Axis", ' || ' lane_id "Group" ' || get_row_class_counts_text || ' FROM ' || ' ( ' || ' SELECT lane_id, ' || ' direction_id, ' || ' range_low, ' || ' range_high, ' || ' min(interval_start_date_time) interval_start_date_time, ' || ' max(interval_end_date_time) interval_end_date_time ' || ' FROM edr_rpt_by_ranges_output ' || ' WHERE rank = 1 ' || ' GROUP BY lane_id, direction_id, range_low, range_high ' || ' ) ' || ' order by "Group", range_low ' ; dbms_output.put_line('SQL start------------------------'); dbms_output.put_line(my_chart_data_statement); dbms_output.put_line('SQL end--------------------------'); SELECT my_used_data_type INTO my_data_type_used FROM SYS.DUAL; SELECT NVL(COUNT(DISTINCT record_id), 0) INTO my_per_vehicle_total FROM edr_cls_by_tawt_per_veh_data; SELECT NVL(COUNT(DISTINCT record_id), 0) INTO my_status_vehicle_total FROM edr_cls_by_tawt_per_veh_data WHERE vehicle_status > 0 AND vehicle_error_count = 0; SELECT NVL(COUNT(DISTINCT record_id), 0) INTO my_error_vehicle_total FROM edr_cls_by_tawt_per_veh_data WHERE vehicle_error_count > 0; SELECT NVL(COUNT(DISTINCT record_id), 0) INTO my_status_clear_total FROM edr_cls_by_tawt_per_veh_data WHERE vehicle_status = 0 AND vehicle_error_count = 0; SELECT NVL(COUNT(1), 0) INTO my_binned_vehicle_total FROM edr_cls_by_tawt_per_veh_data; SELECT NVL(COUNT(1), 0) INTO my_good_weight_total FROM edr_cls_by_tawt_per_veh_data WHERE vehicle_error_count = 0 AND BITAND(vehicle_status, my_good_weight_statuses_mask) = 0; -- insert vehicle totals into the temporary table DELETE FROM edr_rpt_tmp_veh_totals_table; INSERT INTO edr_rpt_tmp_veh_totals_table SELECT my_data_type_used, my_per_vehicle_total, my_binned_vehicle_total, my_error_vehicle_total, my_status_vehicle_total, my_good_weight_total, my_status_clear_total FROM SYS.DUAL; -- execute the query into the output refcursor OPEN report_data FOR my_report_data_statement; OPEN chart_data FOR my_chart_data_statement; OPEN footer_data FOR SELECT data_type_used, per_vehicle_total, binned_vehicle_total, error_vehicle_total, status_vehicle_total, good_weight_total, status_clear_total FROM edr_rpt_tmp_veh_totals_table; END gen_class_by_axle_type; PROCEDURE edr_rpt_gen_class_by_sawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN v_report_axle_group_type := c_axle_single_group_type; gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data); END; PROCEDURE edr_rpt_gen_class_by_fawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN v_report_axle_group_type := c_front_axle_only ; gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data); END; PROCEDURE edr_rpt_gen_class_by_tawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN v_report_axle_group_type := c_axle_tandem_group_type; gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data); END; PROCEDURE edr_rpt_gen_class_by_triawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN v_report_axle_group_type := c_axle_tridem_group_type; gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data); END; PROCEDURE edr_rpt_gen_class_by_qawt ( in_report_parameter_id IN report_tasks.report_task_id%TYPE, report_data OUT SYS_REFCURSOR, chart_data OUT SYS_REFCURSOR, footer_data OUT SYS_REFCURSOR ) AS BEGIN v_report_axle_group_type := c_axle_quadrem_group_type; gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data); END; END edr_rpt_class_by_tawt_package; / LIST SHOW ERROR
FUNCTION RETURN VARCHAR2 class_count in package specifications and
FUNCTION RETURN NUMBER class_count in the package body.
change the type of data SERVICE class_count -
Reg. Converting a package in a Ref cursor level slider
Hi guru,.
I need to convert a package-level slider which contains the clause 'FOR UPDATE OF' in a Ref cursor when the query will be dynamically built with the necessary table name and other settings.
Using this slider many Update statement were made with the 'WHERE CURRENT OF' included in this clause.
Now, I've changed my Ref cursor cursor, but when I compile the cursor is dynamic based is not identified, because I get the error message.
Can someone tell me how to implement?
I need only go to dynamic bulding of the whole procedure.
Kind regards
Vijayasekaran.NMaybe you can use around the ROWID. Like this
Say what your actual code.
declare cursor c is select * from t for update of name; lno t.no%type; lname t.name%type; begin open c; loop fetch c into lno, lname; exit when c%notfound; update t set name = lno||lname where current of c; end loop; close c; end; /
With refcursor you can do.
declare type rc is ref cursor; c rc; lno t.no%type; lname t.name%type; lrowid rowid; begin open c for 'select rowid rid, t.* from t for update of name'; loop fetch c into lrowid,lno, lname; exit when c%notfound; update t set name = lno||lname where rowid = lrowid; end loop; close c; end; /
Published by: Karthick_Arp on December 26, 2008 02:00
-
refcursor out back of a function
Hello...
as the topic of this thread I have indicates wud like to know if it is possible to return an ouput refcursor from a function.coz' a FN can only return a value...
pls help me.
Thank you and best regards,CREATE OR REPLACE FUNCTION PRM_FN_GETHOP ( HOP IN VARCHAR2 , ProcessFor IN VARCHAR2, get_hop_cursor OUT SYS_REFCURSOR) RETURN varchar2 AS v_current_amount number; BEGIN if ProcessFor is null then select PPH_CUR_AMOUNT into v_current_amount from prm_p_hop where PPH_HOP_CODE=HOP; return v_current_amount; else open get_hop_cursor for select PPH_ARR_AMOUNT,PPH_LOP_AMOUNT,PPH_LOPR_AMOUNT from PRM_P_HOP where PPH_HOP_CODE=HOP; RETURN get_hop_cursor; END IF; END PRM_FN_GETHOP;
user10422719 wrote:
Hello...of course... they are...!
the fn must have two the HOP and process
By pressing the Fn with a null value for the process... it must perform a select operation that chooses only one record
else... He must select three columns of a record...any thoughts on the use of case?
The function can return only one type of data. If 'a record' is the same structure as the "a record", then you can return to this structure, but if they are different, then the function is expanded wrongly.
If you use a package, you can overload your name of the function so that it recognizes when parameters are passed in and then each of the functions can return different types...
SQL> ed Wrote file afiedt.buf 1 create or replace package test_pkg as 2 function get_emps(p_deptno IN NUMBER, p_processfor IN NUMBER) return number; 3 function get_emps(p_deptno IN NUMBER) return sys_refcursor; 4* end; SQL> / Package created. SQL> ed Wrote file afiedt.buf 1 create or replace package body test_pkg as 2 function get_emps(p_deptno IN NUMBER, p_processfor IN NUMBER) return number is 3 v_sum number; 4 begin 5 select sum(sal) 6 into v_sum 7 from emp 8 where deptno = p_deptno; 9 return v_sum; 10 end; 11 function get_emps(p_deptno IN NUMBER) return sys_refcursor is 12 v_rc sys_refcursor; 13 begin 14 open v_rc for 'select sal from emp where deptno = '||p_deptno; 15 return v_rc; 16 end; 17* end; SQL> / Package body created. SQL> var emp_sum number; SQL> exec :emp_sum := test_pkg.get_emps(30,0); PL/SQL procedure successfully completed. SQL> print :emp_sum; EMP_SUM ---------- 9400 SQL> var emp_recs refcursor; SQL> exec :emp_recs := test_pkg.get_emps(30); PL/SQL procedure successfully completed. SQL> print emp_recs; SAL ---------- 1600 1250 1250 2850 1500 950 6 rows selected. SQL>
-
Uninstall software update Apple says error in seller contact package package unstaller
Try to get itunes working to make a backup of my faulty iphone before repair.
First-itunes does not start says error. I'm trying to fix it, who said success but same error when you try to start it.
Then uninstall completely worked. Then reinstall that seemed to be over except for a message "an older version of Apple software update already exists" then he went down and install itunes apparently had not been completed.
Then I try to remove the update from the apple software and executed by an error in the installation program - it says there is an error in the installation and contact the supplier of the installation package. Same error if I run the uninstall command line program.
Try to repair the Apple Software Update of programs & features Control Panel and then try to update iTunes again.
For general advice, see troubleshooting problems with iTunes for Windows updates.
The steps described in the second case are a guide to remove everything related to iTunes and then rebuild what is often a good starting point, unless the symptoms indicate a more specific approach.
Review the other boxes and other support documents list to the bottom of the page, in case one of them applies.
The more information box has direct links with the current and recent if you have problems to download, must revert to an older version or want to try the version of iTunes for Windows (64-bit - for older video cards) as a workaround for problems with installation or operation, or compatibility with third-party software.
Backups of your library and device should be affected by these measures but there are links to backup and recovery advice there.
TT2
-
I need a refund on a package I bought
I'm not sure on how to request a refund for a package I bought?
Essentially, iTunes purchases are considered final. This is part of the information provided when you make a purchase. However, you can use this link to contact iTunes support and ask. It is to them. https://www.Apple.com/EMEA/support/iTunes/contact.html
-
Content of library photos - necessary Expert Package
I've had my MacBook for about 5 years now and I have an insane amount of Photos stored for the past 14 years, but during that time, my library of Photos being scenes has become a bit of a mess. (I think)
My photo library app itself is very good, but there a total of scatter gun approach to sync my Photos with iTunes (via a cable not iCloud) allows to synchronize some and not others. Now he has decided to not to sync album art by June 2016 for some strange reason.
I think that it has been corrupted and dare I say I have tinkered around with the "package contents" so I need help
What records I should have in the contents of package of Photos? I have the following: -.
Apple TV Photo Cache - I know it's for my Apple TV which is fine
Spare part - no article here
Data - photos contained here, no idea what it is for?
Data.noindex - photos contained here like above?
database
iPhotolock.data
iPod Photo Cache - I know that allows you to synchronize the photos to my iPhone and I deleted before you try and make it work
Masks - no article here
Masters - it's the only place where my original showing in Photos is kept? (14 items)
Plug-Ins - no article here
Previews - curious as to what this is?
Private - no idea what it is for?
ProjectDBversion.plist
Projects.DB
resources - no idea what this? Photos here too
Miniatures - what is - it used to? I had 16 points here, it should not match the masters?
I'd love to get it back to scratch so any ideas and would love someone to answer some of the questions above
You are chasing a dream - you may (0r can't) get the answers to all or part of these but he questions not because you can't fix anything and if you messes with the content library autour probably have corrupted you it
I daresay I could have tinkered around with the "contents of the package.
rather than wasting time on a quest usless you need
1 resolve to stay out of the inside of the library in the future - there is not serviceable by the user
2. now, either restore a working library from before you "tinkered" around
3 - or start over with a new library, then drag each file in master file to the icon in the Dock to import into the new library of Photos
LN
-
Airpod will come in the same package with iPhone 7 in October?
I heard they arrive in October, but they will come with iPhone 7 in the same package? I will be able to choose between Airpod and EarPods?
Hello
No - Airpod are a separate purchase.
EarPods (wired, with lightning connector) are provided with the iPhone 7 and 7 more.
-
When I download itunes on my pc, I get an error of analysis package, any help?
"When I download itunes on my pc I get a parse error in the package, any help?
Hello xlAdrenaline,
Thank you for using communities of Apple Support.
If I understand your message that you receive a packet parse error when you try to install iTunes on your Windows PC. The following article has some great not to help solve this type of problem:
If you see an error message "Windows package install" when you try to uninstall iTunes from your PC
Best regards
Maybe you are looking for
-
I plugged my music system in an Airport Express as a work-around to play the music from Apple through Sonos. Now I can get music Apple app Sonos, and my network is provided by my Time Capsule, Airport Express has all the useful functions or should I
-
acquire data from the oscilloscope DPO2024
I am trying to acquire data from the oscilloscope DPO2024 using labview. I am able to do, but my vi file only works for channel 1. Other than channel 1, it does not work and instead, it changes the adjustment of the oscilloscope as well. Find the vi
-
Limitation of restoration of Windows 2008 R2
I'm trying to restore a folder that contains the folder 13800 inside and each folder contains about 4 files using windows 2008 R2 backup utility, it gave me an error that it can not restore more than 1000 files, can anyone help?
-
I want to know how to put audio books from itunes on my sansa fuse if its effective?
-
You want to do some cosmetic products with a portrait. How a "sample" a small portion of an image can 'paint' or 'spray' this sample on another area? Advice requested