Initialize Pl/sql table values
Hi,
Can anyone tell me how the Initialize the values in a pl/sql tables. I want an Example.
Cheers
Nirmal
> 1.Arrays are fixed with lower and upper bound, but PL/SQL tables are unbounded.
Ever heard of dynamic arrays? (http://en.wikipedia.org/wiki/Dynamic_array)
> 2.Arrays must be dense, which means index numbers must be consecutive (1,2,3,4…),
but PL/SQL tables do not.
You are confusing arrays with associative arrays. Subscripting an array is done with a numeric index value. An associative array is where the subscript is a key (the name for a name-value pair) and not a numeric index.
See http://en.wikipedia.org/wiki/Arrays and http://en.wikipedia.org/wiki/Associative_array for details and definitions.
So-called PL/SQL "tables" (table of <something> indexed by varchar2) are nothing but an associative array. That is the correct term.
A "collection" is different in that it is a dynamic array of objects and is subscripted using an index.
Calling either these a table in PL/SQL, often lead the programmer to believe that this similar is in nature to a SQL table - and then they attempt to treat an associative array or collection like a SQL table with all kinds of negative consequences ito programming design, memory usage, scalability and performance.
IMO, whoever invented the term "PL/SQL table" is an idiot. It is utterly misleading in the context of using Oracle correctly.
Similar Messages
-
Hi all,
I have the following xml file (books1.xml):
<bookstore>
<book>
<BookID>1</BookID>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<BookID>2<BookID>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<BookID>3<BookID>
<title>XQuery Kick Start</title>
<author>James McGovern</author>
<year>2003</year>
<price>49.99</price>
</book>
<book>
<BookID>4<BookID>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In my Microsoft SQL Server 2012 Management Studio, I executed the following SQL Query code:
--XQuery w3schools example using books1.xml in C:\Temp folder
---SQL Query W3books Title
---9 March 2015
USE XML_XQUERY
GO
CREATE TABLE W3Books(
BookID INt Primary Key,
Title VARCHAR(30));
INSERT INTO W3Books (BookID, Title)
SELECT x.book.query('BookID'), value('.', 'INT'),
x.book.query('title'), value('.', 'VARCHAR(30)')
FROM (
SELECT CAST(x AS XML)
FROM OPENROWSET(
BULK 'C:\Temp\books1.xml',
SINGLE_BLOB) AS T(x)
) AS T(x)
CROSS APPLY x.nodes('W3Books/book') AS x(book);
SELECT BookID, Title
FROM W3Books;
I got the following error messages:
Msg 195, Level 15, State 10, Line 7
'value' is not a recognized built-in function name.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'AS'.
I don't know why I got the error of 'value' is not a recognized built-in function name. Please kindly help and tell me what is wrong in my code and how to correct the error.
Thanks, Scott Chang
P. S.
(1) I mimicked the xml file and SQL Qeury code of Import XML File to SQL Table in
http://pratchev.blogspot.com/2008/11/import-xml-file-to-sql-table.html. The xml file and the code of this sample worked in my SSMS 2012 program.
(2) I am learning the "CAST" and "CROSS APPLY" in the Create Instances of XML Data of Microsoft MSDN - it is very abstract to me.Hi Stan210, Thanks for your nice response.
I corrected my xml file as you pointed out.
I made some changes in some code statements of my SQLQueryW3BookTitle.sql as you instructed:
--XQuery w3schools example using books1.xml in C:\Temp folder
---SQL Query W3books Title
---10 March 2015
USE XML_XQUERY
GO
CREATE TABLE W3Books(
BookID INt Primary Key,
Title VARCHAR(30));
INSERT INTO W3Books (BookID, Title)
SELECT x.book.value('/BookID[1]', 'INT'),
x.book.value('/title[1]', 'VARCHAR(30)')
FROM (
SELECT CAST(x AS XML)
FROM OPENROWSET(
BULK 'C:\Temp\books1.xml',SINGLE_BLOB) AS T(x)
) AS T(x)
CROSS APPLY x.nodes('bookstore/book') AS x(book);
SELECT BookID, Title
FROM W3Books;
I executed my revised sql and I got the following Message and Results:
Msg 515, Level 16, State 2, Line 6
Cannot insert the value NULL into column 'BookID', table 'XML_XQUERY.dbo.W3Books'; column does not allow nulls. INSERT fails.
The statement has been terminated.
(0 row(s) affected)
Results:
BookID Title
I don't know why I just got the names of columns in Results and the "Cannot insert the value NULL into column 'BookID', table 'XML_XQUERY.dbo.W3Books'; column does not allow nulls, insert fails." in Messages. Please kindly help, advise me
how to correct the errors and respond again.
Many Thanks again,
Scott Chang -
Hi,
One my procedure's parameters is a PL/SQL table of id's (NUMBER) that the GUI sends it, based on the user's selections.
Now, I want to use the table's values in my select's where clause to return only the correct records.
However,
select ......
from ....
where id in (i_array_ids)
doesn't work of course, and my attempts of transfering the ids to a comma delimited list of numbers (as opposed to a lenghty varchar2 string) that could work between the ( ) have all failed.
ThanksAnd here's an example I gave with some more up-to-date syntax than in that old AskTom thread:
Re: DYNAMIC WHERE CLAUSE in PROCEDURE -
Inserting values from a PL SQL table to a database table
Hi,
Here is my dilemma.
I have values inserted to a pl sql table which I have gathered from a web page. Now I need to add these same values to a database table. I see the values as 1-'AA', 2='BB' etc.
I use the following code to insert to a outside table in the database and it seems to be crashing.
for i in app_table.first .. app_table.last loop
r_convention(i).priority_country_code:=app_table(i);
insert into test_countries
values (test_seq,tion(i).r_convention(i).priority_country_code);
commit;
end loop;
WHen I run this code I see the values. But it goes to the first value and then crashes and does not go through the
rest of the values. What am I missing here?
Thanks!Hi,
Why can't you directly insert into the table from the object type....
for i in app_table.first .. app_table.last loop
r_convention(i).priority_country_code:=app_table(i);
insert into test_countries
values (test_seq,app_table(i));
commit;
end loop;Can you give me your complete code, so that we can have a better picture..
Edited by: plsql dev on Sep 10, 2010 10:14 PM -
How to retrieve the values from PL/SQL table types.
Hi Every one,
I have the following procedure:
DECLARE
TYPE t1 IS TABLE OF emp%ROWTYPE
INDEX BY BINARY_INTEGER;
t t1;
BEGIN
SELECT *
BULK COLLECT INTO t
FROM emp;
END;
This procedure works perfectly fine to store the rows of employee in a table type. I am not able to retrieve the values from Pl/SQL table and display it using dbms_output.put_line command.
Can anybody help me please!!!!!
Thanks
Ahmed.You mean, you can't add this
for i in t.first..t.last loop
dbms_output.put_line(t(i).empno||' '||t(i).ename||' '||t(i).job);
end loop;or you can't add this
set serveroutput onor maybe, you are working in third party application where dbms_output is not applicable at all?
You see, not able like very similar it is not working - both are too vague...
Best regards
Maxim -
Value retrieve from PL/SQL Table
Hi all,
I am using PL/SQL Table to store the data. In table type p_table which I declared in a Package PCK.
I am storing the value as follows
pck.p_table(p_count)
Here p_count is the counter.
Values are storing the tables. Like
Counter Values
1 1
2 2
3 1.
But when I retrieved the values from the table like pck.p_table(p_counter_1).
Then for first Counter its giving me 0 value instead of 1.
Can you please tell me why this is happening.
Thanks in advance.Ok,here is the code.
if(nvl(values1,0) >= nvl(:cf_qty,0)) then
return (nvl(value1,0)-nvl(value2,0));
else
pck.p_count_first := pck.p_count_first + 1 ;
pck.p_FGI(pck.p_count_first):= nvl(value2,0) - nvl(value1,0);
end if;
Here for First counter value stored as 1,
Second value stored as 1.
When I am retriving the values. like
if (pck.p_FGI.count > 0) then
PCK.p_count_second := pck.p_count_second + 1 ;
v_total := pck.p_FGI(pck.p_count_second) VALUE3;
end if;
Here Value pck.p_FGI(pck.p_count_second) comes as 0 instead of 1.
Can you tell us why is this show value 0. -
How to get value from API which returns parameter in PL/SQL table?
Hello
I have below workflow API with returns info in PL/SQL table. I want to get value of 'USER_ORIG_SYSTEM_ID' column. How can i get that value in local variable.
Please help.
Thanks
Avalon
Wf_Directory.GetRoleInfo2
Syntax
procedure GetRoleInfo2
(Role in varchar2,
Role_Info_Tbl out wf_directory.wf_local_roles_tbl_type);
Description
Returns the following information about a role in a PL/SQL table:
• Name
• Display name
• Description
• Notification preference (’QUERY’, ’MAILTEXT’, ’MAILHTML’,
’MAILATTH’, ’MAILHTM2’, ’SUMMARY’, or, for Oracle
Applications only, ’SUMHTML’)
• Language
• Territory
• E–mail address
• Fax
• Status
• Expiration date
• Originating system
• Originating system ID
• Parent originating system
• Parent originating system ID
• Owner tag
• Standard Who columns
*******************************************************create a variable RoleXXX wf_directory.wf_local_roles_tbl_type;
call procedure GetRoleInfo2('TEST_ROLE',RoleXXX)
use RoleXXX.USER_ORIG_SYSTEM_ID -
Getting the value from a PL/SQL table
I have a view ( VIEW$TEMP ) that is building on runtime using FormsDDL.All its fields are varchar2 but the columns are not predefined.
In a Package (P) Specification I have define a PL/SQL Table like that:
type tt is table of view$temp%rowtype index by binary_integer
vTable tt;
I have opened a cursor and fetch the VIEW$TEMP into vTable.
Now I Need a function
F( vRow in number, vField varchar2 ) return varchar2
that take as arguments a row of the vTable and the Field name as varchar and returns to me the value in the table. This must be to the server(so I can not use copyto).
Any help will be helpful.Hi,
Excuse me, but, if, as I understood, the structure of the view changes at runtime, that would make the any stored procedure invalid, so that, before any execution, the given stored procedure would need to be compiled. Is it not so?
As for that function you need, you simply have to use dbms_sql (if that could be called simple).
Personally, I'd put the problem someway else and use different data structures and views.
Yet, please, don't get me wrong, I'd like to know more about this particular solution you are willing to implement.
Regards,
BD
null -
How to add hash table values to SQL Table using Powershell
Hi,
I have sharepoint list with four(column1, column2, column3,column4)columns.I am reading the list column values and adding to hashtable. Now I want to add values from hastable to SQL table with four(column1, column2, colum3,column4)columns using powershell.
I have written the following script for single column but I would like to know how to add values for multiple columns.
if(($key -eq "Column1") )
$SqlQuery = "INSERT INTO [TableName] ([Column1]) VALUES ('" + $HashTable.Item($key) +"')"
#Set new object to connect to sql database
$connection = new-object system.data.sqlclient.sqlconnection
$Connection.ConnectionString ="server=SQLServerName;database=SQLDBName;Integrated Security = True;"
$connection #List connection information
$connection.open() #Open Connection
$Cmd = New-Object System.Data.SqlClient.SqlCommand
$Cmd.CommandText = $SqlQuery
$Cmd.Connection = $connection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0]
$connection.Close()
Can anybody please help me out to accomplish the task? Any help would be greatly appreciated.
AA.Hi AOk2013,
Not knowledgable on PowercShell, based on my understanding on HashTable in Java, Some modification you can make in your code to achieve your requirement.
If the Keys in HashTable are "Column1","Column2","Column3","Column4", you can reference below.
if(($key -eq "Column1") ) #what is the purposed of this if ?
#$SqlQuery = "INSERT INTO [TableName] ([Term]) VALUES ('" + $HashTable.Item($key) +"')"
#specify the real column names in the table
$SqlQuery = "INSERT INTO [TableName] ([ColumnA],[ColumnB],[ColumnC],[ColumnD]) VALUES ('" + $HashTable.Item("Column1") +"','"+ $HashTable.Item("Column2") +"','"+$HashTable.Item("Column3") +"','"+$HashTable.Item("Column4") +"')"
#Set new object to connect to sql database
$connection = new-object system.data.sqlclient.sqlconnection
$Connection.ConnectionString ="server=SQLServerName;database=SQLDBName;Integrated Security = True;"
$connection #List connection information
$connection.open() #Open Connection
$Cmd = New-Object System.Data.SqlClient.SqlCommand
$Cmd.CommandText = $SqlQuery
$Cmd.Connection = $connection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0]
$connection.Close()
Since your question is regarding PowerShell, I would suggest you post it in a dedicated
PowerShell Forum. It is more appropriate and more experts will assist you.
If you have any feedback on our support, you can click
here.
Eric Zhang
TechNet Community Support -
SQL: Issue with running out of storage on server when running table-valued function
SQL Version: 2008 (not r2)
Problem: I'm getting the following error message when running a table-valued function:
Msg 1105, Level 17, State 2, Line 1
Could not allocate space for object 'dbo.SORT temporary run storage: 141072001204224' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files
to the filegroup, or setting autogrowth on for existing files in the filegroup.
Request: Could anyone tell me if there are modifications that I could make to my SQL code to avoid this storage issues?
Thanks,
....bob sutor
Code Facts:
The JCCD table is a large table 2MM records
The other tables in the JOINS are very small 15 records or less
SQL Function Code:
ALTER FUNCTION [dbo].[xcft_XAWP_GLBalance_JCCD_Detail]()
RETURNS @JCGLDetail TABLE
JCCo tinyint
, Job varchar(10)
, PostingSource varchar(10)
, CostToDate numeric(12,2)
, Phase varchar(20)
, EarnType smallint
, LiabilityType smallint
, CostType tinyint
, ControllingSetting varchar(30)
, GLAccountCharged varchar(20)
, DeptNum varchar(10)
, DeptDesc varchar(30)
, JCDC_CostType tinyint
, CostTypeGL_Open varchar(20)
, CostTypeGL_Closed varchar(20)
, JCDO_ExcludePR varchar(1)
, JCDO_Phase varchar(20)
, PhaseGL_Open varchar(20)
, PhaseGL_Closed varchar(20)
, JCDL_LiabType smallint
, LiabTypeGL_Open varchar(20)
, LiabTypeGL_Closed varchar(20)
, JCDE_EarnType smallint
, EarnTypeGL_Open varchar(20)
, EarnTypeGL_Closed varchar(20)
AS
BEGIN
DECLARE
@WIPMonthCurrent date
SET @WIPMonthCurrent = (Select TOP 1 WIPMonth FROM udxcWIPMonths WHERE ActiveWIPPeriod = 'Y')
INSERT INTO @JCGLDetail
JCCo
, Job
, PostingSource
, CostToDate
, Phase
, EarnType
, LiabilityType
, CostType
, DeptNum
, DeptDesc
, JCDC_CostType
, CostTypeGL_Open
, CostTypeGL_Closed
, JCDO_ExcludePR
, JCDO_Phase
, PhaseGL_Open
, PhaseGL_Closed
, JCDL_LiabType
, LiabTypeGL_Open
, LiabTypeGL_Closed
, JCDE_EarnType
, EarnTypeGL_Open
, EarnTypeGL_Closed
SELECT
JCCD.JCCo, JCCD.Job, JCCD.Source, sum(JCCD.ActualCost) AS CostToDate, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
, JCDM.Department, JCDM.Description
, JCDC.CostType AS JCDC_CostType, JCDC.OpenWIPAcct AS CostTypeGL_Open, JCDC.ClosedExpAcct AS CostTypeGL_Closed
, JCDO.ExcludePR AS JCDO_ExcludePR, JCDO.Phase AS JCDO_Phase, JCDO.OpenWIPAcct AS PhaseGL_Open, JCDO.ClosedExpAcct AS PhaseGL_Closed
, JCDL.LiabType AS JCDL_LiabType, JCDL.OpenBurdenAcct AS LiabTypeGL_Open, JCDL.ClosedBurdenAcct AS LiabTypeGL_Closed
, JCDE.EarnType AS JCDE_EarnType, JCDE.OpenLaborAcct AS EarnTypeGL_Open, JCDE.ClosedLaborAcct AS EarnTypeGL_Closed
FROM JCCD
LEFT JOIN JCJP ON JCCD.JCCo = JCJP.JCCo AND JCCD.Job = JCJP.Job
LEFT JOIN JCCM ON JCJP.JCCo = JCCM.JCCo AND JCJP.Contract = JCCM.Contract
LEFT JOIN JCDM ON JCCM.JCCo = JCDM.JCCo AND JCCM.Department = JCDM.Department
LEFT JOIN JCDC ON JCDM.JCCo = JCDC.JCCo AND JCDM.Department = JCDC.Department AND JCCD.CostType = JCDC.CostType
LEFT JOIN JCDE ON JCDM.JCCo = JCDE.JCCo AND JCDM.Department = JCDE.Department AND JCCD.EarnType = JCDE.EarnType
LEFT JOIN JCDO ON JCDM.JCCo = JCDO.JCCo AND JCDM.Department = JCDO.Department AND JCCD.Phase = JCDO.Phase
LEFT JOIN JCDL ON JCDM.JCCo = JCDL.JCCo AND JCDM.Department = JCDL.Department AND JCCD.LiabilityType = JCDL.LiabType
LEFT JOIN xcft_XAWP_FiscalPeriodCutoffs_ForWIPMonth() AS cutoffs ON JCCD.JCCo = cutoffs.GLCo
WHERE
JCCD.Mth <= cutoffs.FiscalYear_LastMonth
AND JCCD.Job IN(SELECT JobNum FROM budxcWIPData_SQL WHERE WIPMonth = @WIPMonthCurrent)
AND JCCD.JCCo IN(SELECT JCCo FROM JCCO WHERE udExcludeFromWIP <> 'Y' or udExcludeFromWIP IS NULL)
--AND LTRIM(RTRIM(JCCD.Job)) = '71-'
GROUP BY
JCCD.JCCo, JCCD.Job, JCCD.Source, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
, JCDM.Department, JCDM.Description
, JCDC.CostType, JCDC.OpenWIPAcct, JCDC.ClosedExpAcct
, JCDO.ExcludePR, JCDO.Phase, JCDO.OpenWIPAcct, JCDO.ClosedExpAcct
, JCDL.LiabType, JCDL.OpenBurdenAcct, JCDL.ClosedBurdenAcct
, JCDE.EarnType, JCDE.OpenLaborAcct, JCDE.ClosedLaborAcct
UPDATE @JCGLDetail
SET
ControllingSetting =
CASE WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'N' THEN 'PhaseOverride-PR Excluded'
WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'Y'
AND EarnType NOT IN(Select EarnType FROM JCDE WHERE JCDE.JCCo = JCCo AND JCDE.Department = DeptNum)
AND LiabilityType NOT IN(Select LiabType FROM JCDL WHERE JCDL.JCCo = JCCo AND JCDL.Department = DeptNum)
THEN 'PhaseOverride-PR Not Excluded'
WHEN EarnType = JCDE_EarnType THEN 'Earn Type Override'
WHEN LiabilityType = JCDL_LiabType THEN 'Liability Type Override'
ELSE 'Cost Type' END
UPDATE @JCGLDetail
SET
GLAccountCharged =
CASE WHEN ControllingSetting = 'PhaseOverride-PR Excluded' OR ControllingSetting = 'PhaseOverride-PR Not Excluded'
THEN PhaseGL_Open
WHEN ControllingSetting = 'Earn Type Override' THEN EarnTypeGL_Open
WHEN ControllingSetting = 'Liability Type Override' THEN LiabTypeGL_Open
ELSE CostTypeGL_Open END
RETURN
END
Bob Sutorwell, did you either restart the instance or add another tempdb file (no restart required) to let other transactions continue on the server.
or check if autogrowth was limited, change that to unlimnited , to the transactions conintue..
the function may be dumping the data on to tempdb, how much data are you excepting back...what are indexes on the tables
Hope it Helps!! -
JSP + MYSQL question: input form value into a SQL table
Hello,
I am writing some JSP code to read input information from a input form to write this information into a SQL field.
My problems are:
- how can i pass the input form information to other jsp file ? (like Getproperty of something like this)
- how can i move the content of any input information into a variable ? I mean something like this:
String a1;
username.value.of.the.input.field.in.forum_jsp = a1.in.addmessage_jsp;and then:
int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " + " usercode, " + " messagedate, " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");------
The SQL table looks like this:
stmt.executeUpdate("CREATE TABLE forummessages (messagecode int AUTO_INCREMENT PRIMARY KEY, usercode int, messagedate date, message char(255) not null)");My codes are:
forum.jsp - this one should pass the input information to addmessage.jsp
<%@ page contentType="text/html; charset=iso-8859-2" %>
<%@ page import="java.sql.*" %>
<%
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/mysql";
con = DriverManager.getConnection(url,"root", "");
stmt = con.createStatement();
String sql = "SELECT * FROM forummessages,users,bmwecode WHERE (forummessages.usercode=users.usercode) AND (users.bmwcode=bmwecode.bmwcode)";
ResultSet rs = stmt.executeQuery(sql);
%>
<html>
<head>
<title>JSP + MYSQL Teszt</title>
</head>
<body>
<a href="forum.jsp">Forum / Uj hozzaszolas</a>
<a href="userlist.jsp">Felhasznalok kilistazasa</a>
<a href="adduser.jsp">Felhasznalo hozzadasa</a>
<a href="deletemessage.jsp">Hozzaszolas torlese</a>
<br><br>
<form action="addmessage.jsp" method=post">
Felhasznalo:
<input type="text" name="username">
<br><br>
Hozzaszolas:
<input type="text" name="message">
<br><br>
<input type="submit" value="Uj hozzaszolas">
<br><br>
<table border="0">
<tr>
<th>messagecode</th>
<th>user</th>
<th>car type</th>
<th>message</th>
</tr>
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getInt("messagecode") %></td>
<td><%=rs.getString("username") %></td>
<td><%=rs.getString("bmwtype") %></td>
<td><%=rs.getString("message") %></td>
</tr>
<%
} // end while
%>
</table>
</body>
</html>
<%
} catch (Exception e) {
out.println("<font color=red><h3>Error:</h3></font>" + e);
e.printStackTrace();
} finally {
try {
if (stmt!=null) {
stmt.close();
if (con!=null) {
con.close();
} catch (Exception e) {
e.printStackTrace();
%> ----
addmessage.jsp
<%@ page contentType="text/html; charset=iso-8859-2" %>
<%@ page import="java.sql.*" %>
<%
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/mysql";
con = DriverManager.getConnection(url,"root", "");
stmt = con.createStatement();
int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " + " usercode, " + " messagedate, " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");
} catch (Exception e) {
out.println("<font color=red><h3>Hiba:</h3></font>" + e);
e.printStackTrace();
} finally {
try {
if (stmt!=null) {
stmt.close();
if (con!=null) {
con.close();
} catch (Exception e) {
e.printStackTrace();
%>
<a href="forum.jsp">Forum / Uj hozzaszolas</a>
<a href="userlist.jsp">Felhasznalok kilistazasa</a>
<a href="adduser.jsp">Felhasznalo hozzadasa</a>
<a href="deletemessage.jsp">Hozzaszolas torlese</a>
<br><br>---
Thank you for your help in advance.SELECT DISTINCT
hou.name
,poh.segment1 po_num
,pol.line_num po_line_num
,poh.currency_code
--,trunc(poh.creation_date) po_creation_date
,pol.cancel_flag
,msi.segment1 item_num
,pol.unit_price
,round(cost.item_cost,5)
,round((&p_rate * pol.unit_price),5) "CONVERSION"
,(cost.item_cost - round((&p_rate * pol.unit_price),5)) difference
,pov.vendor_name
FROM
po.po_headers_all poh
,po.po_lines_all pol
,po.po_vendors pov
,hr.hr_all_organization_units hou
,inv.mtl_system_items_b msi
,bom.cst_item_costs cost
WHERE
poh.po_header_id = pol.po_header_id
and pov.vendor_id = poh.vendor_id
and poh.org_id = hou.organization_id
and hou.organization_id = :p_operating_unit
and poh.currency_code = :p_currency
and poh.creation_date between :po_creation_date_from and :po_creation_date_to
and poh.type_lookup_code = 'BLANKET'
and msi.inventory_item_id = pol.item_id
and cost.INVENTORY_ITEM_ID = pol.ITEM_ID
--and (cost.item_cost - pol.unit_price) <> 0
and (cost.item_cost - round((&p_rate * pol.unit_price),5)) <> 0
and cost.organization_id = 1
and msi.organization_id = 1
and cost.cost_type_id = 3 --- Pending cost type
and nvl(upper (pol.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
and nvl(upper (poh.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
and nvl(pol.cancel_flag, 'N') = 'N'
and &p_rate user parameter
I want this p_rate to be passed as a user parameter. -
How to pass values and see outout of PL/SQL Tables, SYS_REFCURSORs?
I am new to SQL Developer (Version 3.0.02).
Our QC division wants to test stored procedures using SQL Developer.
I tried to test procedures with PL/SQL tables and SYS_REFCURSORS as input and output parameters.
When we run it by pressing the green arrow we get the Run PL/SQL window.
How can we:
- Put values to SYS_REFCURSOR and PL/SQL table type input parameters?
- How can we display SYS_REFCURSOR and PL/SQL table type output parameters?
All this time we were using SQL*Navigator. In Navigator the PL Tables and SYS_REFCURSORs outputs are shown in a nice grid.
Here, in SQL Developer, do we have to WRITE our own code to input and display these types of parameters????Hi Channa,
Yes in SQL Developer 3.0 you will have to write your own code to test out ref cursors.
I had created test harness scripts for all my procedures having ref cursors as parameters.
And I had to dbms_output all the values on the screen.
Probably a limitation of the SQL Developer 3.0 tool.
In case you come across different solution to this do let me know also.
Thanks,
Viju
blog: http://whizdba.wordpress.com -
Calculate the sum of values in excel file and import it to SQL table using SSIS
Hi,
Can some one help me how to do auto sum of columns in SQL table using SSIS
in SQL table the HRA , PF and Basic should not come, Only it should appear in basic pay as the sum of HRA , PF and Basic...RSingh, Thanks for the use
of derived column.
Instead of using record set i used OLE DB destination
its working Fine...
but now the issue is if i put a new records in excel file its replicating in SQL table
How to get only the changed values in excel to SQL table. -
SQL Server Multiple JOINS with Table Value Function - query never ends
I have a query with 4 joins using a table value function to get the data and when I execute it the query never ends.
Issue Details
- Table value function
CREATE FUNCTION [dbo].[GetIndicator]
@indicator varchar(50),
@refDate datetime
RETURNS
TABLE
AS
RETURN
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
- Query
DECLARE @RefDate datetime
SET @RefDate = '30 April 2014 23:59:59'
SELECT DISTINCT OTHERTABLE.Id As Id
FROM
GetIndicator('ID#1_0#INDICATOR_X',@RefDate) AS OTHERTABLE
JOIN GetIndicator('ID#1_0#INDICATOR_Y',@RefDate) AS YTABLE
ON OTHERTABLE.SomeId=YTABLE.SomeId
AND OTHERTABLE.DateOfEntry=YTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_Z',@RefDate) AS ZTABLE
ON OTHERTABLE.SomeId=ZTABLE.SomeId
AND OTHERTABLE.DateOfEntry=ZTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_W',@RefDate) AS WTABLE
ON OTHERTABLE.SomeId=WTABLE.SomeId
AND OTHERTABLE.DateOfEntry=WTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_A',@RefDate) AS ATABLE
ON OTHERTABLE.SomeId=ATABLE.SomeId
AND OTHERTABLE.DateOfEntry=ATABLE.DateOfEntry
Other details:
- SQL server version: 2008 R2
- If I execute the table function code outside the query, with the same args, the execution time is less the 1s.
- Each table function call return between 250 and 500 rows.Hi,
Calling function in general is a costly query. And definitely joining with a function 5 times in not an efficient one.
1. You can populate the results for all parameters in a CTE or table variable or temporary table and join (instead of funtion) for different parameters
2. Looks like you want fetch the IDs falling to different indicators for the same @Refdate. You can try something like this
WITH CTE
AS
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1, T4.Name
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
SELECT * FROM CTE WHERE Name = 'ID#1_0#INDICATOR_X' AND Name = 'ID#1_0#INDICATOR_Y' AND Name = 'ID#1_0#INDICATOR_Z' AND Name = 'ID#1_0#INDICATOR_W' AND Name = 'ID#1_0#INDICATOR_A' AND ReferenceDate = @RefDate.
Or you can even simplify more depends on your requirement.
Regards,
Brindha. -
Logic for inserting values from Pl/sql table
Hi I'm using Forms 6i and db 10.2.0.1.0
I am reading an xml file using text_io, and extracting the contents to Pl/sql table.
Suppose, the xml
<?xml version="1.0" encoding="UTF-8" ?>
<XML>
<File name="S2_240463.201002170044.Z">
<BookingEnvelope>
<SenderID>KNPROD</SenderID>
<ReceiverID>NVOCC</ReceiverID>
<Password>TradingPartners</Password>
</BookingEnvelope>
</File>
</XML>From this xml, i'm extracting contents to a table of records, say bk_arr, which look like
Tag Val
File name S2_240463.201002170044.Z
SenderID KNPROD
ReceiverID NVOCC
Password TradingPartnersAnd now from this i've to insert into table, say bk_det .
The tag may come in different order, sometimes some additional tags may also come in between,
So i cannot access it sequentially and insert like
Insert into bk_det(file,sndr,rcvr,pswd) values(bk_arr(1).val,bk_arr(2).val....)
The tag name is constant ir for sender id, it will always be SenderID , not something like sndrid or sndid etc..
So if i've to insert to senderid column, then i've to match the tag = SenderID, and take the value at that index in the array.
How best i can do this?
ThanksI am referring to how you are parsing the XML - as you can extract values from the XML by element name. And as the name is known, it's associated value can be inserted easily.
Basic example:
SQL> with XML_DATA as(
2 select
3 xmltype(
4 '<?xml version="1.0" encoding="UTF-8" ?>
5 <XML>
6 <File name="S2_240463.201002170044.Z">
7 <BookingEnvelope>
8 <SenderID>KNPROD</SenderID>
9 <ReceiverID>NVOCC</ReceiverID>
10 <Password>TradingPartners</Password>
11 </BookingEnvelope>
12 </File>
13 </XML>' ) as XML_DOM
14 from dual
15 )
16 select
17 extractValue( xml_dom, '/XML/File/@name' ) as FILENAME,
18 extractValue( xml_dom, '/XML/File/BookingEnvelope/SenderID' ) as SENDER_ID,
19 extractValue( xml_dom, '/XML/File/BookingEnvelope/ReceiverID' ) as RECEIVER_ID,
20 extractValue( xml_dom, '/XML/File/BookingEnvelope/Password' ) as PASSWORD
21 from xml_data
22 /
FILENAME SENDER_ID RECEIVER_I PASSWORD
S2_240463.201002170044.Z KNPROD NVOCC TradingPartners
SQL> Now this approach can be used as follows:
create or replace procedure AddFile( xml varchar2 ) is
begin
insert into foo_files(
filename,
sender_id,
receiver_id,
password
with XML_DATA as(
select
xmltype( xml ) as XML_DOM
from dual
select
extractValue( xml_dom, '/XML/File/@name' ),
extractValue( xml_dom, '/XML/File/BookingEnvelope/SenderID' ),
extractValue( xml_dom, '/XML/File/BookingEnvelope/ReceiverID' ),
extractValue( xml_dom, '/XML/File/BookingEnvelope/Password' )
from xml_data;
end;
/No need for a fantasy called PL/SQL "+tables+".
Maybe you are looking for
-
Failed to install CM Client on computers located in untrusted site
Hello, I deploy System Center 2012 SP1 Configuration Manager and successfully push client to Desktops/Servers, I read in TechNet that this scenario is supported: "The client is on a domain computer that does not have a two-way forest trust with the s
-
TS1424 Albums Vs Compilations in itunes
Certain albums that i have imported into itunes from my CD collection have been included in Compilations instead of Albums. This mean that these albums do no appear when i search by Artist. Is it possible to re-categorise these as Albums?
-
Import시 character set 문제, OORA-01435, IMP-00008 에러에 의해 중단되었습니다. 조언을 부탁합니다.
안녕하세요, 아래와 같이 import를 하려고 하는데 에러가 나면서 중단되었습니다. C:\temp>imp userid=system/1234 file=c:\temp\usr_lms2-TS_LMS_DEV_D1.dmp FULL=y 에러메시지는 아래와 같습니다. 참고로, export 했던 어떤 database에는 usr_lms2 계정이 있었고, import하려는 이 database에는 그 계정이 없어서 usr_lms2 계정을 생성하고 import를 실행
-
Options when adjusting hue/saturation
Using a Hue/Saturation Adjustment layer: 1. Do you ideally want to go through and adjust Reds, Yellows, greens, Cyans, Magentas individually? Are final results not as good if you just adjust the Master by itself? 2. Looking at my imgage, I do not see
-
.mac and personal domain question
I'm sure this has been addressed several times, although, I can't find the answer in a quick search... I set-up a personal domain on my account. I have several websites going in iWeb, however. Can I still host my personal domain on .mac, but still pu