compare a value to the range of values in the table and get the value of corr
Hi allI'm a begineer and glued at one point.
I have a table that has 2 fields
number of days and the number of cards with values such as:
number of days number of cards 20 1
I have a SELECT query that returns the number of days, I need to get the number of cards based on the number of days.
40 2
60 3
As if the select returns 30 I should get 1 as the number of cards, if select returns 48 I should get 2 and so on.
Please help me
Thanks and greetings
SELECT MAX(num_of_cards)
FROM your_table
WHERE num_of_days <= X
Tags: Database
Similar Questions
-
How to insert into a GLOBAL TEMPORARY TABLE and get the data from it?
The requrement is
Split the string ENTRY point on the base and store it in a Collection. And the values of the collection will be stored in a global temporary table. Then, I'm updating some other table based on the data from the temporary table.
There is in fact no error message. But there is no data in the temporary table and also no change in the update statement
First of all, I'm creatiing a global temporary table only once outside the procedure.
CREATE GLOBAL TEMPORARY table GLt (data_element number)
create or replace procedure test_proc (p_in_string VARCHAR2) is
i the number: = 0;
number of POS: = 0;
CLOB lv_str: = p_in_string;
p_delim VARCHAR2 (1): = ', ';
TYPE t_array IS TABLE OF VARCHAR2 (20) INDEX directory.
t_array channels;
BEGIN
-cutting of string input and store in the strings (i) collection
POS: = instr (lv_str, p_delim, 1, 1);
WHILE (pos! = 0) LOOP
i: = i + 1;
Strings (i): = substr(lv_str,1,pos-1);
lv_str: = substr (lv_str, pos + 1, length (lv_str));
POS: = instr (lv_str, p_delim, 1, 1);
IF pos = 0 THEN
Strings (i + 1): = lv_str;
END IF;
END LOOP;
run immediately "drop table TWG;
run immediately ' CREATE GLOBAL TEMPORARY table (data_element number) TWG on commit preserve rows ";
FORALL i in strings.first... Strings.Last
INSERT INTO VALUES TWG (strings (i));
commit;
Update first_tbl set PIN is "XXX" where first_col in (select data_element from TWG);.
commit;
END test_proc;
Published by: cedric b on January 25, 2013 12:59Remove the two execute immediate line. They are wrong.
And then use the table in your code that you created at the beginning. The name is GLT.
And delete the first commit. This validation would empty the temporary table of GLT.You get an error? Or it does not work as expected?
Also, show how you call the procedure.
Published by: Sven w. January 25, 2013 14:45
-
Move the partition of the table and get ORA-14006: invalid partition name
I'm using oracle 11.2.0.4 and I am trying to move a partitioned table to one tablespace to another. I checked may times and I have the correct table name and the name of the partition. However, I get the error ora-14006.
Can see everything what could be the problem?
SQL > ALTER TABLE GWPROD. QRY_TES_ROLLINGCUREDITS MOVE PARTITION 201112 TABLESPACE GW_PROD_T2 PARALLEL (DEGREE 4) NOLOGGING;
ALTER TABLE GWPROD. QRY_TES_ROLLINGCUREDITS MOVE PARTITION TABLESPACE GW_PROD_T2 PARALLEL (DEGREE 4) NOLOGGING 201112
*
ERROR on line 1:
ORA-14006: invalid partition name
Thanks in advance.
Names that begin with numbers are not legal partition names. A fool created by placing them between double quotes. You will need to do the same.
-
How to join tables and get ppl not in the list of the other table
Hi, I have 2 tables
Table (girlscoutid, quarter, point)
Table b (girlscoutid, fname lname)
I want to get the names of ppl who didn't sell any point/s for Q4
girlscoutid agenda quarter 7771 drinks 4QS 9000 Tickets 4QW 7771 Cookies 2QS 5085 books 3QF 3010 Tickets 3QW 5085 Cookies 1QF lscoutid fname lname 7771 Jenn Richochet 9000 Laura Wilkins 5085 Sally Mae 3010 Dora McKenzie That's what I have, however, I get duplicates and also 7771 appears on the list even if she sold something on the 4th quarter. Any suggestions?
SELECT fname, lname, a.girlscoutid
Of a, b
WHERE a.girlscoutid = b.girlscoutid
AND the term NOT AS "4Q_";
Hello
So, all the information that you want to see figure in table b, but if you want to see it depends on the table has.
This looks like a job for a semi Join. Here's a way to do it:
SELECT b.fname
b.lname
b.girlscoutid
B
LEFT OUTER JOIN has IT a.girlscoutid = b.girlscoutid
AND a.quarter NOT AS "4Q_" - or a.TERM, if it is the column
WHERE a.girscoutid IS NULL
;
What you posted was an INNER join, where the rows of each table are included in the only game that if they have a corresponding row in the other table.
An OUTER join includes all the rows in a table (table b in this case) if they have a match in the other table. If a line of b has no corresponding row in a, then all the columns that are supposed to come from table will be NULL in the result set. Given that the join condition includes = b.girlscoutid a.girlscoutid, this means that the only way to a.girlscoutid can be NULL in the result set is if the b line is included although it has no corresponding line one, which are exactly the lines that we want to display. (You can try to run the query above with the WHERE clause, deleted, just to see how it works.)
Alternatively, you can get the desired results by using a subquery NOT EXISTS, a NOT IN subquery or analytical functions. The semi join, supra, is probably the most effective solution.
-
Creating the table and get the invalid identifier
Thank you so much Ed (and all those who responded) to my previous post!, you all be extremely useful.
In fact, I have another question... Can I repost a new thread or continue on this one?
Here's my problem.
create the table DonationEvent
('ID' NUMBER (1,1) Not Null,)
"EventNumber" NUMBER (1,1) Not Null,
'Type' char (30) Not Null,
"OrganizerName' char (30) Not Null,
'Location' char (30) Not Null,
'Date' NUMBER (10.1) Not Null,
'Time' char (30) Null,
"DonationTotal" NUMBER (10.1) Not Null,
Primary Key (ID),
);
Getting ORA-00904: invalid identifier
Also I use Express Edition 10g, how can I get a view of context to see the line where error occurs?Cushgod wrote:
I always get invalid identifiers... Your focus is so useful! My teacher is not useful. At his table did not work it would be copy and paste that work and say that he didn't had the time to debug it... I can't even say what my mistake is on in the Express edition...What do you use to write/test your sql? That's why I asked sqplus. This is the basic sql shell. In the examples I showed you I had by the sql in a text (doit.sql) file, shot to the top of sqlplus, connect to the base, execute "doit.sql".
You're my only hope! Thank you very much in advance, I learn a little which makes me question why my teach would even use "" eventid NUMBER (1,1) not null "" after your explanation. " It's not supposed to have a decimal number to a primary key event IDS... anyway thanks in advance.
create the table DONATIONEVENT
(eventid NUMBER (5) Not Null,)
eventnumber NUMBER (9) Not Null,
EventType VARCHAR2 (30) Not Null,
OrganizerName VARCHAR2 (30) Not Null,
location VARCHAR2 (30) not Null,
EventDate DATE Not Null,
duration VARCHAR2 (30) Null,
donationtotal NUMBER (10.2) Not Null,Primary Key (ID),
);
If I use a DATE instaed (4) no setting, I get "' missing right parenthesis"... once again. I counted my bracket and the match 10 (and 10)
See below.DATE is right. Where did you get the idea of DATE (4)?
The documentation site (tahiti.oracle.com) Oracle seems to be down at the moment, but you really, * really *, * REALLY * need to get there and take the reference SQL and SQL * reference manuals more.
create the table DONATIONEVENT
(eventid NUMBER (5) Not Null,)
eventnumber NUMBER (9) Not Null,
EventType VARCHAR2 (30) Not Null,
OrganizerName VARCHAR2 (30) Not Null,
location VARCHAR2 (30) not Null,
EventDate DATE (4) Not Null,
duration VARCHAR2 (30) Null,
donationtotal NUMBER (10.2) Not Null,Primary Key (ID),
);
-
In the form of table and colspan or how to return more items in one line?
I want to put a line in a higher number of items table it fits. So I want to put several options on an entry line field and text on another and so on. To restart the line, I made a dummy field with html like this:
< table > < /tr > < tr > < td >
But it's really ugly: http://apex.oracle.com/pls/apex/f?p=29764:1
How to force colspan = X extend this cell of the input line along the table and get rid of these unnececary of the empty cells on the right? Attribute of the element does not (obviously)...Create a model of a named column custom report to meet the requirements in the form of tables.
-
comparing string values in the same table
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring 'B1020792' in the same table, example: A12349B1020792. If this happens, the ID of the last creation date of must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 has the date of 1 January 2015 'and A21849B1020792 has date February 1, 2015", since A21849B1020792 has the most recent date, the result must contain only A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349 B1020792 01/01/2015
A12345B1234567 01/03/2015
A43567B1234567 01/04/2015
Here's the query I used:substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 04/01/2015
There is one thing that I'm not able to do with my request, that is, be able to get real IDs list and not list of substrings. If I added a.id column in the select clause and the group by clause, the query includes both by substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
01/01/2015 A12349B1020792 B1020792
B1020792 01/02/2015 A21849B1020792
B1234567 01/03/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
Hello
user11951344 wrote:
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring "B1020792" in the same table, example: A12349B1020792. If this is the case, the ID of the last creation date must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 updated 1 January 2015 ' and A21849B1020792 a date February 1, 2015", as A21849B1020792 has the most recent date, the result should contain only the A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349B1020792 01/01/2015
A12345B1234567 03/01/2015
A43567B1234567 01/04/2015
Here's the query I used:
substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 01/04/2015
There is one thing that I am not able to do with my request, that is, the ability to retrieve the list of IDs real and not a list of substrings. If I added a.id column in the select clause and the group by clause, the query groups according to the two substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
B1020792 01/01/2015 A12349B1020792
B1020792 02/01/2015 A21849B1020792
B1234567 03/01/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
If it makes sense to treat the first 6 characters of the ID separately from the rest of the id in this problem, maybe it makes sense to store those two parts of the id in two different columns. Relational databases work best when each column of each row contains 1 single piece of data (at most). It is so fundamental to the design of table that he called the first normal form.
Given that the two parts are stored in column 1, so you can something like this Request Top - N:
WITH got_r_num AS
(
SELECT r.id
r.create_date AS cd1
, RANK () OVER (PARTITION OF SUBSTR (r.id, 7))
ORDER BY r.create_date DESC
) AS r_num
FROM table_x g - g for data values
JOIN table_x r - r for related values
ON SUBSTR (r.id, 7) = SUBSTR (g.id, 7)
WHERE g.id IN ('A12349B1020792'
, "A21849B1020792".
, "A12345B1234567".
, "A43567B1234567".
)
- AND g.id LIKE 'A %' - if necessary. The above condition ensures already g.id start with "A".
AND r.id LIKE 'a % '.
)
SELECT id, create_date
OF got_r_num
WHERE r_num = 1
;
If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test this.
-
How can I compare unique value with several value...
Hello
I want to compare a value with multiple values, how is it possible?
I tried to design the same logic here as an attachment, but I had the problem that when I entered the value of y that is compared with only a minimum value of x, I don't want I want to compare the value of y with the value of x and then if y is less than x while loop should be stop.
I want to do because in my program some time I have not result I want, for example, the values of x is 4,5,6,7,8 and value is assumed to be 6 then while loop should be stop but here he considers only less and its 4 here so so that the loop is not stop even there is less then 7 and 8. So I want to compare the value of y with all values of x and if y is less then one of the values while x loop should be stop and led should be on.
Please guide me how I can do...
I don't understand? If there is less than the minimum value of X then it is less than all values of X. That's what I do anyway:
-
How compare 2 qint64 value and get second between specific to this 2 milliseconds?
Hi all
I have 2 qint64 value.
QDateTime kvalue22 = QDateTime::currentDateTime(); qint64 callDate1 = kvalue22.toMSecsSinceEpoch(); QDateTime kvalue12 = QDateTime::currentDateTime(); qint64 callDate2 = kvalue12.toMSecsSinceEpoch(); calleDate1 value get is :- 1413876094886 calleDate2 value get is :- 1413876096744
Now, I compare 2 value like this
qint64 finalVal = callDate2 - callDate1; finaVal get is :- -540686770567307544
But I don't get a perfect result. You can view here.
So if you have any solution please let me know as soon as possible.
you set incomingCallDate inside the method, it means that it is created for each method call.
Set out the method for him to retain its value.Your current results stem from the fact that incomingCallDate is initialized in some calls and contains a random value.
-
How to compare a value from array in an if statement
When I compare cdlCorrect [index] 0, it displays true, but when I draw it, it 2.
The if statement seems to be comparing the index itself to 0. How can I compare the value. In fact, as I continue to call this function (by clicking on the button), it always compares to 0, but the trace will return as 2, then 1, then 2, then 0, then 0. I think I'm getting the index, but then they must compare to 0, then 1, then 2, etc. I do not understand why it always compares to zero.
function chkAnswer(mevt:MouseEvent):void {}
cdlDone [index] = 1;
var rectSize:uint = 300;
var correctRect:Shape = new Shape();
correctRect.graphics.beginFill (0x00FF00, 0.5);
if (cdlCorrect [index] == 0) {}
correctRect.graphics.drawRect (45, 40, rectSize, 30); Address: 45:x 120:y rectSize:width 50:height
trace ("this is 0");
}
If (cdlCorrect [index] == 1) {}
correctRect.graphics.drawRect (45, 80, rectSize, 30); Address: 45:x 120:y rectSize:width 50:height
trace ("it is 1");
}
If (cdlCorrect [index] == 2) {}
correctRect.graphics.drawRect (45, 80, rectSize, 30); Address: 45:x 120:y rectSize:width 50:height
trace ("this is 2");
}
trace (cdlCorrect [index]); 2
trace (cdlCorrect); 2,1,2,0,0
}
If you read the values from an xml file then you need to convert them into numbers, or you need to test them as strings.
try changing
If (cdlCorrect [index] == "0") {}
and similarly for the other institutions
-
Hello
do we not have a function to compare two values of type varchar column.
I have a table tab1
I'm trying to store the result in a view...col1 col2 abc abc cde cde efg aba ghi ikl abc abc
How can this be achieved through the function or query.col1 col2 diff abc abc true cde cde true efg aba false ghi ikl false abc abc true
Thank you.BTW, all the posted solution do not consider NULL values:
SQL> with t as ( 2 select 'abc' col1,'abc' col2 from dual union all 3 select 'cde','cde' from dual union all 4 select 'efg','aba' from dual union all 5 select 'ghi','ikl' from dual union all 6 select 'ghi',null from dual union all 7 select null,'ikl' from dual union all 8 select null,null from dual union all 9 select 'abc','abc' from dual 10 ) 11 select col1, 12 col2, 13 nvl2(regexp_replace(col1,'^' || col2 || '$'),'false','true') sy, 14 case when col1=col2 then 'true' else 'false' end arun_Centinul_hoek, 15 DECODE(col1, col2, 'true', 'false') Himanshu 16 from t 17 / COL1 COL2 SY ARUN_CENTINUL_HOEK HIMANSHU ---- ---- ----- ------------------ -------- abc abc true true true cde cde true true true efg aba false false false ghi ikl false false false ghi false false false ikl true false false true false true abc abc true true true 8 rows selected. SQL>
SY.
-
Search for the string in the string table and see the following value in the line
Hi, I'm new I have LV and I do a Vi that read worksheet values and generates 2d channels of the same spreadsheet table. For the moment everything I need is a function that find specyfic string in this table and show the next value in a line. As:
Table:
a; b
c; d
f; gexample: find the 'c '.
VI shoud show "d".
Concerning
Not a bad homework problem. Do it with pencil and paper. Write your table and pretend you're the computer. What you want to do (step by step)? What questions do you have?
Now that the translation a bit to computers. You mentioned that the data is in an array of strings. What structures (LabVIEW) work with tables? [Do you know how to work with tables? [Otherwise, review some of LabVIEW Tutorial material - see top right of the first page of the Forum]. What do you know about channels? What questions you need to ask questions on the channels? What do you know about string functions?
Watch these things in some LabVIEW code, 'feed' some data and see what he does. If it seems to do things "unexplained", you can try to look at the block diagram to run by turning the performance highlight (and if you don't know what that means, use the help of LabVIEW and see the tutorials).
Bob Schor
-
Two tables provided, how you retrieve the values in two columns using values in a column (the pass get values. If col. A is not null values and get the pass. B if col. A is null)?
Guessing
Select nvl (x.col_a, y.col_b) the_column
from table_1 x,.
table_2 y
where x.pk = y.pk
Concerning
Etbin
-
Left join of the two tables and multiple values into a single value separated by commas
Hello
I have following tables with their structures and their data as below.
CREATE TABLE 'BETODI '. "" BETINFO ".
(
VARCHAR2 (8 BYTE) "CURRENTPRESS."
ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL
)
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");
CREATE TABLE 'BETODI '. "" BETMASTER ".
(
ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,
ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,
NUMBER (5.0) "LASTPCIRIM".
)
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);
These two tables have left join as
BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)
now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.
Also something like
Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)
So, for example above, we should be given as
A24 PMC 15; PENSKY-MARTENS
A25 15 PMC
A26 15 PMC
A27 16 (NULL)
A28 16 (NULL)
A30 15 (NULL)
A31 16 (NULL)
A32 16 BFC2-V; V BFC3
A33 16 (NULL)
A34 16 (NULL)
How could do?
My current request is as
Select distinct Curepress, lastpcirim, typeidcontainer
BETMASTER STD left join INF BETINFO
on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)
but I am unable to get the values separated by commas.
Any help would be appreciated.
Thank you
Mahesh.
Hi, Mahesh,
If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim? This sounds like a job for GROUP BY.
And you want the row to contain a list of all different typidcontainers-delimited? This sounds like a job for the aggregate LISTAGG function.
WITH joined_data AS
(
SELECT DISTINCT
MST.curepress, mst.lastpcirim, inf.typeidcontainer
OF betmaster STD
LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)
1
3
)
)
SELECT curepress, lastpcirim
LISTAGG (typeidcontainer, ',')
THE Group (ORDER BY typeidcontainer) AS container_list
OF joined_data
Curepress GROUP, lastpcirim
;
Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are. (Note that the subquery is just what you posted).
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful. Don't forget to tell what version of Oracle you are using. LISTAGG was new in Oracle 11.2.
Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces? Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.
-
How to assign values to the nested table and passes as a parameter for the procedure?
How to assign values to the nested table and passes as a parameter for the procedure?
Here are the object and its type
create or replace type test_object1 as an object
(
val1 varchar2 (50).
val2 varchar2 (50).
VARCHAR2 (50) val3
);
create or replace type test_type1 is table of the test_object1;
create or replace type test_object2 as an object
(
val1 varchar2 (50).
val2 varchar2 (50).
VARCHAR2 (50) val3
);
create or replace type test_type2 is table of the test_object2;
GRANT ALL ON test_object1 to PUBLIC;
GRANT ALL ON test_type1 to PUBLIC;
GRANT ALL ON test_object2 to PUBLIC;
GRANT ALL ON test_type2 to PUBLIC;
Here is the table object type:
create the table test_object_tpe
(
sl_num NUMBER,
Description VARCHAR2 (100),
main_val1 test_type1,
main_val2 test_type2
)
NESTED TABLE main_val1 STORE AS tot1
NESTED TABLE main_val2 STORE AS earlier2;
-----------------------------------------------------------------------------------------------------------
Here is the procedure that inserts values into the nested table:
PROCEDURE INSERT_TEST_DATA (sl_num in NUMBER,
Description in VARCHAR2,
p_main_val1 IN test_type1,
p_main_val2 IN test_type2
)
IS
BEGIN
FOR rec in p_main_val1.first... p_main_val1. Last
LOOP
INSERT INTO xxdl.test_object_tpe
(
sl_num,
Description,
main_val1,
main_val2
)
VALUES
(
sl_num
description
test_type1 (test_object1)
p_main_val1 .val1 (CRE),
p_main_val1 .val2 (CRE),
p_main_val1 .val3 (rec)
)
)
test_type2 (test_object2 (p_main_val2 .val1 (CRE),
p_main_val2 .val2 (CRE),
p_main_val2 .val3 (rec)
)
)
);
END LOOP;
commit;
END INSERT_TEST_DATA;
-------------------------------------------------------------------------------------------
Here are the block anonymoys what values attributed to the object type and pass values in the procedure:
Set serveroutput on;
declare
p_sl_num NUMBER: = 1001;
p_description VARCHAR2 (50): = 'Test Val1;
inval1 test_type1: = test_type1();
inval2 test_type2: = test_type2();
Start
inval1 (1) .val1: = "testx1";
inval1 (1) .val2: = "testx2";
inval1 (1) .val3: = "testx3";
inval2 (1) .val1: = "testy1";
inval2 (1) .val2: = "testy2";
inval2 (1) .val3: = "testy3";
CSI_PKG. INSERT_TEST_DATA (sl_num = > p_sl_num,)
Description = > p_description,
p_main_val1 = > inval1,
p_main_val2 = > inval2
);
end;
/
Someone can correct me.
Thank you
LavanThanks for posting the DOF and the sample code but whenever you post provide your Oracle version 4-digit (result of SELECT * FROM V$ VERSION).
>
How to assign values to the nested table and passes as a parameter for the procedure?
>
Well you do almost everything bad that could be hurt.Here is the code that works to insert data into your table (the procedure is not even necessary).
declare p_sl_num NUMBER := 1001; p_description VARCHAR2(50) := 'Testing Val1'; inval1 test_type1 := test_type1(); inval2 test_type2 := test_type2(); begin inval1.extend(); inval1(1) := test_object1('testx1', 'testx2', 'testx3'); inval2.extend(); inval2(1) := test_object2('testy1', 'testy2', 'testy3'); INSERT INTO test_object_tpe ( sl_num, description, main_val1, main_val2 ) VALUES (p_sl_num, p_description, inval1, inval2); commit; end; /
See example 5-15 making reference to an element of nested Table Chapter 5 using PL/SQL collections and records in the PL/SQL doc
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/Collections.htm#CJABEBEA1. you don't even have the procedure because it is a simple INSERTION in the table you can do directly (see my above code)
inval1(1).val1 := 'testx1';
Since you have not yet created all the elements, there is no element 1 "inval1". You need EXTEND the collection to add an element
inval1.extend();
And then, there is an empty element, but "inval1" is a container for objects of type 'test_object1' not for scalars as "val1", "val2", and "val3".
If you can not doinval1(1).val1 := 'testx1';
You must create an instance of 'test_object1 '.
inval1(1) := test_object1('testx1', 'testx2', 'testx3');
And so on for the other collection
You don't need the procedure (as my code example shows), but once you fill in the variables correctly it will work.
Maybe you are looking for
-
My MacBook Pro loses the WiFi constantly
Since I got my new MacBook Pro (13-inch early 2015), I had speed incredibly slow connection. I am currently running 10.11.5 It became obvious that it was the computer when: I had to connect my printer to print when I was not with my 2008 macbook I'm
-
So, I installed Skype before and it worked just fine. Then last month, when I opened it, I couldn't connect. I uninstall and reinstall it again in the hope that it could solve the problem but stil I couldn't connect. I checked if my phone is still su
-
Can someone explain please the icon with a check mark phone in iTunes.
I would just like someone to explain to me how the iphone with the checkbox icon in iTunes on my phone
-
Hi all Please refer to the attached 2 pictures, they are similar, just the size is defferent. (pass PNG, 5478 pass. PNG). But now I try to use IMAQ detect circles to catch the GREEN button. For the PNG pass, it works very well, but for another exampl
-
How can I install my deskjet d1660 on windows 7?
Hi, I have a HP Deskjet D1660, which I am trying to install on my MacBook Pro running Windows 7 64 - bit on Boot Camp. I installed it successfully on my side Mac that is running Lion, but when I try to install with Windows, it says that I don't have