Select from refcursor in PL/SQL pkg
Greetings,
I would like to be able to return a set of values in some sort of temporary structure(temp table, cursor..it don't matter) to be used as part of the WHERE clause in several other queries. Normally I would just use a query in each of the other queries like so:
SELECT a.1, a.2, a.3
FROM bigtbl a,
(SELECT x, y, z FROM criteriakeys)b
WHERE a.x = b.x AND
a.y = b.y AND
a.z = b.z
SELECT c.1, c.2, c.3
FROM bigrtbl c,
(SELECT x, y, z FROM criteriakeys)b
WHERE c.x = b.x AND
c.y = b.y AND
c.z = b.z
etc...
The problem is that the query(b in the above) is a complex one that will be hitting against a very large number of records. I understand that temp tables are not supposed to be needed in Oracle. I haven't in 10 years and until now did not even know that it was possible. So I would use a refcursor BUT I don't know how to use a refcursor as the base of a SELECT something like:
rc ref cursor;
getcriteriakeys(rc); -- send in a refcursor and come back full of records
SELECT a.1, a.2, a.3
FROM bigtbl a,
(SELECT x, y, z FROM rc)b
WHERE a.x = b.x AND
a.y = b.y AND
a.z = b.z
This seems, to me anyway, to be an obvious use of refcursor but I cannot find any mention of it either way. I can infer from the way refcursors are used that they only send back a row at a time. This is nice but would produce sub-optimal results.
Any suggestions or comments will be welcome.
Thanks
If query b is really complex, takes a "while" to execute (long enough that you don't want to do it more than once in a set of statements), and not straightforward as in your example, one option would be to load the results of query b into a global temporary table - and then join to that table in your successive query.
A ref cursor is not really applicable in this context.
The routine would be something like:
insert into gtt
select * from ...; -- complex query b
-- the selects below would either be cursor for loops or single row select/into
-- (couldn't tell from your sample)
select *
from a, gtt
where a.x = gtt.x
and ...;
select *
from b, gtt
where b.x = gtt.x
and ...;
Similar Messages
-
Urgent. . .About select * from multiple tables
When I am doing the 'Select * from tables' in JSP,
sql = dbconn.prepareStatement("SELECT * FROM protein WHERE protein_id ='"+p_i+"'");
It works, because I only select one table.
Then, I change to select from two tables,
sql = dbconn.prepareStatement("SELECT * FROM protein, fuses WHERE protein_id ='"+p_i+"'");
It also works properly?
However, When I do like:
sql = dbconn.prepareStatement("SELECT * FROM protein, protein_taxa WHERE protein_id ='"+p_i+"'");
It doesn?t work.
So, I think it might be the problem that there is a common column 'protein_id' in both tables, although protein_taxa.protein_id is a foreign key of protein.protein_id. Therefore, I can select two table protein, fuses which have different columns, but no way to select the table they have same name column.
However, it?s essential for me to select all the data from the database. Any way I could achieve it? Thanks a lot!!SELECT *
FROM protein, protein_taxa
WHERE protein.protein_id = 'a_protein_id'
and protein.protein_id = protein_taxa.protein_id It would also be good to indicate which fields you want on the select clause. This will liberate the server to return two fields with the same name.
SELECT protein.protein_id, protein.name, protein_taxa.taxa /* ??? */
FROM protein, protein_taxa
WHERE protein.protein_id = 'a_protein_id'
and protein.protein_id = protein_taxa.protein_id -
Hi All
below query giving me error in query generator but working well in Sql server.
error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to select from. '' (SWEI)
Select
T1.U_grp01 As 'BA',T3.DocDate As 'Posting Date',Month(T3.DocDate) As 'PostMonth',Year(T3.DocDate) As 'PostYear',
'AR Invoice' As 'Type',T3.DocNum As 'Doc No',T3.CardCode As 'Cust. Code',T3.CardName As 'Cust. Name',T5.SlpName As 'Sale Emp. Name',
T4.IndustryC As 'Channel Type',T6.CityB As 'BillToCity',T7.Name As 'BillToState',T6.CityS As 'ShipToCity',T8.Name As 'ShipToState',
T4.U_Une_Zone As 'Zone',
T2.ItmsGrpNam As 'L1',T0.LineNum As 'Row No',T0.ItemCode As 'ItemCode',T0.Dscription As 'Item Name',t0.whscode,
T0.Quantity As 'Quantity',T0.StockPrice As 'COGS Price',IsNull(Sum(T0.Quantity * T0.StockPrice),0) As 'COGS Value',T0.VatSum As 'Tax Amount',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then T0.PriceBefDi Else (T0.PriceBefDi * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then T0.INMPrice Else (T0.INMPrice * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then Sum(T0.Quantity * T0.INMPrice) Else Sum(T0.Quantity * T0.INMPrice * T0.Rate) End) Else T0.LineTotal End) ,0) As 'Sales Value',t9.linetotal as 'Freight',
T3.DocType As 'DocType',
(SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
FROM INV4
WHERE INV4.StaType = -90
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum) AS 'BED',
(SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
FROM INV4
WHERE INV4.StaType = -60
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum) AS 'Cess',
(SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
FROM INV4
WHERE INV4.StaType = 9
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum) AS 'HeCess',
(SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
FROM INV4
WHERE (INV4.StaType = 1 or inv4.staType = 8)
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum) AS 'VAT',
(SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
FROM INV4
WHERE INV4.StaType = 8
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum) AS 'CST'
From INV1 T0
Left Join OITM T1 On T1.ItemCode=T0.ItemCode
Left Join OITB T2 On T2.ItmsGrpCod=T1.ItmsGrpCod
Left Join OINV T3 On T3.DocEntry=T0.DocEntry
Left Join OCRD T4 On T4.CardCode=T3.CardCode
Left Join OSLP T5 On T5.SlpCode=T4.SlpCode
Left Join INV12 T6 On T6.DocEntry=T0.DocEntry
Left Join OCST T7 On T7.Code=T6.StateB and T7.Country='IN'
Left Join OCST T8 On T8.Code=T6.StateS and T8.Country='IN'
left join inv3 t9 on t9.docentry = t3.docentry
WHERE T3.[DocDate] >= [%0] and T3.[DocDate] <= [%1] and t3.U_UNE_GCAT = '2'
Group By T1.U_grp01,T3.DocEntry,T3.DocNum,T3.DocDate,T0.LineNum,T3.CardCode,T3.CardName,T5.SlpName,T4.IndustryC,T4.U_Une_Zone,
T6.CityB,T7.Name,T6.CityS,T8.Name,T0.VatSum,T0.Currency,T0.Rate,T3.DocType,T0.Price,T0.LineTotal,
T2.ItmsGrpNam,T0.ItemCode,T0.Dscription,T0.StockPrice,T0.INMPrice,T0.PriceBefDi,T0.Quantity,t9.linetotal,t0.WhsCode
Union All
Select
T1.U_grp01 As 'BA',T3.DocDate As 'Posting Date',Month(T3.DocDate) As 'PostMonth',Year(T3.DocDate) As 'PostYear',
'AR Invoice' As 'Type',T3.DocNum As 'Doc No',T3.CardCode As 'Cust. Code',T3.CardName As 'Cust. Name',T5.SlpName As 'Sale Emp. Name',
T4.IndustryC As 'Channel Type',T6.CityB As 'BillToCity',T7.Name As 'BillToState',T6.CityS As 'ShipToCity',T8.Name As 'ShipToState',
T4.U_Une_Zone As 'Zone',
T2.ItmsGrpNam As 'L1',T0.LineNum As 'Row No',T0.ItemCode As 'ItemCode',T0.Dscription As 'Item Name',t0.whscode,
T0.Quantity As 'Quantity',T0.StockPrice As 'COGS Price',IsNull(Sum(T0.Quantity * T0.StockPrice),0) As 'COGS Value',T0.VatSum As 'Tax Amount',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then T0.PriceBefDi Else (T0.PriceBefDi * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then T0.INMPrice Else (T0.INMPrice * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
IsNull((Case When T3.DocType='I' Then (Case When T0.Currency = 'INR' Then Sum(T0.Quantity * T0.INMPrice) Else Sum(T0.Quantity * T0.INMPrice * T0.Rate) End) Else T0.LineTotal End) ,0) As 'Sales Value',t9.linetotal as 'Freight',
T3.DocType As 'DocType',
(SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
FROM rin4
WHERE rin4.StaType = -90
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum) AS 'BED',
(SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
FROM rin4
WHERE rin4.StaType = -60
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum) AS 'Cess',
(SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
FROM rin4
WHERE rin4.StaType = 9
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum) AS 'HeCess',
(SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
FROM rin4
WHERE (rin4.StaType = 1 or rin4.staType = 8)
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum) AS 'VAT',
(SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
FROM rin4
WHERE rin4.StaType = 8
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum) AS 'CST'
From rin1 T0
Left Join OITM T1 On T1.ItemCode=T0.ItemCode
Left Join OITB T2 On T2.ItmsGrpCod=T1.ItmsGrpCod
Left Join Orin T3 On T3.DocEntry=T0.DocEntry
Left Join OCRD T4 On T4.CardCode=T3.CardCode
Left Join OSLP T5 On T5.SlpCode=T4.SlpCode
Left Join rin12 T6 On T6.DocEntry=T0.DocEntry
Left Join OCST T7 On T7.Code=T6.StateB and T7.Country='IN'
Left Join OCST T8 On T8.Code=T6.StateS and T8.Country='IN'
left join rin3 t9 on t9.docentry = t3.docentry
WHERE T3.[DocDate] >= [%0] and T3.[DocDate] <= [%1] and t3.U_UNE_GCAT = '2'
Group By T1.U_grp01,T3.DocEntry,T3.DocNum,T3.DocDate,T0.LineNum,T3.CardCode,T3.CardName,T5.SlpName,T4.IndustryC,T4.U_Une_Zone,
T6.CityB,T7.Name,T6.CityS,T8.Name,T0.VatSum,T0.Currency,T0.Rate,T3.DocType,T0.Price,T0.LineTotal,
T2.ItmsGrpNam,T0.ItemCode,T0.Dscription,T0.StockPrice,T0.INMPrice,T0.PriceBefDi,T0.Quantity,t9.linetotal,t0.WhsCode
Thanks in AdvanceHi deepak..
try this
/* SELECT FROM OSRT P1 */
DECLARE @FROM AS DATE
/* WHERE */
SET @FROM = /* P1.FromDate */ '[%1]'
/* SELECT FROM OSRT P2 */
DECLARE @TO AS DATE
/* WHERE */
SET @TO = /* P2.ToDate */ '[%2]';
SELECT T1.U_grp01 AS 'BA',
T3.DocDate AS 'Posting Date',
MONTH(T3.DocDate) AS 'PostMonth',
YEAR(T3.DocDate) AS 'PostYear',
'AR Invoice' AS 'Type',
T3.DocNum AS 'Doc No',
T3.CardCode AS 'Cust. Code',
T3.CardName AS 'Cust. Name',
T5.SlpName AS 'Sale Emp. Name',
T4.IndustryC AS 'Channel Type',
T6.CityB AS 'BillToCity',
T7.Name AS 'BillToState',
T6.CityS AS 'ShipToCity',
T8.Name AS 'ShipToState',
T4.U_Une_Zone AS 'Zone',
T2.ItmsGrpNam AS 'L1',
T0.LineNum AS 'Row No',
T0.ItemCode AS 'ItemCode',
T0.Dscription AS 'Item Name',
t0.whscode,
T0.Quantity AS 'Quantity',
T0.StockPrice AS 'COGS Price',
ISNULL(SUM(T0.Quantity * T0.StockPrice), 0) AS 'COGS Value',
T0.VatSum AS 'Tax Amount',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN T0.PriceBefDi
ELSE (T0.PriceBefDi * T0.Rate)
END
ELSE T0.Price
END
0
) AS 'Sales Price',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN T0.INMPrice
ELSE (T0.INMPrice * T0.Rate)
END
ELSE T0.Price
END
0
) AS 'Sales Price',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN SUM(T0.Quantity * T0.INMPrice)
ELSE SUM(T0.Quantity * T0.INMPrice * T0.Rate)
END
ELSE T0.LineTotal
END
0
) AS 'Sales Value',
t9.linetotal AS 'Freight',
T3.DocType AS 'DocType',
SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
FROM INV4
WHERE INV4.StaType = -90
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum
) AS 'BED',
SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
FROM INV4
WHERE INV4.StaType = -60
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum
) AS 'Cess',
SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
FROM INV4
WHERE INV4.StaType = 9
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum
) AS 'HeCess',
SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
FROM INV4
WHERE (INV4.StaType = 1 OR inv4.staType = 8)
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum
) AS 'VAT',
SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
FROM INV4
WHERE INV4.StaType = 8
AND INV4.DocEntry = T3.DocEntry
AND INV4.LineNum = T0.LineNum
) AS 'CST'
FROM INV1 T0
LEFT JOIN OITM T1
ON T1.ItemCode = T0.ItemCode
LEFT JOIN OITB T2
ON T2.ItmsGrpCod = T1.ItmsGrpCod
LEFT JOIN OINV T3
ON T3.DocEntry = T0.DocEntry
LEFT JOIN OCRD T4
ON T4.CardCode = T3.CardCode
LEFT JOIN OSLP T5
ON T5.SlpCode = T4.SlpCode
LEFT JOIN INV12 T6
ON T6.DocEntry = T0.DocEntry
LEFT JOIN OCST T7
ON T7.Code = T6.StateB
AND T7.Country = 'IN'
LEFT JOIN OCST T8
ON T8.Code = T6.StateS
AND T8.Country = 'IN'
LEFT JOIN inv3 t9
ON t9.docentry = t3.docentry
WHERE T3.[DocDate] >= @FROM
AND T3.[DocDate] <= @TO
AND t3.U_UNE_GCAT = '2'
GROUP BY
T1.U_grp01,
T3.DocEntry,
T3.DocNum,
T3.DocDate,
T0.LineNum,
T3.CardCode,
T3.CardName,
T5.SlpName,
T4.IndustryC,
T4.U_Une_Zone,
T6.CityB,
T7.Name,
T6.CityS,
T8.Name,
T0.VatSum,
T0.Currency,
T0.Rate,
T3.DocType,
T0.Price,
T0.LineTotal,
T2.ItmsGrpNam,
T0.ItemCode,
T0.Dscription,
T0.StockPrice,
T0.INMPrice,
T0.PriceBefDi,
T0.Quantity,
t9.linetotal,
t0.WhsCode
UNION ALL
SELECT T1.U_grp01 AS 'BA',
T3.DocDate AS 'Posting Date',
MONTH(T3.DocDate) AS 'PostMonth',
YEAR(T3.DocDate) AS 'PostYear',
'AR Invoice' AS 'Type',
T3.DocNum AS 'Doc No',
T3.CardCode AS 'Cust. Code',
T3.CardName AS 'Cust. Name',
T5.SlpName AS 'Sale Emp. Name',
T4.IndustryC AS 'Channel Type',
T6.CityB AS 'BillToCity',
T7.Name AS 'BillToState',
T6.CityS AS 'ShipToCity',
T8.Name AS 'ShipToState',
T4.U_Une_Zone AS 'Zone',
T2.ItmsGrpNam AS 'L1',
T0.LineNum AS 'Row No',
T0.ItemCode AS 'ItemCode',
T0.Dscription AS 'Item Name',
t0.whscode,
T0.Quantity AS 'Quantity',
T0.StockPrice AS 'COGS Price',
ISNULL(SUM(T0.Quantity * T0.StockPrice), 0) AS 'COGS Value',
T0.VatSum AS 'Tax Amount',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN T0.PriceBefDi
ELSE (T0.PriceBefDi * T0.Rate)
END
ELSE T0.Price
END
0
) AS 'Sales Price',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN T0.INMPrice
ELSE (T0.INMPrice * T0.Rate)
END
ELSE T0.Price
END
0
) AS 'Sales Price',
ISNULL(
CASE
WHEN T3.DocType = 'I' THEN (
CASE
WHEN T0.Currency = 'INR' THEN SUM(T0.Quantity * T0.INMPrice)
ELSE SUM(T0.Quantity * T0.INMPrice * T0.Rate)
END
ELSE T0.LineTotal
END
0
) AS 'Sales Value',
t9.linetotal AS 'Freight',
T3.DocType AS 'DocType',
SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
FROM rin4
WHERE rin4.StaType = -90
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum
) AS 'BED',
SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
FROM rin4
WHERE rin4.StaType = -60
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum
) AS 'Cess',
SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
FROM rin4
WHERE rin4.StaType = 9
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum
) AS 'HeCess',
SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
FROM rin4
WHERE (rin4.StaType = 1 OR rin4.staType = 8)
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum
) AS 'VAT',
SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
FROM rin4
WHERE rin4.StaType = 8
AND rin4.DocEntry = T3.DocEntry
AND rin4.LineNum = T0.LineNum
) AS 'CST'
FROM rin1 T0
LEFT JOIN OITM T1
ON T1.ItemCode = T0.ItemCode
LEFT JOIN OITB T2
ON T2.ItmsGrpCod = T1.ItmsGrpCod
LEFT JOIN [dbo].[Orin] T3
ON T3.DocEntry = T0.DocEntry
LEFT JOIN OCRD T4
ON T4.CardCode = T3.CardCode
LEFT JOIN OSLP T5
ON T5.SlpCode = T4.SlpCode
LEFT JOIN rin12 T6
ON T6.DocEntry = T0.DocEntry
LEFT JOIN OCST T7
ON T7.Code = T6.StateB
AND T7.Country = 'IN'
LEFT JOIN OCST T8
ON T8.Code = T6.StateS
AND T8.Country = 'IN'
LEFT JOIN rin3 t9
ON t9.docentry = t3.docentry
WHERE T3.[DocDate] >= @FROM
AND T3.[DocDate] <= @TO
AND t3.U_UNE_GCAT = '2'
GROUP BY
T1.U_grp01,
T3.DocEntry,
T3.DocNum,
T3.DocDate,
T0.LineNum,
T3.CardCode,
T3.CardName,
T5.SlpName,
T4.IndustryC,
T4.U_Une_Zone,
T6.CityB,
T7.Name,
T6.CityS,
T8.Name,
T0.VatSum,
T0.Currency,
T0.Rate,
T3.DocType,
T0.Price,
T0.LineTotal,
T2.ItmsGrpNam,
T0.ItemCode,
T0.Dscription,
T0.StockPrice,
T0.INMPrice,
T0.PriceBefDi,
T0.Quantity,
t9.linetotal,
t0.WhsCode
rgds
Kennedy -
Unable To Select From SQL Server table with more than 42 columns
I have set up a link between a Microsoft SQL Server 2003 database and an Oracle 9i database using Heterogeneous Services (HSODBC). It's working well with most of the schema I'm selecting from except for 3 tables. I don't know why. The common denominator between all the tables is that they all have at least 42 columns each, two have 42 columns, one has 56, and the other one, 66. Two of the tables are empty, one has almost 100k records, one has has 170k records. So I don't think the size of the table matters.
Is there a limitation on the number of table columns you can select from through a dblink? Even the following statement errors out:
select 1
from "Table_With_42_Cols"@sqlserver_db
The error message I get is:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message [Generic Connectivity Using ODBC]
ORA-02063: preceding 2 lines from sqlserver_db
Any assistance would be greatly appreciated. Thanks!Not a very efficient and space friendly design to do name-value pairs like that.
Other methods to consider is splitting those 1500 parameters up into groupings of similar parameters, and then have a table per group.
Another option would be to use "vertical table partitioning" (as oppose to the more standard horizontal partitionining provided by the Oracle partition option) - this can be achieved (kind of) in Oracle using clusters.
Sooner or later this name-value design is going to bite you hard. It has 1500 rows where there should be only 1 row. It is not scalable.. and as you're discovering, it is unnatural to use. I would rather change that table and design sooner than later. -
SQL> create type string_table is table of varchar(100);
2 /
Type created.
declare
v_names string_table := string_table();
begin
v_names.EXTEND(3);
v_names(1) := 'name1';
v_names(2) := 'name2';
v_names(3) := 'name3';
dbms_output.put_line(v_names(1));
dbms_output.put_line(v_names(2));
dbms_output.put_line(v_names(3));
dbms_output.put_line(v_names.COUNT());
select * from table(v_names);
end;
select * from table(v_names);
ERROR at line 12:
ORA-06550: line 12, column 7:
PLS-00428: an INTO clause is expected in this SELECT statementselect * from table(v_names);
I guess ,here you were trying to put the content of the NT into another NT, or just trying to print it.
But, I don't think INTO Clause is mandatory here.
Please check your modified code (w/o INTO) and the output :
DECLARE
TYPE string_table IS TABLE OF VARCHAR (100);
v_names string_table := string_table ();
v_test string_table := string_table ();
BEGIN
v_names.EXTEND (3);
v_names (1) := 'name1';
v_names (2) := 'name2';
v_names (3) := 'name3';
DBMS_OUTPUT.put_line ('Old collection - '||v_names (1));
DBMS_OUTPUT.put_line ('Old collection - '||v_names (2));
DBMS_OUTPUT.put_line ('Old collection - '||v_names (3));
DBMS_OUTPUT.put_line ('Old collection - '||v_names.COUNT ());
DBMS_OUTPUT.put_line (CHR(10));
/* SELECT * FROM TABLE (v_names); */
v_test := v_names;
DBMS_OUTPUT.put_line ('New collection -- '||v_test (1));
DBMS_OUTPUT.put_line ('New collection -- '||v_test (2));
DBMS_OUTPUT.put_line ('New collection -- '||v_test (3));
DBMS_OUTPUT.put_line ('New collection -- '||v_test.COUNT ());
DBMS_OUTPUT.put_line (CHR(10));
/* Printing using FOR LOOP */
FOR i IN v_test.FIRST..v_test.LAST
LOOP
DBMS_OUTPUT.put_line ('In FOR Loop --- '||v_test (i));
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error ' ||SQLERRM|| DBMS_UTILITY.format_error_backtrace);
END;gives o/p :
Old collection - name1
Old collection - name2
Old collection - name3
Old collection - 3
New collection -- name1
New collection -- name2
New collection -- name3
New collection -- 3
In FOR Loop --- name1
In FOR Loop --- name2
In FOR Loop --- name3Refer this link -- http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/tuning.htm#CIHGGBGF
Edited by: ranit B on Dec 26, 2012 2:29 PM
-- code modified
Edited by: ranit B on Dec 26, 2012 2:45 PM
-- code 'again' updated -- FOR LOOP added -
Error while executing SQL query -' Must Specify Table to select from'
Hi all,
While executing query using query generator
it shows error message
[Microsoft][SQL Native Client][SQL Server]Must specify table to select from.
2). [Microsoft][SQL Nativ
SELECT T1.ItemCode, T1.Dscription AS 'Item Description', T1.Quantity, T1.Price, T1.LineTotal,
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-90 AND T1.LineNum=T2.LineNum) as 'BEDAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-60 AND T1.LineNum=T2.LineNum) as 'ECSAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=7 AND T1.LineNum=T2.LineNum) as 'HECSAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=1 AND T1.LineNum=T2.LineNum) as 'VATAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=4 AND T1.LineNum=T2.LineNum) as 'CSTAmt'
FROM dbo.[OPCH] T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN PCH4 T2 ON T2.DocEntry=T0.DocEntry
WHERE T0.DocDate >='[%0]' AND T0.DocDate <='[%1]' AND T0.DocType = 'I'
GROUP BY T1.ItemCode,T1.Dscription,T1.Quantity, T1.Price, T1.LineTotal,T0.DocEntry,T1.DocEntry,T1.LineNum,T2.LineNum
It's executing fine in MS SQL Server Studio Management.
Please give y'r ideas to solve the problem.
Jeyakanthantry this, it works fine in my B1:
SELECT T1.ItemCode, T1.Dscription AS 'Item Description', T1.Quantity, T1.Price, T1.LineTotal,
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-90 AND T1.LineNum=T2.LineNum) as 'BEDAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=-60 AND T1.LineNum=T2.LineNum) as 'ECSAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=7 AND T1.LineNum=T2.LineNum) as 'HECSAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=1 AND T1.LineNum=T2.LineNum) as 'VATAmt',
(Select SUM(T2.TaxSum) From PCH4 T2 Where T0.DocEntry=T2.DocEntry AND T2.staType=4 AND T1.LineNum=T2.LineNum) as 'CSTAmt'
FROM dbo.OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN PCH4 T2 ON T2.DocEntry=T0.DocEntry
WHERE T0.DocDate >='[%0]' AND T0.DocDate <='[%1]' AND T0.DocType = 'I'
GROUP BY T1.ItemCode,T1.Dscription,T1.Quantity, T1.Price, T1.LineTotal,T0.DocEntry,T1.DocEntry,T1.LineNum,T2.LineNum
B1 don't like brackets!
Regards -
Selecting from a SQL Server 2005 with long column names ( 30 chars)
Hi,
I was able to set up a db link from Oracle 11.2.0.1 to SQL Server 2005 using DG4ODBC.
My problem is that some column names in the Sql Server are longer than 30 chars and trying to select them gives me the ORA-00972: identifier is too long error.
If I omit these columns the select succeeds.
I know I can create a view in the sql server and query it instead of the original table, but I was wondering if there's a way to overcome it with sql.
My select looks like this:
select "good_column_name" from sometable@sqlserver_dblink -- this works
select "good_column_name","very_long_column_name>30 chars" from sometable@sqlserver_dblink -- ORA-00972ThanksI tried creating a view with shorter column names but selecting from the view still returns an error.
create view v_Boards as (select [9650_BoardId] as BoardId, [9651_BoardType] as BoardType, [9652_HardwareVendor] as
HardwareVendor, [9653_BoardVersion] as BoardVersion, [9654_BoardName] as BoardName, [9655_BoardDescription] as BoardDescription,
[9656_SlotNumber] as SlotNumber, [9670_SegmentId] as SegmentId, [MasterID] as MasterID, [9657_BoardHostName] as BoardHostName,
[9658_BoardManagementUsername] as BoardManagementUsername, [9659_BoardManagementPassword] as BoardManagementPassword,
[9660_BoardManagementVirtualAddress] as BoardManagementVirtualAddress, [9661_BoardManagementTelnetLoginPrompt] as
MANAGEMENTTELNETLOGINPROMPT, [9662_BoardManagementTelnetPasswordPrompt] as MANAGEMENTTELNETPASSPROMPT,
[9663_BoardManagementTelnetCommandPrompt] as MANAGEMENTTELNETCOMMANDPROMPT FROM Boards)performing a select * from this view in sqlserver works and show the short column names
this is the error i'm getting for performing a select * from v_boards@sqlserver_dblink
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Microsoft][SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetLoginProm'. {42S22,NativeErr = 207}[Microsoft]
[SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetPasswordP'. {42S22,NativeErr = 207}[Microsoft][SQL Native
Client][SQL Server]Invalid column name 'BoardManagementTelnetCommandPr'. {42S22,NativeErr = 207}[Microsoft][SQL Native Client][SQL
Server]Statement(s) could not be prepared. {42000,NativeErr = 8180}
ORA-02063: preceding 2 lines from sqlserver_dblinkI also tried replacing the * with specific column names but it fails on the columns that have a long name (it doesn't recognize the short names from the view)
what am I doing wrong?
Edited by: Pyrocks on Dec 22, 2010 3:58 PM -
How to Select from Oracle 8i database and insert into Sql Server 2005 datab
Hi how to Select from Oracle 8i and insert into Sql Server 2005.
Source db as Oracle 8i
Target db as Sql Server 2005.
I need to select one table data from Oracle 8i & insert into Sql Server 2005
ThanksThanks Khan..
Is there is any query (OPENQUERY) available for that?
Regards.. -
Dynamic parameter selection from infoview not storing the sql password
We are having the problem of dynamic parameter selection from infoview not storing the sql password as it does for the actual report. We are using Crystal Reports XI Release 2 version 11.5.3.438 (Not sure of SP level, asked in separate thread).
To be more specific.
We have created a report that dynamically populates the parameters of the report by pulling the records from the Informix sql database and allowing selection from there.
In the Central Management Console for the report object we have set as follows:
Process - Database:
Use original database logon information from the report - the sql username and pw etc
Use same database logon as when report is run
Process - Parameters
In selecting a default selection there is the option to put in the sql password, however, this does not stick and clears after update.
As such the end result is that every time this report is run from infoview and a user chooses a parameter (there are 5), crystal goes through some timeout for about a minute or so and then requests the sql password, if a user then selects the next parameter, the same timeout and password dialog appears.
We need the crystal report to handle to the sql password for fetching the parameters as well as for the database section of running the report, however, the parameters insists on the end user always putting the password in.
This is 100% replicatable on our system.
Any way that we can fix this?
Will an update fix this issue? If so could you please advise which one?
ThanksHi,
I am having the exact same problem. Any help?
And what does "Use same database logon as when report is run" mean? For me that would be that no prompt is needed for getting values in a dynamic parameter...
Regards
Magnus -
Unable to select from Oracle to SQL Server
Hi group,
I am having some issues while trying to select a SQL Server table from Oracle.
Oracle version is 10.2.0.4 64 bits on Solaris 64 bits too, this database connects to Oracle Client (with dg4odbc) on Windows 64 bits installation (Oracle Cient version is 11.2.0.1), and finally SQL Server is running right on a Windows 2000 server on 32 bits.
When I try to select the SQL Server table from Oracle, I am getting the next error message:
SQL> select * from "interfaceinventarios"@TEST;
select * from "interfaceinventarios"@TEST
ERROR at line 1:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from TEST
tnsping TEST is working well.
On the Windows Server (64 bits) I used: C:\Windows\System32\odbcad.exe executable to create the datasource.
Any help or advice will be really appreciated.
Thanks in advance.
Kind regards,
FranciscoHi,
If your server is of 64 bit then the oracle client needs to be 64 bit. -
PL/SQL: ORA-22992: cannot use LOB locators selected from remote tables
Dear ALL,
My O/S is Redhatlinux 5.2 and i had Migrated my Oracle databse to 11g2. But after that while i am retrieving records through dblinks from one of my other Oracle 9.2.0.8 databse it's throwing the error : PL/SQL: ORA-22992: cannot use LOB locators selected from remote tables.* This error i am getting in TOAD as well as SQL Developer.
Can anybody tell me how to fix this error ? Because am not able to get the records.
Also am getting another error during retrieving data from some of my tables after migrating i.e the table which having CLOB data type while am accessing to retrieve the records using select query it's throwing the error :
+(The following error has occurred:+
A query with LOB's requires OCI8 mode, but OCI7 mode is used.)
If anyone having any idea kindly share.
Thanks and Regards
BiswaHi,
Ya what u sent that is fine. But already am using one procudure which is accessing LOB data from another databse through DBlink and working fine. But there Both the databse are 9.2.0.8.
But while am executing the same procedure in oracle 11g where the Dblink accessing the data from Oracle 9i , there am getting this error.
Kindly tell if u know any resolution.
Thanks -
Executing SQL queries in SAP-GUI e.g. select * from but000
Hallo,
I am newbie in the SAP world. Is there a way to run select statements from SAP GUI? e.g. I want to know how many rows are returning from a join xyz.
select count() from tabA and tabB where tabA.id = tabB.id and tabA.Name is not null.*
Is it possible with SQVI (SQ01)?
Please help.Testcase:
SQL> create table scott.testit
( id number not null,
value1 varchar2(10) not null )
tablespace DATA;
Table created.
SQL> desc scott.testit;
Name Null? Type
ID NOT NULL NUMBER
VALUE1 NOT NULL VARCHAR2(10)
SQL> insert into scott.testit (id,value1) values ( 1, 'Hello' );
1 row created.
SQL> commit;
Commit complete.
SQL> select * from scott.testit;
ID VALUE1
1 Hello
ADD COLUMN, the old fashioned way
SQL> alter table scott.testit add ( ADDFIELD1 varchar2(5) );
Table altered.
SQL> desc scott.testit;
Name Null? Type
ID NOT NULL NUMBER
VALUE1 NOT NULL VARCHAR2(10)
ADDFIELD1 VARCHAR2(5)
SQL> select * from scott.testit where ADDFIELD1 is null;
ID VALUE1 ADDFI
1 Hello
Works as expected
Try to get NOT NULL and DEFAULT to work
SQL> alter table scott.testit modify ( ADDFIELD1 NOT NULL );
alter table scott.testit modify ( ADDFIELD1 NOT NULL )
ERROR at line 1:
ORA-02296: cannot enable (SCOTT.) - null values found
SQL> alter table scott.testit modify ADDFIELD1 default '000';
Table altered.
SQL> alter table scott.testit modify ( ADDFIELD1 NOT NULL );
alter table scott.testit modify ( ADDFIELD1 NOT NULL )
ERROR at line 1:
ORA-02296: cannot enable (SCOTT.) - null values found
No suprise so far. You would usually need to update all NOT NULL
values to some values and you would be able to enable the NOT NULL constraint
allthough this may run for quite a while on big tables.
Now lets try the new stuff
SQL> alter table scott.testit drop column ADDFIELD1;
Table altered.
SQL> alter table scott.testit ADD ADDFIELD1 varchar2(3) DEFAULT '000' not null;
Table altered.
SQL> desc scott.testit
Name Null? Type
ID NOT NULL NUMBER
VALUE1 NOT NULL VARCHAR2(10)
ADDFIELD1 NOT NULL VARCHAR2(3) <<<< BING !!!
SQL> select * from scott.testit;
ID VALUE1 ADD
1 Hello 000 <<<< Default '000' is working
SQL> select * from scott.testit where ADDFIELD1 is NULL;
no rows selected <<<< NOW this might be suprising
SQL> insert into scott.testit (id,value1,addfield1) values (2,'Bye', '000');
1 row created.
SQL> commit; <<<< Trying to compare "real" '000' with DEFAULT '000'
Commit complete.
SQL> select * from scott.testit;
ID VALUE1 ADD
1 Hello 000 <<<< Added with default
2 Bye 000 <<<< inserted as '000'
SQL> alter table scott.testit modify ADDFIELD1 default '111';
Table altered.
SQL> select * from scott.testit; <<<< Now it gets exciting
ID VALUE1 ADD
1 Hello 000 <<<< WOA... How does this work?
2 Bye 000
SQL> set longC 20000 long 20000
SQL> select dbms_metadata.get_ddl('TABLE','TESTIT','SCOTT') from dual;
DBMS_METADATA.GET_DDL('TABLE','TESTIT','SCOTT')
CREATE TABLE "SCOTT"."TESTIT"
( "ID" NUMBER NOT NULL ENABLE,
"VALUE1" VARCHAR2(10) NOT NULL ENABLE,
"ADDFIELD1" VARCHAR2(3) DEFAULT '111' NOT NULL ENABLE <<<< No '000' DEFAULT
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "DATA"
SQL>
Looks like Oracle is at least a whole lot more clever than I expected.
It must have stored the first Default value somewhere else, as the documentation
says, that the effective rows will NOT be updated (otherwise it would never work so fast).
I need to dig into how datablocks are dumped and read.
Just to finalize this:
SQL> alter table scott.testit modify ADDFIELD1 NULL;
Table altered.
SQL> select * from scott.testit;
ID VALUE1 ADD
1 Hello 000
2 Bye 000
SQL> select * from scott.testit where addfield1 is null;
no rows selected
SQL>
So the change persists even if you revert the constraint allthough the data
should not been changed. Surely need to do a datablock dump of this.
Need to do additional tests with indexes.
But right now I am running out of time.
May be someone else likes to join the expedition.
Volker -
Polulate textfield(s) from a MS SQL Database based on selection from DropDown List
I am new to LiveCycle Designer. I am trying to create a Master Bill of Lading form. I want the user to be able to enter a Store Number from a in a text field and, based on what they enter I want to populate the address information from a database on my SQL Server.
When I bind the address fields from the database, I only see the first record in the database.
I'm not sure where to go from here...
Thanks in advance,
JeremyThat seemed to fix my error and returned the value to my DDL.
I have modified the code so it looks at the clone of my dataConnection (dcStoreData)
CODE:
btnClear.MainPage.sStNo::change - (JavaScript, client)
var inStrNbr = xfa.event.newText;
if (inStrNbr == ""){
app.alert("You must enter a valid name - try again!") } var nIndex = 0;
while(xfa.sourceSet.nodes.item(nIndex).name != "dcStoreData")
nIndex++;
tfStoreID.rawValue = inStrNbr;
var oDB = xfa.sourceSet.nodes.item(nIndex).clone(1);
// the node pertaining to the data connection specified
//app.alert(oDB.saveXML("pretty"));
//set up sql call to DB to get specifics about employee
oDB.nodes.item(1).query.setAttribute("text", "commandType");
oDB.nodes.item(1).query.select.nodes.item(0).value = "Select * from tblStoreMast_LastVersion where StorNbr = '" + inStrNbr + "'";
//app.alert(oDB.nodes.item(1).saveXML("pretty"));
//now connect to DB and get a record
oDB.open()
oDB.close();
it runs with no error and I am seeing the value it has given my DDL.rawValue
Now I get the "error:"
GeneralError: Operation failed.
XFAObject.open:16:XFA:btnClear[0]:MainPage[0]:sStNo[0]:change
ado2xfa operation failed. Item cannot be found in the collection corresponding to the requested name or ordinal.
My Store Number is stored as an int in the database.
Do I have to somehow cast it as a character?
Sorry for the headache!
Jeremy -
I have created a SELECT FROM SQL statement that basically checks if an individual has already registered with my application. The actual search works a treat, with any matches found being ammended to a JTextArea I have created. However, I need to know when a match is not found and am not sure how this is achieved.
When I created an update statement I was able to use the code
int result = statement.executeUpdate(Update);
if(result == 1) //to determine if a match was found.
Can anyone explain how to apply the same logic to this code, please??
try
makeConnection();
Statement statement = connection.createStatement();
query = "SELECT * FROM Manager_Details " +
"WHERE First_Name = '" + details[0] +
"'AND Last_Name = '" + details[1] + "'";
rs = statement.executeQuery(query);
MII.displayMatchedManagers(rs);
statement.close();
connection.close();
catch (SQLException sqlex)
System.out.println(sqlex.toString());
Thanks for any help,
Kris Dowsetry
makeConnection();
Statement statement = connection.createStatement();
query = "SELECT * FROM Manager_Details " +
"WHERE First_Name = '" + details[0] +
"'AND Last_Name = '" + details[1] + "'";
rs = statement.executeQuery(query);
MII.displayMatchedManagers(rs);
statement.close();
connection.close();
the MII.displayMatchingManagers method is below:
try
while(rs.next())
details = "Manager \\ Prediction ID: " + rs.getString("Num") +
"\nFirst Name: " + rs.getString("First_Name") +
"\nLast Name: " + rs.getString("Last_Name") +
"\nAddress: " + rs.getString("Address") +
"\nPostcode: " + rs.getString("Postcode") +
"\nArea Code: " +
What I want to be able to do is display all the matches if one is found,
or call an add method if no match is found. My problem is how to determine if a match has been found??? -
Select from SQL Server Activity
Hi,
I'm using the Select from SQL Server Activity in CPO to look up some values in a table, straightforward SQL queries like select * from Table work 100% but when I start applying a WHERE clause to the query it fails to return the results even though when running query in SQL studio it returns results successfully.
The issue seems to be when trying to use brackets in a OR statement:
The SQL Statement is:
SELECT AppName FROM METADaaS WHERE
NCCX NOT LIKE '%18421%'
AND RTYPE='A'
AND BUNDLEDWITH LIKE '%GOL Back Office%'
AND (NCC = '0' OR NCC LIKE '%18421%')
This returns no results in CPO but in SQL Studio returns the results as expected.
If I remove the "(NCC = '0' OR NCC LIKE '%18421%')" I get results in CPO.
thanksAny SQL statement should work. I would suggest you open a TAC case.
Maybe you are looking for
-
1.I wanted to know if I can run a .sql file from the dbms_job package. 2. I also wanted to know the feature in oracle that I can use to send email to myself once the job is executed- showing successful execution or errors. Thanks for your suggestions
-
Anyone know what I should look for? What is causing the video not to play and only the QT icon to be displayed? This has never happened before on my Safari.
-
Installing Weblogic Admin Server as service - service won't start
I'm installing Weblogic Admin Server as a Service in Weblogic 10 on a Windows 2008 R2 box. The service installs correctly, but when I start it, it immeidately stops with this error: "The <service name> service on Local Computer started and then stopp
-
Adding many hyperlinks to images / pdf imports in InDesign
Hi, I have recently imported a PDF into Indesign which are now images. One page is the table of contents and I wish to add a link over the top of the image so I can link to other parts of the document. How do I add many hotspots or hyperlinks to 1 pa
-
I'm developing a webdynpro application using a Pie chart. In the chart designer, you can tell it to show the labels. I have this check on. Underneath that there is a field call label format which has "$Label" as a default, if I get rid of this