PL/SQL :: Creating Collection And Joining List To Database Table?

Jul 31, 2012

based on a provided list of key values, joining the collected list against a source table to retrieve additional information related to the key. In this simple example, the procedure accepts a list of employee numbers. The goal is to print a list of names associated with those numbers.

The method is to materialize the list of employee numbers as rows and join those rows to a source table to get the names. I have used BULK COLLECT. Why we cannot cast PLSQL tables using a type defined in the procedure's specification (why the type needs to exist as an object before we can cast it, like this:

SELECT * FROM TABLE ( CAST ( SOME_FUNCTION(&some parameter) AS SOME_TYPE ) );

here is my demo SQL, which you should be able to execute against the SCOTT schema without any change

declare
type employee_numbers is table of emp.empno%type index by binary_integer;
type employee_names is table of emp.ename%type index by binary_integer;
type employees_record is record (empno employee_numbers, person_name employee_names);
records employees_record;

[code]...

View 12 Replies


ADVERTISEMENT

SQL & PL/SQL :: Creating PLSQL Collection Table Type With Dynamic Query?

Jul 12, 2013

How can I create PLSQL table type dynamically?

I will have to take the Employee Names and create a table structure. Number of employee names can vary from day to day. So, whenever I execute my procedure with Table type, I will have to build the table columns with the employee names.

View 2 Replies View Related

SQL & PL/SQL :: Creating List Of Month From Dual Table?

Nov 3, 2011

creating sql query for producing result as per below from dual table.

SELECT to_char( sysdate,'MON-RRRR')
FROM dual
where sysdate between '01-APR-2011' and '31-MAR-2012'
order by 1 desc

from above query the result is

NOV-2011

but i need the result as per below

APR-2011
MAY-2011
JUN-2011
JUL-2011
AUG-2011
SEP-2011
OCT-2011
NOV-2011 CURRENT MONTH

View 4 Replies View Related

PL/SQL :: Joining The Same Table Twice

Oct 14, 2013

Shouldn't they produce the same output? 

SELECT c1.c_no, c1.c_name, c1.city
FROM customers c1 LEFT OUTER JOIN customers c2 ON (c1.city = c2.city AND c1.c_name<>c2.c_name); SELECT c1.c_no, c1.c_name, c1.city
FROM customers c1 RIGHT OUTER JOIN customers c2 ON (c1.city = c2.city AND c1.c_name<>c2.c_name);

View 8 Replies View Related

PL/SQL :: Joining Order Table With Asset Or CX_ACTION Table?

Apr 18, 2013

joining the Order table with the Asset table or the Order table with CX_ACTION table to Can i get reference on this .

select x.x_msisdn,
x.x_product_name,
x.x_action,
x.x_status_outcome,
a.recovered_dt,
x.x_amount,

[code].....

View 1 Replies View Related

Joining Two Columns In Same Table?

Jan 30, 2007

We have a table for reports. If user A submits a report ...and say the sequence # is 242. When this report goes to Admin ...he submits this request then in same table we add another row with say sequence # 245. THEN we update column called 'Asctd ID' for 242 and add 245 in there. and then update Asctd ID for 245 and add 242 in there.

(This table has many fields, one of which is report Name field)

Now i am running a query like this...

SELECT b.JOB_ID, a.DESC, TO_CHAR(a.CREATE_DATE,'MM/DD/YYYY'),
DECODE(a.DLVRY_TYPE,'','PDF',a.DLVRY_TYPE), DECODE(a.FLG,'','N/A',
a.FLG), ((TO_DATE(a.CREATE_DATE,'DD-MON-YY')) + 21) -
TO_DATE(SYSDATE, 'DD-MON-YY'), c.STATUS_DESC, a.SIZE_NUM,
b.PRVDR_ID, a.asctd_id, d.NM
FROM REQUEST_DIM a, PROVIDER_DIM b, STATUS_DIM c, DIM d
WHERE a.FLAG = 'P' and RTRIM(a.RPT_RQST_USER_ID) = 'TEST02' AND a.RPT_RQST_TYPE = 'D'
AND a.RPT_RQST_ACTIVE_IND = 'A' and a.asctd_id is not null and a.RPT_RQST_ID = b.RPT_RQST_ID
and b.JOB_ID = c.JOB_ID and b.PRVDR_ID = d.PRVDR_ID
AND c.CREATE_DT = (SELECT MAX(d.CREATE_DT)
FROM STATUS_DIM d
WHERE d.RPT_RQST_ID = b.RPT_RQST_ID and d.JOB_ID = b.JOB_ID )
ORDER BY a.RPT_RQST_ID, a.CREATE_DATE

Now this query is run by the admin (job 245) ...it returns a bunch of stuff and also the name of the report that the admin gave this. But when admin sees this we want to be able to displace the report name that user A gave it (asctd ID 242). so the row 245 HAS a asctd ID 242. and there is a row 242 from which we can get the name easily. But i dont know if this is possible in ONE QUERY??

View 2 Replies View Related

Joining 2 Table Together In Oracle?

Jan 7, 2013

Basically, i was asked to join Table 1 and Table 2 together in oracle. I have been given the values of Table 1. For example, Depot_ID has value of DEP01, DEP02, DEP02 etc. Therefore, I have to create table 2 with those attributes given below. But the attribute name of the Table 2 is Depot_No which is different.

My question: Is it correct to give the same values of Depot_ID in Table 1 to Depot_No in Table 2, such as, DEP01, DEP02, DEP02?

How to join those two tables below:

Table 1:

Depot_ID
Address
Location

Table 2:

Product_ID
Depot_No
Quantity
Aisle
Bay

View 2 Replies View Related

SQL & PL/SQL :: Joining Subsequent Rows In A Table

Mar 29, 2010

I create a second "DATE_PAIRS" table, and join a few subqueries. It works with conditions (ID=1), but scanning the whole table (2+ million records) is abysmal.

Table:
ID Date Price
---------------------
1 2010/1/1 100
1 2010/1/2 125
1 2010/1/5 115
2 2010/1/1 115
2 2010/1/2 105
2 2010/1/5 125

I'd like to return

ID Date1 Date2 Price1 Price2
--------------------------------
1 2010/1/1 2010/1/2 100 125
1 2010/1/2 2010/1/5 125 115

etc ..

View 11 Replies View Related

SQL & PL/SQL :: Joining One Row To Multiple Rows In Same Table?

Feb 8, 2011

I have two tables. The first contains all Segment information within Oracle i.e;

Table 1
Segment Description Flex_Value
1 North 1234
1 South 1235
1 East 1236
2 Car C001
2 Boat B001

and the second table contains financial data, but only the segment code;

Table 2
Date Segment1 Segment2 Value
01/01/11 1234 C001 10,000
02/01/11 1235 C001 10,000

what I want to return is some of the columns within table two as well as additional columns for the segment descriptions.

Below is an extract of what I have put together, and it does return what I need, but I'm sure there is a much more efficient way of creating the query;

SELECT

b.DATE,
b.SEGMENT1,
b.SEGMENT2,
b.SEGMENT3,
b.SEGMENT4,
b.SEGMENT5,

[code].....

View 6 Replies View Related

PL/SQL :: Creating A List Of Dates And Hours

Jul 24, 2013

I have the following code which will produce a list of dates - 

SELECT to_date('01-Jan-2013','DD-Mon-YYYY') + rownum - 1
FROM     all_objectsWHERE   rownum <= to_date('31-Jan-2013','DD-Mon-YYYY') - to_date('01-Jan-2013','DD-Mon-YYYY') + 1 01/01/201302/01/201303/01/201304/01/2013.....30/01/201331/01/2013

 But what I'm looking for is a way to also include all possible hours with the dates, so my output would be like -

 01/01/2013 0001/01/2013 0101/01/2013 0201/01/2013 03...31/01/2013 2131/01/2013 2231/01/2013 23

View 5 Replies View Related

Retrieving Info From Database And List Out In HTML Table?

Feb 21, 2011

I am having a little trouble retrieving info from my mock database.

here are my definitions:
response.setHeader("pragma", "no-cache");
response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
response.setHeader("Expires", "01 Apr 1995 01:10:10 GMT");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");

[code]...

and here is my select statement.
ds = (DataSource) context.lookup(dSource);
conn = ds.getConnection();
stmt = conn.prepareStatement("select add_date, campus, name, leader from TABLENAME where id = ? order by xbbo_add_date");
stmt.setString(1, colleagueID);
result = stmt.executeQuery();

***basically I am trying to retrieve this info from my db, and list it out in a HTML table. I am writing this on a JSP page. Also, where i want the retrieved data listed, I am using for ex: <%=name%>

View 5 Replies View Related

Forms :: Creating List Item With Time?

Jul 9, 2013

Oracle Developer Suite 10g

I want to create List item with time .

like in pic when I click on upper side at list item increase time and other side decrease time.

View 1 Replies View Related

Creating List Of Items And Using Foreign Keys As Primary

May 19, 2007

How can I create a list of items in a field, for instance lets say I have a table called car and one of the sub categories is parts. How can I make it so that parts can be any number of pre-defined entities? Or even table, for instance if I make a table called parts how can I use that in the car table in place of parts?

My second question is about using foreign keys as primary keys. If I am writing an email sql DB and I decided to use the members usrname as the primary key in the member table but then made another table that lists all the emails and decided to make the foreign key member username the primary key there.

Is that safe to do or should i create a sequence in which to identify a primary key for the email list table? Also what if I extend member to several other tables and use it as a primary key there too, seems like a kind of dangerous way to do things...

View 1 Replies View Related

10.2.0.4.0 Two Node RAC - Collection Cause Database Performance To Go Down In AWR?

Jul 16, 2012

we had an issue with our 10.2.0.4.0 two node RAC Database where when running stats collection caused the database performance to go down and in AWR I noticed the following:

Top 5 Timed Events
Event Waits Time(s) Avg Wait(ms) % Total Call Time Wait Class
gc buffer busy 95,077 73,786 776 76.0 Cluster
cursor: pin S wait on X 3,524,808 54,467 15 56.1 Concurrency
library cache lock 30,223 13,660 452 14.1 Concurrency
gc cr request 2,876 3,594 1,250 3.7 Cluster
library cache pin 1,740 1,800 1,035 1.9 Concurrency

when looked under Library Cache Activity section in the AWR report, I see the following:

Namespace Get Requests Pct Miss Pin Requests Pct Miss Reloads Invali- dations
BODY 59 3.39 3,056 0.13 1 0
CLUSTER 70 0.00 73 0.00 0 0
INDEX 178 0.00 925 0.00 0 0
SQL AREA 423,064 50.25 2,465,209 2.37 182 119,671
TABLE/PROCEDURE 1,848 21.27 22,638 0.62 70 0
TRIGGER 14 0.00 1,801 0.06 1 0

does this mean, we are having memory crunch for this instance on node 1? we have sga_target=26gb and sga_max_size=32gb set for this instance.

View 2 Replies View Related

SQL & PL/SQL :: Table Variable Or Collection

Jul 11, 2012

Is there any table except (global temp table and permanent table) which can be used to store data and be used in inner, left and right join for a session.

View 7 Replies View Related

SQL & PL/SQL :: Sorting Collection In Nested Table

Sep 11, 2012

I'm trying to sort a collection in a nested table in PL/SQL so these value can be used later for a display and for export to Excel. The sort is failing.

-- PLS-00642: local collection not allowed in SQL statements

-- PL/SQl: ORA-00902: invalid datatype

The error message are also noted below in the code on the line that fails.

A quick overview of this code- Using a nested table MyNestedTable the values from several select queries are combined into MyRecordsetZero using CURSOR, and MULTISET UNION. I'm trying to either sort MyRecordsetZero or populate MyRecordsetSorted with the sorted values for futher use.

IMPORTANT: The code is running in an enviroment that does not have permission to create.

Versions:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Developer: 8.0.0.1480

DECLARE
-- Declare the variable MyTID to be used by select statements and
-- set its data type and max character count
MyTID varchar2(10);
[code]....

View 13 Replies View Related

SQL & PL/SQL :: Sorting Nested Table / Collection

Nov 10, 2011

In test.pks file I declared the following type

TYPE tab_tests is table of NUMBER(15);

In test.pkb, I have the following procedure

PROCEDURE report (
i_cid IN NUMBER
)
IS
test1 tab_tests := tab_tests();
test2 tab_tests;
BEGIN

-- I populate test1 with the data and it works fine. But when I tried to make a sorted nested table with the following command.

I got this error 'ORA-00902: invalid datatype',

a nested table than the following, like a built in Oracle collection method?

execute immediate 'select cast( multiset (select * from table(test1) order by 1) as tab_tests) INTO test2 FROM dual';
END;

View 16 Replies View Related

SQL & PL/SQL :: Replace Temp Table With Collection?

Nov 4, 2011

how I can replace gtt in the following procedure with an Oracle Collection?

gtt or Collection is more efficient?
PROCEDURE report_gen (
i_table IN NUMBER
)
IS
BEGIN
create global temporary table test_gtt (tid NUMBER(15));

[code].....

View 6 Replies View Related

SQL & PL/SQL :: Use Collection In Select Statement As Table?

May 26, 2011

i'm trying to use a collection in a select statement as a table, but i've got an error which i don't understand.

This exemple is very simple. I'm trying to validate the solution. The object will contain the result of a query from a big table, and i have 4 request to make on it. I don't want to select 4 times the big table to get the result, but i need the whole result to make my requests (intersect, minus and union)

CREATE OR REPLACE
TYPE zy_w AS OBJECT(
CODE_INFORMATIONVARCHAR2(4),

[Code]....

****************
Rapport d'erreur :
ORA-06550: Ligne 12, colonne 3 :
PL/SQL: ORA-00947: nombre de valeurs insuffisant
ORA-06550: Ligne 5, colonne 3 :
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:
%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

View 9 Replies View Related

SQL & PL/SQL :: Collection Data - Get All Records From Table?

Nov 5, 2012

CREATE TABLE table_a(f_table_type_id NUMBER, f_bet_amount NUMBER, f_win_amount NUMBER);
CREATE TABLE table_b(f_table_type_id NUMBER, f_bet_amount NUMBER, f_win_amount NUMBER);
CREATE TABLE table_c(f_table_type_id NUMBER, f_bet_amount NUMBER, f_win_amount NUMBER);
INSERT INTO table_c VALUES(3,100,100);

[code]...

for each of the is which I get in v_ids, if there are records in a,b,c then I should get all those records, but the above loop is not working.

My final result should be LIKE :
f_table_type_id f_bet_amount f_win_amount
1 200 200
2 100 100
3 100 100

View 7 Replies View Related

SQL & PL/SQL :: Use A Select Statement On Collection Table?

Sep 1, 2011

there is a possible to use a select statement on collection table?

View 1 Replies View Related

Application Express :: Automatic Update Of Collection And Table?

Oct 29, 2013

I am trying to update a collection and a table.I got some example code and installed on oracle.com, but I just can't seem to get it to work.I always get an errorORA-20001: Current version of data in database has changed since user initiated update process.I think the problem lies with comparing the checksums, but I cannot spot the mistake 

View 2 Replies View Related

SQL & PL/SQL :: Oracle Query Joining A Table With Existing Query?

Jun 19, 2012

I have the following four tables with the following structures Table A

ColA1 ColA2 ColA3 ColA4 ColA5 AA 100 CC DD EE

Table B

ColB1 ColB2 ColB3 ColB4 ColB5 AA 100 40452 A9 CDE

when these two tables were joined like the following:

Select colA1,ColA2, ColA3, ColA4, ColB3,ColB4, ColB5 from table A Left outer join (select ColB3, ColB4, ColB5 from table B where colB3 = (select max(colB3) from table B ) on (colA1 = colB1 and ColA2 = col B2)

Now i have to join the next table C with table B

Table C structure is

ColD1 ColD2 ColD3 Desc1 A9 Executive Desc1 A7 Engineer

I have the common column such as ColD2 and colB4 to get the Col D3

how do i join the existing query + join between table b and table c?

View 4 Replies View Related

Data Guard :: Creating Standby Database From Active Database Using RMAN

Dec 21, 2012

creating the standby database from Active database using RMAN and getting the below issue after i executed the duplicate command.

Version of Database:11g(11.2.0.1.0)
Operating System:Linux 5
Error:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 12/21/2012 17:26:52
RMAN-03015: error occurred in stored script Memory Script
RMAN-04006: error from auxiliary database: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
[code]....

provide any work arounds to proceed further in creating the standby database.

View 1 Replies View Related

PL/SQL :: Related Collection Within A Collection

Sep 20, 2012

There is a nested table with in a nested table type and i want to print the value and again assign a new value to the next subscript and i have tried a lot but couldn't find any solution.

declare
type type_name is table of varchar2(10);
type type_name1 is table of type_name;
names type_name1:=type_name1(type_name('hello'));
begin
-----HOW TO PRINT A VALUE--------
-----HOW TO ASSIGN A NEW VALUE TO NEW SUBSCRIPT
null;
end;

1) need to print the values of names(1)
2)Assign a value to names(2)

View 3 Replies View Related

PL/SQL :: How To Create One-column Collection From Another Multi-column Collection

Mar 22, 2013

I am describing a SQL statement to get it's column list:DECLARE

cur     NUMBER;
col_cnt INTEGER;
rec_tab DBMS_SQL.DESC_TAB;

[Code]....

Now I need to get out the columns list from rec_tab.col_name and put it to my_colls collection. Have Oracle any build-in to do that?

View 4 Replies View Related

Creating SQL Script That Can Update Info From One Table In Dbase1 To Another Table In Dbase2?

May 16, 2013

creating an sql script that can update info from one table in dbase1 to another table in dbase2 that has the same columns and if possible insert date and time in one column when the synchronized is done?

View 3 Replies View Related

Creating Table From Existing Table In Another Schema?

Jan 4, 2009

I am creating a table from another existing table in another schema. The existing table contains data. When I am using the query- create table m _voucher as select * from ipm.m_voucher,I am getting the whole data of m_voucher but I want empty m_voucher table, so what will be the query to get the empty m_voucher table?

View 4 Replies View Related

SQL & PL/SQL :: Creating A Database From Scratch

Apr 10, 2011

I just started using SQL PL/SQL a couple of weeks ago and am now creating a database from scratch.The tables have all been created, and I'm now doing the triggers. One in particular is giving me a headache...

I have 3 different types of client, A, B and C. Each class gets a discount bigger than the one before, and you need to buy until you reach a threshold of X before you move to the next class. I'm trying to do the following trigger:

When I update one of the threshold for the class, I want to make sure the new value isnt bigger than the value of the next class. For example, if a client needs to buy for 100$ before moving to Class B from A and 200$ to move from Class B to Class C and I update the first threshold from 100$ to 250$, I want an error message to pop up saying the threshold is too high.

Right now the Class table looks like this:

Class ID (A,B and C)
Threshold (0,100 and 200)
Discount (0, 0.05, 0.10)

View 3 Replies View Related

Creating Standby Database In OEM 10g?

Dec 7, 2012

DB = Oracle 10.2.0.4
OS = Solaris 10 Sparc

I am trying to create a physical standby database using the add standby database option within OEM 10g. This is something we have done numerous times before on 10g and 11g db's without a single issue, but for some reason, this time after selecting my RMAN backup location and staging area location , I am getting the following error when I click Next:

RMAN Backup Location - The specified RMAN backup is invalid. Could not identify controlfile from the backup

It is the latest backup (using RMAN catalog) from the previous evening and includes datafiles and control file.

Here is the output for List backup:

BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
1741586 7.70G DISK 00:03:26 06-DEC-12
BP Key: 1741590 Status: AVAILABLE Compressed: NO Tag: TAG20121206T220033
Piece Name: /carebackup/oradata/CARELIVE/carelive/backup/df_CARELIVE_4811_1.bus

[code].....

The only difference between creating a standby for this db and others we have created is that the file system the backups are stored on is on a non-global zone shared via nfs mount.

I know that when I try and share that filesystem with other servers I get the message: share_nfs: Cannot share filesystems in non-global zones If the /backup filesystem is not shared with any other servers would OEM be able to read from that NGZ? The filesystem is available to connect to using ssh from other locations, but not sure how OEM handles this part of the process.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved