Helps the sql pl table
Here is what I need help... I need to go through a few lines of code andAdd values in a pl sql table. Then I must get these values I added in a different section.
But when I try to retrieve the values it gives me only the last value. So I think I write about the values that I am incrementing. Could someone please help?
How do I retrieve these values to be added to an existing table? When I run it it seems to have only the last value?
All comments appreciated!
DECALRE
TYPE app_cnt_type IS TABLE OF THE priority_countries.country_code%TYPE
INDEX OF DIRECTORY;
app_table app_cnt_type;
v_capp_index directory.
BEGIN
-the counter of the country continues to go to different countries as 'US', 'UK', 'MX '...
IF v_section_name = "country" THEN
app_table (1): = v_input_value;
v_capp_index: = app_table.first;
LOOP
MESSAGE (app_table (v_capp_index));
EXIT WHEN v_capp_index = app_table. LAST;
v_capp_index: = app_table. Next (v_capp_index);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
MESSAGE ("no country more");
END;
You're always one value of loading and then a loop in a collection that is never more than one value. Whenever you call the code block, the collection is re-initialized.
How about something like that, by passing the values one by one.
create or replace package p is
procedure clear_collection;
procedure add_value(p_value in varchar2);
procedure show_values;
end;
create or replace package body p is
type t is table of varchar2(100);
a t;
procedure clear_collection is
begin
a.delete;
end;
procedure add_value(p_value in varchar2) is
begin
a.extend;
a(a.last) := p_value;
end;
procedure show_values is
begin
if a.exists(a.first) then
for i in a.first .. a.last loop
dbms_output.put_line(i||' '||a(i));
end loop;
end if;
end;
begin
a := t();
end;
begin
p.clear_collection;
p.add_value('US');
p.add_value('UK');
p.add_value('MX');
p.show_values;
end;
1 US
2 UK
3 MX
Tags: Database
Similar Questions
-
Oracle on the SQL Server tables dblinked query error ORA-00904
Hello
I created a dblink to a SQL from Oracle database using generic connectivity.
The following query returns the error ORA-00904 invalid identifier in the (tblEmp.Empno) WHERE clause
SELECT 'EmpNo', "EmpName", "DeptName".
OF tblEmp@sqlserver.
tblDept@sqlserver
WHERE tblDept.DeptNo = tblEmp.Empno
I had to include the column names between double quotes because of the case review of the columns, but I can't do the
same thing for the WHERE clause.
(1) so how can I fix this error?
(2) also how can I include the Deptno column with the table alias in the columns list?
(Deptno is ambiguous in the Emp and Dept tables)
Kind regards
SamLooks like you have case-sensitive column names, try this
SELECT "EmpNo","EmpName", "DeptName" FROM tblEmp@sqlserver e, tblDept@sqlserver d WHERE d."DeptNo" = e."Empno" --<--- are you sure this is the correct join condition
What should we not
WHERE d."DeptNo" = e."DeptNo"
Published by: Alex Nuijten on September 22, 2009 13:28
-
Adding record helps the dynamically nested table
Hello guys im trying to add records to a nested table plsql dynamically. Here is my code that only adds a record. I can not figuered on why it's not more then add one record to the nested table. I think I would say at the table to update the index and insert the new index but I'm not sure on the index can someone throw me a BONE.
I also tried the records, but I seem to be facing the same problem.
create or replace PROCEDURE QUICKTEST AS BEGIN /*declare and array to loop through. to write error log.*/ declare TYPE local_table IS TABLE OF VARCHAR2(30); acct_code local_table; TYPE rec_type IS RECORD ( -- local RECORD type f1 INTEGER, f2 VARCHAR2(4) ); r2 rec_type; -- local type num number(17):=0; begin FOR Lcntr IN 1..20 LOOP acct_code := local_table ('I'); r2.f2 := num+1; num:=num+1; END LOOP; END QUICKTEST;
I think you are looking for something in the lines of...
CREATE OR REPLACE PROCEDURE quicktest AS TYPE local_table IS TABLE OF VARCHAR2(30); acct_code local_table := local_table(); TYPE rec_type IS RECORD( -- local RECORD type f1 INTEGER ,f2 VARCHAR2(4) ); TYPE rec_type_arr IS TABLE OF rec_type INDEX BY BINARY_INTEGER; r2 rec_type_arr; -- local type num NUMBER(17) := 0; BEGIN FOR lcntr IN 1 .. 20 LOOP acct_code.EXTEND; acct_code(lcntr) := 'I' || lcntr; r2(lcntr).f1 := num + 1; r2(lcntr).f2 := 'J' || TO_CHAR(num + 1); num := num + 1; END LOOP; DBMS_OUTPUT.put_line(acct_code.COUNT); DBMS_OUTPUT.put_line(r2.COUNT); FOR i IN acct_code.FIRST .. acct_code.LAST LOOP DBMS_OUTPUT.put_line(acct_code(i)); END LOOP; FOR i IN r2.FIRST .. r2.LAST LOOP DBMS_OUTPUT.put_line(r2(i).f1 || ' :: ' || r2(i).f2); END LOOP; END quicktest; /
-
Hello
I want to display the following result:
MaxDate, tagname, pubid, County
I have 2 select sentences:
1. SELECT MAX (tagdate) as lastdate OF JPASSETTAGS where TAGNAME = 'NY '.
2. SELECT t.TAGNAME, pubid, COUNT (*) as count FROM JPASSETTAGS t, ASSETPUBLICATION where a.ASSETID = t.ASSETID GROUP BY t.TAGNAME ORDER BY 3 DESC pubid
How could he be with a select?
JPASSETTAGS table has the column tagdate, tagname, assetid
table ASSETPUBLICATION has the pubid column, assetid
Thank you!Hello
If you are sure that all tag names would come after joining so you can use query below.
SELECT t.TAGNAME, pubid, COUNT(*) as count MAX(DECODE(t.TAGNAME,'NY',t.TAGdate,NULL)) as MaxDate FROM JPASSETTAGS t,ASSETPUBLICATION a where a.ASSETID = t.ASSETID GROUP BY t.TAGNAME,pubid ORDER BY 3 DESC
See you soon,.
-
need help on sql on the full month
Hello
I have a table as below:
The table name:
Information
-----------------
staff_number
Date
clock_in
clock_out
Note
I want to create sql which will list down all date selection staffnumber
Select date, clock_in, staff_number, clock_out, information note where (date > = to_date('01/01/2010') and date < = to_date('01/02/2010')) and staff_number = "012345 '
Can someone help me on how to change the sql code out in the list, if there is no database on a certain date.
For example
012345 8.10 01/01/2010 17:30
012345 8.12 02/01/2010 16:30
012345 03/01/2010 - not in the database, but I want it appears in sql
012345 04/01/2010 08:30 18:40
012345 8.10 05/01/2010 16:30
012345 06/01/2010 08:30 16:30
....
012345 8.10 02/01/2010 16:30
Thanks in advanceYou don't need LAST_DAY then:
select to_date('13/01/2010', 'dd/mm/rrrr')+ level-1 dt from dual connect by level <= to_date('23/02/2010', 'dd/mm/rrrr')-to_date('13/01/2010', 'dd/mm/rrrr')+1;
(And subtract from the most recent date)
-
How to use the T distribution table in sql statements?
Hi all
I'm in the need to use the T distribution table in sql... I don't know how to use...
Is there a function to use the values of table in sql statements?
Can someone please help me in this?How about this http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions157.htm#i1279931?
Concerning
Etbin
-
While performing a mapping (present in the package) that loads the file to table data, my mapping is being failed in the step - LKM file with above mentioned SQL error.
This task is running for 30 candy Mint and loading data about 30 to 40 million for the temporary table of C$ ODI.
Before the completion of the task is to make failure and also C$ table is also get deleted.
Any possible resolution for above mentioned the issue?
Problems have been solved.
In our case, the prefix of all the data store name has been SRC_ so the nickname of all the data store became SRC, and the table name C$ depends on the daatastore Alias.
So for executing two mapping tables $ CAN have been getting dropped by other mapping due to the same table name $ CAN.
Change the Alias name giving it a unique name solve the problem.
-
How to see the sql on the tables verified statements?
Hi all
I just check schema as the following comment run
AUDIT UPDATE TABLE DELETE TABLE INSERT TABLE BY user1, user2 BY ACCESS;
However, I could not find the SQL statements.
SELECT A.TIMESTAMP, A.* DE DBA_AUDIT_TRAIL A
OÙ
Username = ' USER1'
Also, this does not work, it shows empty
select sql_text from sys. aud$ où obj$ nom = « TAB_PROJELOG »
Oracle Database 11 g Release 11.2.0.4.0 - 64 bit Production
db
Redirect audit records to the database audit trail (the
SYS.AUD$
table), except for records that are always written in the track operating system audit. Use this setting for a general database for administration.If the database is started in read-only mode with
AUDIT_TRAIL
defined ondb
, then affects the Oracle database internallyAUDIT_TRAIL
toos
. Check the log of alerts for details.db, extended
Performs all the actions of
AUDIT_TRAIL
=db
and fulfills also the bind SQL and SQL CLOB type text columns of theSYS.AUD$
table, when it is available. These two columns are filled only when specified.If the database is started in read-only mode with
AUDIT_TRAIL
defined ondb, extended
, then affects the Oracle database internallyAUDIT_TRAIL
toos
. Check the log of alerts for details.
https://docs.Oracle.com/CD/E11882_01/server.112/e40402/initparams017.htm#REFRN10006
-
What is the SQL to determine what are the table objects in the KEEP buffer pool?
What is the SQL to determine what are the table objects in the KEEP buffer pool?
Select owner, table_name
from dba_tables
where USER_TABLES = "KEEP."
/
David Fitzjarrell
-
How can I pass a condition of the table in the sql statement?
For example, in the table in the COND Varchar2 column (200) there is the value ' VAR > 10'.
| COND |
|' VAR > 10' |
where VAR is the name of the table column. I would like to make statement CASE WHEN VAR > 10 AND 0... I tried with as subquery
WHEN BOX (SELECT COND FROM TABLE WHERE...) THEN 0, but it does not work.
Hello
You can do this by using dynamic SQL.
that is to say:
declare v_stm varchar2(4000); v_cond varchar2(100); v_result integer; begin select cond into v_cond from yourtable where a=1; v_stm := 'select case when '||v_cond||' then 0 ...'; -- dynamic sql execute immediate v_stm into v_result; end; /
Remember that, in general, dynamic SQL has a performance degradation that SQL static and should be avoided when possible.
Storage condition or the SQL statements in the tables is not a good practice.
Kind regards.
Alberto
-
Dimension to build using the SQL table and process to populate the SQL table
I have a dimension in a cube that is manually* built by one of our power users. Now, I have to get all the information of members of this dimension in a SQL table (example: with columns... Level0, level0property, level1, level1property etc...) to use this table in the STUDIO for the responsibility of the Member.
Is there any easy process to do this? Currently I am building each line manually in the SQL table and there are 1100 + members in that manually built dimension. Please advice.Look at the outline of applied olap Extractor is a free utility
-
Table of misinterpretation of the SQL Developer Reference
I use SQL Developer with Oracle 11 g DBMS 2.1.1.64.
I've noticed recently that even if the DBMS allows you to create a table and a function with the same name, if I try to type a variable % TYPE by using the table, that I have just mentioned, there is a compilation error. For example, there are cancel_tag_range and cancel_tag_range of the table function. Then I do this variable declaration:
v_current_tag cancel_tag_range.start_tag%TYPE;
that translates into error "PLS-00225: reference of the subprogram or cursor 'CANCEL_TAG_RANGE' is out of range."
that is, SQL Developer interprets as a reference to the function, not the table.
It seems to me that the SQL Developer should know how to handle this. After all, the DBMS let me name 2 objects the same - which I think should be a problem because they are different object types - one is an array and the other a function. In addition, the context of the statement should specify that the table is referenced.
Why does this happen? And there at - there no way to get around this other than rename one of these objects? Thank you.SQLDeveloper use the PL/SQL compiler in the DBMS so the error comes from the DBMS. You'll have to rename it, I suspect.
-
How to store the SQL in the oracle table?
I tried this way:
SQL > insert into sql_text values ('select invoice, invoice_dt, DT_INVOICED from PS_BI_HDR where DT_INVOICED = 21)
(Jan - 2010' and BILL_STATUS ='INV ");
Insert in sql_text values ('select invoice, invoice_dt, DT_INVOICED from PS_BI_HDR where DT_INVOICED = 21 - JAN-)
010' and BILL_STATUS ='INV ")
*
ERROR on line 1:
ORA-00917: lack of comma
Please help to solve, I can't use the concatenation (|)
coz
It is dynamic.'select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV' '
user2060331 wrote:
No sql statement is a dynamic value inserted by a user to execute on the SQl prompt.Then use q-literals:
SQL> ACCEPT stmt PROMPT "Enter statement: " Enter statement: select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV' SQL> insert into sql_text values('&stmt'); old 1: insert into sql_text values('&stmt') new 1: insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'') insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'') * ERROR at line 1: ORA-00917: missing comma SQL> insert into sql_text values(q'[&stmt]'); old 1: insert into sql_text values(q'[&stmt]') new 1: insert into sql_text values(q'[select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV']') 1 row created. SQL>
SY.
-
Join itself find missing links, helps the query, table
Data in the table:
I'm trying to right a query that returns the relationships that are the only way.tblRelationships RelationshipID SourceID DestinationID 1 100 200 2 200 100 3 300 100
So for the above data, 3 would return because he'll only source 300 to 100 and not source from 100 to 300.
Published by: avalanche333 on January 15, 2010 12:26SQL> create table tblRelationships ( 2 RelationshipID NUMBER, 3 SourceID NUMBER, 4 DestinationID NUMBER) 5 / Table created. SQL> insert into tblRelationships values (1,100,200); 1 row created. SQL> insert into tblRelationships values (2,200,100); 1 row created. SQL> insert into tblRelationships values (3,300,100); 1 row created. SQL> SQL> select relationshipid from tblrelationships 2 where sourceid in ( 3 select SourceID from tblRelationships 4 minus 5 select destinationid from tblRelationships) 6 / RELATIONSHIPID -------------- 3 SQL> drop table tblRelationships 2 / Table dropped. SQL>
-
The temporary and tables using SQL tuning tools
The application that I support uses temporary tables for the majority of queries... Looking at the SQL tuning advisor and more of other oracle tuning tools, they seem well managing temporary tables.
It's what Happens (from what I can tell).
(1) oracle identifies a SQL statement (or the ADMINISTRATOR only), to be tuned.
(2) the original execution statistics are saved for comparison
(3) oracle tries to find a new plan (but at this point, the temporary table is empty).
(4) it tries to execute the new plan (once again the temporary table is empty).
(5) it comparies the execution time of the new plan against the original plan
The comparison, of course, is not a reasonable comparison.
Does anyone have experience with this problem? My first thought is for 'premium' of the temporary table, then run the Advisor of tuning in the same session (hoping that it will use the values in the temporary table).
Other than that, rereading of the database seems to be the best way to adjust sql plan changes using baselines.Expected.
Maybe you are looking for
-
Upgrade to El Capitan Mountain Lion
Can I move to El Capitan of Cougar or do I go to Yosemite first?
-
MAX with replication DAQ cards
Hello Hope someone could shed some light on this Its a long time since I've used Labview & MAX and am a little rusty right now. I'm trying to upgrade an old data acquisition system to a newer version. This is because originally one full working backu
-
I need help, change the administration password
I bought my computer at a yard sale. It has an administrative password. Can I get help to know what it is?
-
Can I install a USB 2.0 5-Port PCI card on XP
I have a Compaq Presario AMD Duron processors 701 MHz 768 RAM. Windows ME original system upgraded to Windows XP Home Edition Version 2002 service Pack 3. Can I install a PCI 5 ports USB 2.0 on this system?
-
URGENT driver please, which should I get?
Hello I have a laptop Inspiron 1505/4600 (E1505, processor Intel Core Duo T2300E (2MB/1.66GHz/667MHz) and had to reformat the hard drive and install a new Win XP Pro. I don't have the original CD of OS that came with it, not to mention that I have no