Dynamically Accessing a PL/SQL Table
If I have 2 plsql tables :
vt1_games and vt2_games that I usuallly update with the
following:
vt1_games(vt1_count).team1_num := ......
or
vt2_games(vt2(count).team1_num := ......
How can I use a variable for the plsql table name and pointer?
Thanks,
Paul
In full agreement with Guido's suggestion, i think too, there are not so many choices, one possible solution could be
SQL> create table dept_sal(deptno number,sal number);
Table created.
SQL> declare
2 type emp_r is record(
3 deptno emp.deptno%type,
4 sal emp.sal%type);
5 type emp_t is table of emp_r index by binary_integer;
6 l_emp emp_t;
7 l_dept emp_t;
8 begin
9 -- populate initial collection
10 select deptno, sal bulk collect into l_emp from emp;
11
12 for i in l_emp.first .. l_emp.last loop
13 l_dept(l_emp(i).deptno).deptno :=l_emp(i).deptno;
14 l_dept(l_emp(i).deptno).sal := nvl(l_dept(l_emp(i).deptno).sal,0) + l_emp(i).sal;
15 end loop;
16
17 forall i in indices of l_dept
18 insert into dept_sal values l_dept(i);
19 end;
20 /
PL/SQL procedure successfully completed.
SQL> select * from dept_sal;
DEPTNO SAL
10 8750
20 10875
30 9400In other words, about 20 lines of code to implement
insert into dept_sal select deptno,sum(sal) from emp group by deptno;Best regards
Maxim
Similar Messages
-
Table does not exist (servlet accessing the postgres sql table)
Hello every body,
I am running servlet to access the postgres sql table. But there exist error.
ERROR: relation "employee" does not exist
I have checked the table name in database and table name into the servlet. Both are same. Please give me suggestion to solve this error.
Thankscan you connect to the database without the servlet?
put your stuff into this and try it. If it works, add something to check the table names. - %
package test;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
* Connect to a database using JDBC
public class ConnectionTest
private static final String DEFAULT_DRIVER = "your driver here";
private static final String DEFAULT_URL = "your url here";
private static final String DEFAULT_USERNAME = "your username here";
private static final String DEFAULT_PASSWORD = "your password here";
public static void main(String[] args)
Connection connection = null;
ResultSet rs = null;
try
String driver = ((args.length > 0) ? args[0] : DEFAULT_DRIVER);
Class.forName(driver);
String url = ((args.length > 1) ? args[1] : DEFAULT_URL);
String username = ((args.length > 2) ? args[2] : DEFAULT_USERNAME);
String password = ((args.length > 3) ? args[3] : DEFAULT_PASSWORD);
connection = DriverManager.getConnection(url, username, password);
DatabaseMetaData databaseMetaData = connection.getMetaData();
System.out.println("product: " + databaseMetaData.getDatabaseProductName());
System.out.println("major : " + databaseMetaData.getDatabaseMajorVersion());
System.out.println("minor : " + databaseMetaData.getDatabaseMinorVersion());
System.out.println("schemas");
rs = databaseMetaData.getSchemas();
while (rs.next())
System.out.println(rs.getString(1));
catch (Exception e)
e.printStackTrace();
finally
close(rs);
close(connection);
public static void close(ResultSet resultSet)
try
if (resultSet != null)
resultSet.close();
catch (Exception e)
e.printStackTrace();
public static void close(Statement statement)
try
if (statement != null)
statement.close();
catch (Exception e)
e.printStackTrace();
public static void close(Connection connection)
try
if (connection != null)
connection.close();
catch (Exception e)
e.printStackTrace();
} -
Dynamic number of PL/SQL tables help!!!
Hi,
I have a PL/SQL code in which I am using PL/SQL table of tables.
The number of such tables created in the code can be dynamic.
At the end of the procedure I want to insert the records from those PL/SQL tables into a database table.
Something like this.
insert into DBL.RA_CONTROL_REPORT (time_slot1,time_slot2,time_slot3,time_slot4,time_slot5,time_slot6,time_slot7,
time_slot8,time_slot9,time_slot10,time_slot11,time_slot12,time_slot13,time_slot14,time_slot15,time_slot16,
time_slot17,time_slot18,time_slot19,time_slot20,time_slot21,time_slot22,time_slot23,time_slot24,time_slot25,
time_slot26,time_slot27,time_slot28,time_slot29,time_slot30,time_slot31,time_slot32,time_slot33,time_slot34,
time_slot35,time_slot36,time_slot37,time_slot38,time_slot39,time_slot40,time_slot41,time_slot42,time_slot43
,time_slot44,time_slot45,time_slot46,time_slot47,time_slot48)
values ( Outer_table(1)(i),Outer_table(2)(i),Outer_table(3)(i),Outer_table(4)(i),Outer_table(5)(i)
,Outer_table(6)(i),Outer_table(7)(i),Outer_table(8)(i),Outer_table(9)(i),Outer_table(10)(i),Outer_table(11)(i)
,Outer_table(12)(i),Outer_table(13)(i),Outer_table(14)(i),Outer_table(15)(i),Outer_table(16)(i),Outer_table(17)(i)
,Outer_table(18)(i),Outer_table(19)(i),Outer_table(20)(i),Outer_table(21)(i),Outer_table(22)(i),Outer_table(23)(i)
,Outer_table(24)(i),Outer_table(25)(i),Outer_table(26)(i),Outer_table(27)(i),Outer_table(28)(i),Outer_table(29)(i)
,Outer_table(30)(i),Outer_table(31)(i),Outer_table(32)(i),Outer_table(33)(i),Outer_table(34)(i),Outer_table(35)(i)
,Outer_table(36)(i),Outer_table(37)(i),Outer_table(38)(i),Outer_table(39)(i),Outer_table(40)(i),Outer_table(41)(i)
,Outer_table(42)(i),Outer_table(43)(i),Outer_table(44)(i),Outer_table(45)(i),Outer_table(46)(i),Outer_table(47)(i)
,Outer_table(48)(i));
Here, DBL.RA_CONTROL_REPORT is my database table.
And each Outer_table()() is my PL/SQL table.
I need to make this query dynamic by inserting only from those many number of PL/SQL tales which are created.
Assume that I know the number of PL/SQL tables created.
But when I try to do so, and apply execute immediate to that query. It gives me an error as unimplemented feature.
Sample code where I have tried doing so is as follows:
Query3:='insert into DBL.RA_CONTROL_REPORT (';
for i in 1..max_cnt loop
for idx in 1..Interval_Count loop
col_name :=col_name||'time_slot'||idx||',';
table_name :=table_name||'Outer_table('||idx||')('||i||'),';
end loop;
col_name:=rtrim(col_name,',');
table_name:=rtrim(table_name,',');
Query3:=Query3||col_name||') values('||table_name||')';
dbms_output.put_line(query3);
execute immediate query3;
commit;
end loop;
Where max_cnt -> No of PL/SQL tables created.
Please help.Now using the above approach to determine the bucket for a row, this result can be (outer) joined to the 48 buckets for the day and one can determine whether there are values for that bucket or not.
For example:
SQL> with MV as(
2 select
3 trunc(sysdate)+(dbms_random.value(1,24)/24) as TIME,
4 trunc(dbms_random.value(1,100)) as B
5 from dual
6 connect by level <= 1000
7 ),
8 DATA_BUCKETS as(
9 select
10 time,
11 --// determine the decimal hour
12 (to_number(to_char(time,'hh24'))*60)
13 +to_number(to_char(time,'mi')) as MINUTES,
14 --// use the decimal minute to determine
15 --// which half-hour bucket it goes into
16 trunc( ((to_number(to_char(time,'hh24'))*60)+
17 +to_number(to_char(time,'mi')))
18 /30
19 )+1 as BUCKET,
20 b
21 from mv
22 ),
23 ACTUAL_BUCKETS as(
24 select
25 level as BUCKET
26 from dual
27 connect by level <= 48
28 )
29 select
30 actual_buckets.bucket,
31 sum(b),
32 case --// is there data in the data bucket?
33 when sum(data_buckets.b) is null then 'No'
34 else
35 'Yes'
36 end as BUCKET_HAS_DATA
37 from actual_buckets,
38 data_buckets
39 where actual_buckets.bucket = data_buckets.bucket (+)
40 group by
41 actual_buckets.bucket
42 order by 1
43 /
BUCKET SUM(B) BUCKET_HAS_DATA
1 No
2 No
3 1321 Yes
4 1582 Yes
5 1409 Yes
6 786 Yes
7 1082 Yes
8 1323 Yes
9 998 Yes
10 1462 Yes
11 850 Yes
12 947 Yes
13 1033 Yes
14 1224 Yes
15 655 Yes
16 810 Yes
17 1319 Yes
18 702 Yes
19 994 Yes
20 671 Yes
21 1136 Yes
22 1199 Yes
23 1034 Yes
24 1184 Yes
25 1470 Yes
26 890 Yes
27 1549 Yes
28 740 Yes
29 1229 Yes
30 833 Yes
31 1159 Yes
32 1613 Yes
33 1234 Yes
34 770 Yes
35 1196 Yes
36 1324 Yes
37 1263 Yes
38 1155 Yes
39 785 Yes
40 1130 Yes
41 1286 Yes
42 1056 Yes
43 1462 Yes
44 1032 Yes
45 831 Yes
46 888 Yes
47 806 Yes
48 995 Yes
48 rows selected.
SQL>I leave the pivot of this into a single row with 48 columns for you to research and figure out. I'm also pretty sure that other forum members can provide a lot more elegant examples than what I've done here.
The point is that SQL is a very powerful and very capable data processing language. And if you want to build Oracle solutions that are robust and performant and scalable, then you need to Mamimise Maximise SQL and Minimise PL/SQL*.
In other words - do not use PL/SQL when SQL can do the job better and faster.
Edited by: Billy Verreynne on Sep 16, 2011 9:40 AM -
Hi Friends,
I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
CREATE or REPLACE PROCEDURE test_proc IS
TYPE tP2 is TABLE of varchar2(10); --declared a collection
dt2 tP2 := tP2('a','b','c');
i NUMBER(8);
begin
SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
DBMS_OUTPUT.PUT_LINE('**'||i);
end;
While executing the above procedure, I encountered foll. error:
ERROR at line 1:
ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
ORA-06553: PLS-801: internal error [0]
Can anyone please help me, where the problem is??
Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
Thanks in advance.
Best Regards,
Jay Raval.Thanks Roger for the Update.
It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
If someone have any other idea on this, please do let me know.
Thanks a lot for all help.
Best Regards,
Jay Raval.
You have to define a database type...
create type tP2 is table of varchar2(10)
CREATE OR REPLACE PROCEDURE TEST_PROC
IS
dt2 tP2 := tP2('a','b','c');
i NUMBER(8);
begin
SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
DBMS_OUTPUT.PUT_LINE('**'||i);
end;
This will work.
Roger -
Using PL/SQL Table in Forms
Hi,
I am populating a PL/SQL table by fetching data through a explicit cursor. But when i am accessing the PL/SQL table after population, i am getting a "NO DATA FOUND" error.
I am attaching the Forms local progam units which have the logic.
PACKAGE f_get_bike_makers IS
TYPE prectype_maker_dtls_pll IS RECORD (
country_code ad_bike_maker_details.abmd_country_code%TYPE,
country_name table_values.tvs_description%TYPE,
manu_code ad_bike_maker_details.abmd_manufacturer_code%TYPE,
maker_name ad_bike_maker_details.abmd_maker_name%TYPE,
maker_name_kana ad_bike_maker_details.abmd_maker_name_kana%TYPE,
const_by ad_bike_maker_details.abmd_constructed_by%TYPE,
const_time ad_bike_maker_details.abmd_construction_time%TYPE,
update_by ad_bike_maker_details.abmd_updated_by%TYPE,
update_time ad_bike_maker_details.abmd_updated_time%TYPE
TYPE ptabtype_maker_dtls_pll IS TABLE OF prectype_maker_dtls_pll
INDEX BY BINARY_INTEGER;
FUNCTION f_get_bike_makers_pll RETURN ptabtype_maker_dtls_pll;
END;
PACKAGE BODY f_get_bike_makers IS
FUNCTION f_get_bike_makers_pll
RETURN ptabtype_maker_dtls_pll
IS
CURSOR cur_maker_dtls
IS
SELECT abmd.abmd_country_code,
tvs.tvs_description,
abmd.abmd_manufacturer_code,
abmd.abmd_maker_name,
abmd.abmd_maker_name_kana,
abmd.abmd_constructed_by,
abmd.abmd_construction_time,
abmd.abmd_updated_by,
abmd.abmd_updated_time
FROM ad_bike_maker_details abmd,
table_values tvs
WHERE abmd.abmd_country_code = tvs.tvs_code
AND tvs.tvs_tad_code = 'COUNTRIES'
ORDER BY abmd.abmd_country_code;
ln_tab_index BINARY_INTEGER := 0;
ltab_maker_dtls ptabtype_maker_dtls_pll;
BEGIN
FOR lcur_maker_dtls IN cur_maker_dtls
LOOP
ln_tab_index := ln_tab_index + 1;
ltab_maker_dtls (ln_tab_index) := lcur_maker_dtls;
END LOOP;
RETURN ltab_maker_dtls;
END f_get_bike_makers_pll;
END;
PROCEDURE f_populate_maker_names
IS
ltab_maker_dtls f_get_bike_makers.ptabtype_maker_dtls_pll;
lb_record_group BOOLEAN;
ln_ltab_maker_dtls_index BINARY_INTEGER;
BEGIN
-- read all the vehicle types from table_values
-- get makers and countries
ltab_maker_dtls := f_get_bike_makers.f_get_bike_makers_pll ;
DELETE_GROUP_ROW ('REC_MAKER_NAME', all_rows);
ln_ltab_maker_dtls_index := ltab_maker_dtls.FIRST;
begin
WHILE ln_ltab_maker_dtls_index IS NOT NULL
LOOP
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_MANUFACTURER_CODE',
ltab_maker_dtls (ln_ltab_maker_dtls_index).manu_code,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_MAKER_NAME',
ltab_maker_dtls (ln_ltab_maker_dtls_index).maker_name,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'COUNTRY_NAME',
ltab_maker_dtls (ln_ltab_maker_dtls_index).country_name,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_COUNTRY_CODE',
ltab_maker_dtls (ln_ltab_maker_dtls_index).country_code,
ln_ltab_maker_dtls_index
ln_ltab_maker_dtls_index := ltab_maker_dtls.NEXT (ln_ltab_maker_dtls_index);
end;
END LOOP;
exception when no_data_found then
message('ln_ltab_maker_dtls_index :'||ln_ltab_maker_dtls_index);
message(' ');
end;
ltab_maker_dtls.DELETE;
END;
SQL> desc ad_bike_maker_details
Name Null? Type
ABMD_COUNTRY_CODE NOT NULL VARCHAR2(2)
ABMD_MANUFACTURER_CODE NOT NULL VARCHAR2(2)
ABMD_MAKER_NAME VARCHAR2(60)
ABMD_MAKER_NAME_KANA VARCHAR2(60)
ABMD_CONSTRUCTED_BY NOT NULL VARCHAR2(20)
ABMD_CONSTRUCTION_TIME NOT NULL DATE
ABMD_UPDATED_BY VARCHAR2(20)
ABMD_UPDATED_TIME DATE
SQL> desc table_values
Name Null? Type
TVS_TAD_CODE NOT NULL VARCHAR2(15)
TVS_CODE NOT NULL VARCHAR2(15)
TVS_DESCRIPTION NOT NULL VARCHAR2(70)
Oracle Database Version
=======================
Oracle8 Enterprise Edition Release 8.0.6.1.0 - Production
PL/SQL Release 8.0.6.1.0 - Production
Forms Version
==============
Forms [32 Bit] Version 5.0.6.8.0 (Production)
PL/SQL Version 2.3.4.0.0 (Production)
Please do let know what could be the possible source of error.
Thanks in advance.
NitinBut we have to use the PL/SQL table as per our design standards.
We are implementing the population logic of the PL/SQL table in the database as a
package function. We are then accessing the PL/SQL table in Forms to populate the record group.It is curious that you would have such a unique requirement -- something that might make forms run a tiny bit faster -- yet you are using an ancient version of Forms.
Also the "NO DATA FOUND" error is not raised everytime the PL/SQL table is accessed.
What could be the reason for this erratic behaviour?I wonder if there may be a bug in SQL Net in the Oracle-to-Forms communication where PL/SQL tables are passed as out parameters. I know there is one in Web Forms 6 (6.0.8.19.1) when passing a pl/sql table from the form to Oracle -- I had to write the pl/sql table to a database table to get my process to work. -
Oracle datalinks to update a MS SQL table
I am accessing a MS SQL table thru an Oracle procedure. Reads with no problems. When I try and update a column (2 columns affected one is a int and the other is datetime) receive the following error:
ORA-02070: database IWSCIV does not support || in this context
Sql Statements tried are
UPDATE iwPhotoProcessed@IWSCIV
SET "Status" = 1
where "BKno" = '1' || v_app_id;
UPDATE iwPhotoProcessed@IWSCIV
SET "Status" = 1, CompletedDate='04/05/2008 09:14:15 AM'
where "BKno" = '1' || v_app_id;
The above command (minus the @IWSCIV) works fine in MS SQL and updates rows.1) I would generally suggest avoiding string literals when doing UPDATE statements in general, but particularly in the case of updates across Heterogeneous Connectivity database links.
2) I would generally write something like this (assuming "BKno" is declared as a string)
DECLARE
l_new_status NUMBER := 1;
l_app_id VARCHAR2(10) := '1' || v_app_id;
BEGIN
UPDATE iwPhototProcessed@IWSCIV
SET "Status" = l_new_status
WHERE "Bkno" = l_app_id;
END;Justin -
Oracle Pl/Sql table question..
Hi guys,
I have an Oracle PL/SQL question. I don't
know which board can i ask it. This is why
i am asking here.
I declare a PL/SQL table(traditional array),
and populate it in a session. Another user logged on with another session and wanted to access this PL/SQL table data, But He/she received "No Data Found".
Is the PL/SQL table session scope?
Pl/Sql table declared in Package Spec
and the procedures to populate and
access the data in/from this Pl/Sql table
are coded in package body.
Thanks...Ali
nullHi guys,
I have an Oracle PL/SQL question. I don't
know which board can i ask it. This is why
i am asking here.
I declare a PL/SQL table(traditional array),
and populate it in a session. Another user logged on with another session and wanted to access this PL/SQL table data, But He/she received "No Data Found".
Is the PL/SQL table session scope?
Pl/Sql table declared in Package Spec
and the procedures to populate and
access the data in/from this Pl/Sql table
are coded in package body.
Thanks...Ali
null -
Accessing PL/SQL table in SQL query
Hello,
Is it possible to use plain SQL to query PL/SQL table? In my case this table is returned by UTL_HTTP.REQUEST_PIECES function, which is defined as:
create or replace package utl_http is
type html_pieces is table of varchar2(2000) index by binary_integer;
function request_pieces (url in varchar2,
max_pieces natural default 32767)
return html_pieces;
pragma restrict_references (request_pieces, wnds, rnds, wnps, rnps);
Generally, I want to access chunks of external data for comparison without using PL/SQL. Thanks ahead for ideas. Ideally, I need working example because my attempts to use TABLE & CAST failed.I was going to suggest you could try and create your own wrapper around utl_http and use a database type, but then I remembered this excellent thread which covers it better than I ever could - Billy, hope you don't mind passing on your good work!
Re: Error using UTL_HTTP over HTTPS -
How to fetch the data from pl/sql table dynamically
Hi All, I have the requirement of comparing two db views data in pl/sql. So, I have bulk collect the view into pl/sql table. But, the issue is, It is expecting to provide the column name for comparison. But, in my case, column name is dynamic. So, i cannot provide the column name directly for comparison.
For eg: In my view t1_VW, i have 4 columns. stid, c1,c2,c3,c4 and similar structure for t2_vw
my code
TYPE v1_type IS TABLE OF t1_vw%ROWTYPE;
l_data v1_type;
TYPE v1_type1 IS TABLE OF t2_vw%ROWTYPE;
l_data1 v1_type1;
test varchar2(1000);
test1 varchar2(1000);
temp1 number;
begin
SELECT * Bulk collect into l_data
FROM T1_VW;
SELECT * Bulk collect into l_data1
FROM T2_VW;
select l_data(1).stid into temp1 from dual; -- It is working fine and gives me the value properly
-- But, in my case, we are reading the column names from array, i am constructing the query dynamically and execute it.
test :='select l_data(1).stid into temp1 from dual';
execute immediate test into temp1;
-- I am getting error as follows:
Error report:
ORA-00904: "L_DATA": invalid identifier
ORA-06512: at "SYSTEM.BULKCOMPARISON", line 93
ORA-06512: at line 2
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action
end;
- Please help me to get rid of this issue. Is it possible to construct the query dynamically and fetch the data?. If not, is there any other better approach to compare the data between two views?.Output should display what are all columns changed and its old value and new value.
For eg., output should be
COLUMNNAME OLD_VALUE NEW_VALUE STID
C1 20 10 1
C2 50 40 2
C3 60 70 2
C2 80 90 3Why no do this only via a simple sql ?
create table a (STID number, C1 number, C2 number, C3 number);
insert into a values (1, 20, 30, 40)
insert into a values (2, 40, 50, 60);
insert into a values (3, 90, 80, 100);
create table b as select *
from a where 1 = 0;
insert into b values (1, 10, 30, 40)
insert into b values (2, 40, 40, 70);
insert into b values (3, 90, 90, 100);
commit;And now you can issue such a kind of select
SELECT stid , c1, c2, c3
FROM
( SELECT a.*,
1 src1,
to_number(null) src2
FROM a
UNION ALL
SELECT b.*,
to_number(null) src1,
2 src2
FROM b
GROUP BY stid , c1, c2, c3
HAVING count(src1) <> count(src2)
order by stid;I would then create a new table a_b_difference having the same structure as a or b and insert into it like this
create table a_b_diff as select * from a where 1 = 0;
insert into a_b_diff
SELECT stid , c1, c2, c3
FROM
( SELECT a.*,
1 src1,
to_number(null) src2
FROM a
UNION ALL
SELECT b.*,
to_number(null) src1,
2 src2
FROM b
GROUP BY stid , c1, c2, c3
HAVING count(src1) <> count(src2)
order by stid
;Then each time there is a difference between a column in a and its equivalente one in b (per unique stid ) a record will be inserted in this table.
You can do more by adding the name of the table in front of each record in this table to see exactly where the data comes from
Best Regards
Mohamed Houri -
Report cannot access pl/sql table variable defined in Package Spec.
Hi,
I've created a package spec called pkg_report with a PL/SQL table variable defined called body_text_table. When I tried to compile the following code under the Before Report trigger:
:desc := pkg_report.body_text_table(1);
Oracle gave me the following error:
Implementation Restriction: 'PKG_REPORT.BODY_TEXT_TABLE': Cannot directly access remote package variable or cursor.
Does anyone have any idea about this error? Thank you for your time at looking at it.
Regards,
JohnYou cannot directly access the package variable in a database package. The work around is to create a set_variable and get_variable wrapper function in the package body. See Metalink note 105838.1 for more info.
A simple example:
create or replace package my_package as
my_var number;
function get_variable return number ;
procedure set_variable (p_value in number) ;
end ;
create or replace package body my_package as
function get_variable return number is
begin
return my_var;
end ;
procedure set_variable(p_value in number) is
begin
my_var := p_value ;
end ;
end; -
Hi All,
I am using Oracle 8i. I have created a dynamic PL/SQL table in my procedure. Now i need to select rows and sort the data in that PL/SQL table. How do i do it? I
I appreciate any help on this.
Thanks,
VijiSQL> select count(1) from emp;
COUNT(1)
14
SQL> create or replace type emp_row is OBJECT
2 (
3 EMPNO NUMBER(4),
4 ENAME VARCHAR2(10),
5 JOB VARCHAR2(9),
6 MGR NUMBER(4),
7 HIREDATE DATE,
8 SAL NUMBER(7,2),
9 COMM NUMBER(7,2),
10 DEPTNO NUMBER(2)
11* )
SQL> /
Type created.
SQL> set serveroutput on
SQL> declare type emp_table is table of emp_row index by binary_integer;
2 plsql_tab emp_table;
3 rec_num number;
4 begin
5 select emp_row(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
6 BULK COLLECT into plsql_tab
7 from scott.emp;
8 select count(1) into rec_num
9 from scott.emp;
10 DBMS_OUTPUT.PUT_LINE(rec_num||' records in SCOTT.EMP');
11 DBMS_OUTPUT.PUT_LINE(plsql_tab.count||' records in plsql_table');
12 end;
13 /
14 records in SCOTT.EMP
14 records in plsql_table
PL/SQL procedure successfully completed. -
Function returning pl/sql table of dynamic structure
Hi,
I use oracle11g/windows platform.
I have a requirement to be coded like this:
A function to return pl/sql table(cant use ref cursor) whose columns varies everytime it runs i.e.,
means
type pl_tab_type is object(col1 varchar2(1000), col2 varchar2(1000))
type pl_tab is table of pl_tab_type
func f return pl_tab
as
end;
note : pl_tab_type will vary for each run of function f
i.e.,for example, pl_tab_type can be changd to as follows:
type pl_tab_type is object(col1 varchar2(1000), col2 varchar2(1000),col3 varchar2(1000))
how to return pl/sql table of dynamic type from func, thanks for help in advance.WRONG FORUM!
Please mark this question ANSWERED and repost it in the SQL and PL/SQL forum.
PL/SQL -
Dynamically fetaching data into PL/SQL tables help
Hi,
I am develioping a PL/SQL procedure in which I am creatig 24 PL/SQL tables of the same type.
But while inserting data in them I need to use the table names dynamically i.e., the Execute immediate used to put the data into the tables would remain same just I need that for each and every run of for loop for that Execute immediate statement, it should use different table name.
Please see sample code below:
col_name varchar2(20);
Type RA_TABLE is table of CALL_DETAIL_EXCEPTION.IC_CIRCT_GR_CD%TYPE
index by binary_integer;
MY_RA1 RA_TABLE;
MY_RA2 RA_TABLE;
MY_RA3 RA_TABLE;
MY_RA4 RA_TABLE;
BEGIN
for idx in 1..cnt_interval Loop
Col_name := 'MY_RA'||idx;
query1:='select Trunk_info bulk collect INTO MY_RA'|| idx ||' from dbl.vw_cgi v where not exists (select 1 from dbl.varun f
where f.ic_circt_gr_cd= v.TRUNK_INFO and f.call_gmt_dnect_dt_time between
to_date('''||stime||''',''yyyymmddhh24miss'') and to_date('''||etime||''',''yyyymmddhh24miss''))';
Now when I execute this code, it gives me an error for query1 saying that it is unimplemented feature in Oracle.
It is not able to pick up that dynamic table name.
Please help!user9315951 wrote:
I am develioping a PL/SQL procedure in which I am creatig 24 PL/SQL tables of the same type.All wrong. This is NOT how one treats data in PL/SQL.
There is NO such concept as PL/SQL "+tables+". You are in fact defining associative arrays and not using these as associative arrays, but as normal arrays. Your code can consume vast amounts of server memory as private process memory. Your code CAN crash the Oracle database server (yes, I have seen this multiple times - even in production).
Your code is flawed. Your approach is flawed.
I suggest that you take several steps back, gain some understanding of fundamental Oracle concepts, about what does scale and perform in PL/SQL and SQL, and then apply these concepts and principles. -
Hi
How do you access sql table to get data reflected in planning forms (apart from the HAL or via API) , Here we are using Planning 9.3.1. Is there any other way to access data.
regards
M.VYou load data into the underlying Essbase database, so you can use the native capabilities there.
Those include a SQL Interface tool that allows you to pull directly from relational tables/schemas using standard SQL statements via Essbase load rules. The next stage up from this is to use the Integration Services (EIS) toolset that enables you to create complex integrations via models and use these to push data into Essbase.
Hope this helps
Andy King
www.analitica.co.uk -
Hello everyone,
I’ve been assigned one requirement wherein I would like to read around 50 CSV files from a specified folder.
In step 1 I would like to create schema for this files, meaning take the CSV file one by one and create SQL table for it, if it does not exist at destination.
In step 2 I would like to append the data of these 50 CSV files into respective table.
In step 3 I would like to purge data older than a given date.
Please note, the data in these CSV files would be very bulky, I would like to know the best way to insert bulky data into SQL table.
Also, in some of the CSV files, there will be 4 rows at the top of the file which have the header details/header rows.
According to my knowledge I would be asked to implement this on SSIS 2008 but I’m not 100% sure for it.
So, please feel free to provide multiple approaches if we can achieve these requirements elegantly in newer versions like SSIS 2012.
Any help would be much appreciated.
Thanks,
Ankit
Thanks, <b>Ankit Shah</b> <hr> Inkey Solutions, India. <hr> Microsoft Certified Business Management Solutions Professionals <hr> http://ankit.inkeysolutions.comHello Harry and Aamir,
Thank you for the responses.
@Aamir, thank you for sharing the link, yes I'm going to use Script task to read header columns of CSV files, preparing one SSIS variable which will be having SQL script to create the required table with if exists condition inside script task itself.
I will be having "Execute SQL task" following the script task. And this will create the actual table for a CSV.
Both these components will be inside a for each loop container and execute all 50 CSV files one by one.
Some points to be clarified,
1. In the bunch of these 50 CSV files there will be some exception for which we first need to purge the tables and then insert the data. Meaning for 2 files out of 50, we need to first clean the tables and then perform data insert, while for the rest 48
files, they should be appended on daily basis.
Can you please advise what is the best way to achieve this requirement? Where should we configure such exceptional cases for the package?
2. For some of the CSV files we would be having more than one file with the same name. Like out of 50 the 2nd file is divided into 10 different CSV files. so in total we're having 60 files wherein the 10 out of 60 have repeated file names. How can we manage
this criteria within the same loop, do we need to do one more for each looping inside the parent one, what is the best way to achieve this requirement?
3. There will be another package, which will be used to purge data for the SQL tables. Meaning unlike the above package, this package will not run on daily basis. At some point we would like these 50 tables to be purged with older than criteria, say remove
data older than 1st Jan 2015. what is the best way to achieve this requirement?
Please know, I'm very new in SSIS world and would like to develop these packages for client using best package development practices.
Any help would be greatly appreciated.
Thanks, <b>Ankit Shah</b> <hr> Inkey Solutions, India. <hr> Microsoft Certified Business Management Solutions Professionals <hr> http://ankit.inkeysolutions.com
1. In the bunch of these 50 CSV files there will be some exception for which we first need to purge the tables and then insert the data. Meaning for 2 files out of 50, we need to first clean the tables and then perform
data insert, while for the rest 48 files, they should be appended on daily basis.
Can you please advise what is the best way to achieve this requirement? Where should we configure such exceptional cases for the package?
How can you identify these files? Is it based on file name or are there some info in the file which indicates
that it required a purge? If yes you can pick this information during file name or file data parsing step and set a boolean variable. Then in control flow have a conditional precedence constraint which will check the boolean variable and if set it will execute
a execte sql task to do the purge (you can use TRUNCATE TABLE or DELETE FROM TableName statements)
2. For some of the CSV files we would be having more than one file with the same name. Like out of 50 the 2nd file is divided into 10 different CSV files. so in total we're having 60 files wherein the 10 out of 60 have
repeated file names. How can we manage this criteria within the same loop, do we need to do one more for each looping inside the parent one, what is the best way to achieve this requirement?
The best way to achieve this is to append a sequential value to filename (may be timestamp) and then process
them in sequence. This can be done prior to main loop so that you can use same loop to process these duplicate filenames also. The best thing would be to use file creation date attribute value so that it gets processed in the right sequence. You can use a
script task to get this for each file as below
http://microsoft-ssis.blogspot.com/2011/03/get-file-properties-with-ssis.html
3. There will be another package, which will be used to purge data for the SQL tables. Meaning unlike the above package, this package will not run on daily basis. At some point we would like these 50 tables to be purged
with older than criteria, say remove data older than 1st Jan 2015. what is the best way to achieve this requirement?
You can use a SQL script for this. Just call a sql procedure
with a single parameter called @Date and then write logic like below
CREATE PROC PurgeTableData
@CutOffDate datetime
AS
DELETE FROM Table1 WHERE DateField < @CutOffDate;
DELETE FROM Table2 WHERE DateField < @CutOffDate;
DELETE FROM Table3 WHERE DateField < @CutOffDate;
GO
@CutOffDate which denote date from which older data have to be purged
You can then schedule this SP in a sql agent job to get executed based on your required frequency
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Maybe you are looking for
-
Error while connecting to SQL Server 2000 using Heteregenous Services 11g
Hope this is the right thread to post on! We have been given the challenge of connecting to and reading data from a SQL Server 2000 database. Our Infrastructure guys have set up the network access. The SQL Server DB is set to windows NT Authenticatio
-
DTW Error on A/R Credit Memos
Hello guys! I got a problem while trying to upload A/R Credit Memos through Data Transfer Workbench. It shows an error message inthe DTW Error Log: "Cannot add invoice with zero total and deferred tax ORIN.DocTotalApplication-Defined or Object-Defin
-
Scanner error 22 with HP Laserjet M1210 MFP
Hello - I have an HP Laserjet M1210 MFP (fax, printer and scanner all in one) that has been working until yesterday. Now I am getting an error message "Scanner Error 22". I have tried to unpulg and replug the machine after a few minutues multiple t
-
Organizer applications (project management and to do's)
I'm looking for an application that will let me organize and edit my "important, to do's, passwords, financial" etc, etc documents (now in pages or word). Ideally I need these on my iPhone and my laptop. I'm really hoping for something that I can /im
-
[7Pro] [Acro Pro XI] After Started Acro Pro XI, AcrobatPro XI quit without message after 20 secondes Hi All, See the resume in the title.. [7Pro - 32Bits] [Acro Pro XI] After first Started Acro Pro XI with last Update v11.0.9 (no PDF files opened.. j