Fixing this Table Variable Query
Please assist me to correct this syntax for this Table Variable Question below.
/* Create a table variable with Departure City and State in 2 different columns along
with Flight Destination City and Ontime. */
DECLARE @NTable TABLE (FlightDepartureCity varchar(50), FlightDepartureCity1 varchar(50),FlightDestinationCity varchar(50), [Ontime] INT)
INSERT INTO @NTable
SELECT Left(FlightDepartureCity,CHARINDEX('-',FlightDepartureCity)-1) as City,
RIGHT(FlightDepartureCity,LEN(FlightDepartureCity) - CHARINDEX('-',FlightDepartureCity)) as FirstName,
FlightDestinationCity, Ontime
FROM Flights
SELECT Left(FlightDepartureCity,CHARINDEX('-',FlightDepartureCity)-1),
RIGHT(FlightDepartureCity,LEN(FlightDepartureCity) - CHARINDEX('-',FlightDepartureCity)) ,
FlightDestinationCity, Ontime FROM @NTable
Disregard I figured it out
DECLARE @NTable TABLE (FlightDepartureCity varchar(50), FlightDepartureCity1 varchar(50),FlightDestinationCity varchar(50), [Ontime] INT)
INSERT INTO @NTable
SELECT Left(FlightDepartureCity,CHARINDEX('-',FlightDepartureCity)-1) as City,
RIGHT(FlightDepartureCity,LEN(FlightDepartureCity) - CHARINDEX('-',FlightDepartureCity)) as FirstName,
FlightDestinationCity, Ontime
FROM Flights
SELECT * from @NTable
Similar Messages
-
Table variable query optimisation
I have a table variable which (sometimes) needs to contain a couple of thousand rows, this slews the execution plan. This is fixed by DBCC TRACEON(2453) which causes the
rows in the table variable to be estimated properly, this requires sysadmin rights which I am reluctant to grant to other than this stored proc. The proc is excuted by most users with SQL authentication. I've tried with exec as 'NT AUTHORITY\SYSTEM' but that
does not seem to be recognized as I'm using sql authentication. Cant use a temp table as this breaks asp net Linq which is user to wrap the stored procedure.
Suggestions please? Is there another way to tell the proc to count the row in a table variable? Is there a tight scripted way to grant
sysadmin rights to just this stored proc across a number of databases and servers?Hi Erland, I'm feeling particularly dumb at the moment... I read your article and each step seems clear. so I then tried to put together a script to create a certificate, create a logon, create a (SQL) user, create a proc to run as that user and test. My
dismal attempt is below.
USE master
go
-- Create a test login and test database
CREATE LOGIN testuser WITH PASSWORD = 'CeRT=0=TeST'
CREATE DATABASE certtest
go
-- Move to the test database.
USE certtest
go
-- Create the test user.
CREATE USER testuser
go
-- Create the test table and add some data.
CREATE TABLE testtbl (a int NOT NULL,
b int NOT NULL)
INSERT testtbl (a, b) VALUES (47, 11)
go
-- Create the certificate.
CREATE CERTIFICATE TraceOnCert
ENCRYPTION BY PASSWORD = 'All you need is love'
WITH SUBJECT = 'Certificate for TraceOnProc',
START_DATE = '20020101', EXPIRY_DATE = '20200101'
go
-- Create the login
CREATE LOGIN TraceOnLogin WITH PASSWORD = 'CeRT=0=TeST'
GO
--create user link to login
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'TraceOnUser')
CREATE USER TraceOnUser FOR LOGIN TraceOnLogin
--give login sysadmin rights
EXEC master..sp_addsrvrolemember @loginame = N'TraceOnLogin', @rolename = N'sysadmin'
go
GRANT SELECT ON testtbl TO TraceOnUser
go
-- Create two test stored procedures, and grant permission.
CREATE PROCEDURE unsigned_sp AS
DBCC TRACEON(2453)
SELECT SYSTEM_USER, USER, name, type, usage FROM sys.user_token
EXEC ('SELECT a, b FROM testtbl')
DBCC TRACEOFF(2453)
go
CREATE PROCEDURE TraceOnProc WITH EXECUTE AS 'TraceOnUser' AS
DBCC TRACEON(2453)
SELECT SYSTEM_USER, USER, name, type, usage FROM sys.user_token
EXEC ('SELECT a, b FROM testtbl')
DBCC TRACEOFF(2453)
-- EXEC unsigned_sp
go
GRANT EXECUTE ON TraceOnProc TO public
GRANT EXECUTE ON unsigned_sp TO public
go
go
-- Run as the test user, to actually see that this works.
EXECUTE AS USER = 'testuser'
go
-- First run the unsigned procedure. This gives a permission error.
EXEC unsigned_sp
go
-- Then run the signed procedure. Now we get the data back.
EXEC TraceOnProc
go
-- Become ourselves again.
REVERT
go
-- Clean up
USE master
DROP DATABASE certtest
DROP LOGIN testuser
DROP LOGIN TraceOnLogin -
How to fix this QtyOnHand FMS query with SO and PO ShipDates.
Hi Forum,
I have this query that returns available quantity that takes into account (from PO) on order and on commit (SO) based on dates of order and receive.
declare
@onhand as float,
@openqty_s_order as float,
@openqty_p_order as float
set @onhand = (select oitw.onhand from oitw
where oitw.whscode = $[$38.24.0] and oitw.itemcode = $[$38.1.0])
set @openqty_s_order = (select sum(openqty) from rdr1
where (rdr1.shipdate <= $[$38.25.0]) and (rdr1.itemcode = $[$38.1.0]) and (rdr1.whsCode = $[$38.24.0]))
set @openqty_p_order = (select sum(openqty) from por1
where (por1.shipdate <= $[$38.25.0]) and (por1.itemcode = $[$38.1.0]) and (por1.whsCode = $[$38.24.0]))
select (@openqty_p_order + @Onhand - @openqty_s_order)
Whenever the SO ShipDate is <= PO Ship Date, the value returned by entire query is 0.0 instead of OnHand - Qty committed by SO's.
This query works when SO ShipDate is >= PO ShipDate, it returns OnHand-Qty Committed by SOs + Available through POs
To repeat the problem:
BASICALLY whenever @openqty_p_order has no value returned then the entire select -> select (@openqty_p_order + @Onhand - @openqty_s_order) returns 0.0, even though @onhand - @openqty_s_order have values that is not zero.
Appreciate your help. Thank you.Hi Syed Aleem,
Modify the Query as follows :
Select @OpenQty=isNull(sum(openqty),0)
From RDR1
where (rdr1.shipdate <= $[$38.25.0]) and (rdr1.itemcode = $[$38.1.0]) and (rdr1.whsCode = $[$38.24.0]))
Select @openqty_p_order=isNull(Sum(OpenQty),0)
from por1
where (por1.shipdate <= $[$38.25.0]) and (por1.itemcode = $[$38.1.0]) and (por1.whsCode = $[$38.24.0]))
The problem occurs when there is no row to select then aggregate clause returns NULL which cannot be used in any Operation .
Hence use isNull function to avoid this error.
Thanks and Regards,
Pooja Singh. -
Fixing this Scalar Variable Syntax question
Please help me to correct this syntax for this practice question below.
/* Create and set a Variable equal the number of Flights that were late.*/
DECLARE @FlightsLate varchar(50)
SET @FlightsLate = (SELECT* FROM
Flights WHERE Ontime = 0)
SELECT @FlightsLateIf you want to get the total numbers that are late you need to do this
DECLARE
@FlightsLate varchar(50)
SET
@FlightsLate = (SELECT count(*) FROM
Flights WHERE
Ontime = 0)
SELECT
@FlightsLate
Assuming that Ontime =0 means Late
Javier Villegas |
@javier_vill | http://sql-javier-villegas.blogspot.com/
Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you -
Hello Experts,
Can You help me; I get the follwing error in my query
Msg 1087, Level 15, State 2, Line 31
Must declare the table variable "@ASE_SUBART_GROEP".
the @ASE_SUBART_GROEP is a self-defined table in this SQL environment.
Maybe you know the error or the missing part
Thanks in advance, Jos DielemansI'm not familiar with SAP Business One unfortunately, so can only be of limited help here. But I'm going to guess that @ASE_SUBART_GROEP is a table variable passed to a stored procedure and is defined and passed down by the application, so you won't
be able to copy-paste this code directly into management studio and get it to work.
You could remove the join to return *all* records. Although the dataset might be very big
SELECT T0.CardCode AS 'Klantnr'
,T0.CardName AS 'Klantnaam'
,T4.GroupName AS 'Klantgroep'
,T9.Descr AS 'Merknaam'
,T5.SlpName AS 'Verkoper'
,T3.MailCity AS 'Leverplaats'
,T7.NAME AS 'Leverland'
,T3.City AS 'Factuurplaats'
,T7.NAME AS 'Factuurland'
,T0.DocNum AS 'Documentnr'
,T0.DocDate AS 'Datum'
,Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) AS 'Jaar'
,RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2) AS 'Maand'
,(Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) + '-' + RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2)) AS 'Periode'
,T1.ItemCode AS 'Artikelnr'
,T2.ItemName AS 'Artikelnaam'
,T1.Quantity AS 'Aantal VEH'
,T2.SVolume AS 'Aantal EH per VEH'
,(T1.Quantity * T2.SVolume) AS 'Aantal EH'
,T8.UnitName AS 'EH-Naam'
,T6.ItmsGrpNam AS 'Artikelgroep'
,T2.U_ItemGrp AS 'Hoofdgroep'
,T10.NAME AS 'Subgroep'
,T1.CogsAcct AS 'Kostpr.rek.'
,T1.AcctCode AS 'Opbrengstrek.'
,T1.LineTotal AS 'BrutoOmzet'
,T0.DiscPrcnt AS 'Korting'
,(+ T1.LineTotal * (100 - T0.DiscPrcnt) / 100) AS 'NettoOmzet'
FROM dbo.OINV T0
INNER JOIN dbo.INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OCRD T3 ON T0.CardCode = T3.CardCode
INNER JOIN OCRG T4 ON T3.GroupCode = T4.Groupcode
INNER JOIN OSLP T5 ON T3.SlpCode = T5.SlpCode
INNER JOIN OITB T6 ON T2.ItmsGrpCod = T6.ItmsGrpCod
INNER JOIN OCRY T7 ON T3.Country = T7.Code
LEFT OUTER JOIN OLGT T8 ON T2.SVolUnit = T8.UnitCode
LEFT OUTER JOIN UFD1 T9 ON T3.U_ZPgroep = T9.FldValue
AND TableID = 'OCRD'
AND FieldID = 2
--LEFT OUTER JOIN @ASE_SUBART_GROEP T10 ON T2.U_ASE_SUB_ARTGROEP = T10.Code
WHERE T0.DocDate >= '20120101'
AND T0.Canceled = 'N'
UNION ALL
SELECT T0.CardCode AS 'Klantnr'
,T0.CardName AS 'Klantnaam'
,T4.GroupName AS 'Klantgroep'
,T9.Descr AS 'Merknaam'
,T5.SlpName AS 'Verkoper'
,T3.MailCity AS 'Leverplaats'
,T7.NAME AS 'Leverland'
,T3.City AS 'Factuurplaats'
,T7.NAME AS 'Factuurland'
,T0.DocNum AS 'Documentnr'
,T0.DocDate AS 'Datum'
,Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) AS 'Jaar'
,RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2) AS 'Maand'
,(Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) + '-' + RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2)) AS 'Periode'
,T1.ItemCode AS 'Artikelnr'
,T2.ItemName AS 'Artikelnaam'
,- T1.Quantity AS 'Aantal VEH'
,T2.SVolume AS 'Aantal EH per VEH'
,(- T1.Quantity * T2.SVolume) AS 'aantal EH'
,T8.UnitName AS 'EH-Naam'
,T6.ItmsGrpNam AS 'Artikelgroep'
,T2.U_ItemGrp AS 'Hoofdgroep'
,T10.NAME AS 'Subgroep'
,T1.CogsAcct AS 'Kostpr.rek.'
,T1.AcctCode AS 'Opbrengstrek.'
,- T1.LineTotal AS 'BrutoOmzet'
,T0.DiscPrcnt AS 'Korting'
,(+ T1.LineTotal * (100 - T0.DiscPrcnt) / 100) AS 'NettoOmzet'
FROM dbo.ORIN T0
INNER JOIN dbo.RIN1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OCRD T3 ON T0.CardCode = T3.CardCode
INNER JOIN OCRG T4 ON T3.GroupCode = T4.Groupcode
INNER JOIN OSLP T5 ON T3.SlpCode = T5.SlpCode
INNER JOIN OITB T6 ON T2.ItmsGrpCod = T6.ItmsGrpCod
INNER JOIN OCRY T7 ON T3.Country = T7.Code
LEFT OUTER JOIN OLGT T8 ON T2.SVolUnit = T8.UnitCode
LEFT OUTER JOIN UFD1 T9 ON T3.U_ZPgroep = T9.FldValue
AND TableID = 'OCRD'
AND FieldID = 2
--LEFT OUTER JOIN @ASE_SUBART_GROEP T10 ON T2.U_ASE_SUB_ARTGROEP = T10.Code
WHERE T0.DocDate >= '20120101'
AND T0.Canceled = 'N'
ORDER BY T0.CardCode
The join to the table variable has been commented out above, so the code should run. After that you might want to update the WHERE clause to include only particular sub-groups -
RE: Table Variable error in a query
Dear Readers, I am getting this error below when I create the table variable . Any ideas where I could be going wrong...
Use GG_TS
GO
--Using table variable
Declare @customerscount table
(firstname char(30),
totals int,
customerNumber int)
Insert @customerscount
Select
Customers.firstname,
Count(*) as 'Totals',
Orders.CustomerNumber
FROM
Customers join orders ON
customers.customernumber = orders.customernumber
Group BY
customers.firstname,orders.customernumber
The error I am getting is below:
Incorrect syntax near the keyword 'table'.
Thanks so much!
SQL 75No, Now it's giving me a different error. Below is the error: By the way I am running this in SQL server 2012
under tempDB as it is a table variable.
Msg 208, Level 16, State 1, Line 6
Invalid object name 'Customers'.
Below is my Query:
Declare @customerscount table
(firstname char(30),
totals int,
customerNumber int)
Insert @customerscount
Select
Customers.firstname,
Count(*) as 'Totals',
Orders.CustomerNumber
FROM
Customers join orders ON
customers.customernumber = orders.customernumber
Group BY
customers.firstname,orders.customernumber
Thank-you
SQL 75
No need to run this in tempdb
You can run this in your database itself ie database where tables customers, orders etc exist and table variable gets created in tempdb itself
The reason for your error is because it cant find the tables in the tempdb database
So run the query in your own database
Otherwise you need to change it as below if you stiil want this to be executed in tempdb
Declare @customerscount table
(firstname char(30),
totals int,
customerNumber int)
Insert @customerscount
Select
c.firstname,
Count(*) as 'Totals',
o.CustomerNumber
FROM
<yourdbname>.dbo.Customers c join <yourdbname>.dbo.orders o ON
c.customernumber = o.customernumber
Group BY
c.firstname,o.customernumber
assuming dbo is your default schema
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Acrobat X... Used to be able to Certify with Visible signature, and still be able to search all text. Now some areas (text resembling tables) are no longer searchable. How can I fix this?
[discussion moved to Creating, Editing & Exporting PDFs forum]
-
Hi , my sister got really mad and she banged her iPod touch 5th generation on a table and she banged it so hard that the screen didn't crack but inside the the iPod is damage as in like colors are popping out and the screen doesn't work, can i fixed this?
Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
Apple - iPod Repair price
A third-party place like the following maybe less. Google for more.
iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens -
== Issue
==
I have another kind of problem with Firefox
== Description
==
i have been trying to get the audio to play for 3 days now i did see where it had been deleted this is a used comp i haven't had it long can you fix this i'm at my wits end
== Firefox version
==
3.6.3
== Operating system
==
Windows NT 5.0
== User Agent
==
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
== Plugins installed
==
*-Default Plug-in
*Adobe Acrobat Plug-In Version 5.10 for Netscape
*Java(TM) Platform SE binary
*Next Generation Java Plug-in 1.6.0_20 for Mozilla browsers
*Network Object Plugin
*Windows Multimedia Services DRM Store Plug-In
*Npdsplay dllHello Virginia.
You may be having a problem with some extension or plugin that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal? -
What is the table for query name
Hi All,
I need an urgent requirement for removing duplicate technical query names from the production. Since there are few issues with the SAP given program I am customizing the SAP Program. Can any one tell me what is the table where the QUERY NAME and it's technical name can be found?
Thanks,
Alex.hi Alex,
try RSRREPDIR, RSZCOMPDIR.
there is one oss note all the tables.
Table containing Work Book and query relation
Query Detailes
oss 792779
Symptom
Report ANALYZE_RSZ_TABLES is designed as a check-tool for detecting and solving different types of inconsistencies in the main query definition database tables.
The program is recommended for BW system administrators.
Other terms
Query definition, query, reusable, component, variable, missing elements, missing records, missing UID, INCONSISTENCY, RSZELTDIR, RSZCOMPDIR, RSZCOMPIC, RSZGLOBV, RSZCALC, RSZSELECT, RSRREPDIR.
Reason and Prerequisites
ATTENTION: the described version of the program is delivered with the following Support Packages:
SP27 for release BW 3.0B
SP21 for release BW 3.1C
SP13 for release BW 3.5
All versions of this report available in systems before those Support Packages are test versions which can be used only for information purposes.
Check prerequisites
Checks are possible only for elements in object version 'A' (active) and 'D' (delivered).
Checks for query elements in 'D' version are possible only in the systems which are set as content.
Checks description
Report performs checks in the tables containing the parts of the definitions of queries and query components: RSRREPDIR, RSZCOMPDIR, RSZCOMPIC, RSZGLOBV, RSZELTDIR and RSZELTXREF.
1. Table RSRREPDIR
The table RSRREPDIR is a header table of the generated reports. Consistency of query definition in this table allows to select a query in the Open Dialogs of fronted application and to call report generated for this particular query using transaction RSRT.
The following errors can be found:
- queries with missing definition;
- queries with missing GENUNIID;
- queries with technical names different than in RSZCOMPDIR;
- non-queries in the table.
1.1 Queries with missing definition
The queries are available only in the table RSRREPDIR and not found in the table RSZELTDIR in the corresponding object version. Such queries (in active version) can be accessed only from RSRT transaction. An attempt to execute such query will return the short dump 'Exception condition INCONSISTENCY'. The error also happens during query generation in RSRT or during mass regeneration of the queries using RSR_GEN_DIRECT_ALL_QUERIES report or application menu of transaction RSRT. The inconsistent queries can not be repaired because of missing query definitions. The recommended solution is to delete those records in order to avoid the possible system dumps.
1.2 Queries with missing GENUNIID
Queries having empty GENUNIID field in the table RSRREPDIR. Such queries may be available in the frontend and in RSRT transaction. An attempt to execute such query will return the message'GENUNIID not found'. Situation requires additional investigation at SAP. Create an OSS message for BW-BEX-ET-QDEF.
1.3 Queries with technical names different than in RSZCOMPDIR
The check outputs the queries which have different technical names in the RSRREPDIR and RSZCOMPDIR tables. Execution of a query using the technical name given in Query Designer and stored in the table RSZCOMPDIR will return the error message 'GENUNIID not found'. The system tries to find the corresponding GENUNIID for the wrong COMPID which does not exist in the system or which belong to another query. The recommended solution is to correct the wrong COMPID in the table RSRREPDIR via corresponding procedure.
1.4 Non-queries in the table
The table RSRREPDIR normally contains only reports. Query elements of other types should not exist in this table and can be deleted. In case, when such records exist in the table an attempt to access them in RSRT returns the error message 'GENUNIID not found'. The recommended solution is to delete those records from the table using the corresponding procedure.
2. Table RSZCOMPIC
The table RSZCOMPIC contains an InfoProvider assignment for queries and other reusable query components (STR, RKF and CKF).
The following errors can be found:
- local elements in RSZCOMPIC;
- components with inconsistent definition;
- components based on non-existing InfoProviders;
- components based on non-active InfoProviders.
2.1 Local elements in RZSCOMPIC
The table RSZCOMPIC contains an InfoProvider assignment for the reusable components. The local elements and also variables have no InfoProvider assignment and should not exist in this table. Those elements can be deleted via corresponding procedure.
2.2 Components with inconsistent definition
The reusable queries or query components existing in the table RSZCOMPIC, but not found in the table RSZELTDIR. Those reusable components may return 'Exception condition INCONSISTENCY' dump during accessing/execution. The situation may have different outcomes and has to be investigated at SAP. Create an OSS message for BW-BEX-ET-QDEF.
2.3 Components based on non-existing InfoProviders
Queries or query components are assigned to the InfoProviders which do not exist anymore in the system. Queries without InfoProvider are not available in Open Dialogs of frontend applications, but can be executed in RSRT. The execution will return the error message'InfoProvider not found'. The recommended solution is to delete the unnecessary components. Deletion of these queries or query components can be done directly from the list using corresponding procedure similar to RSZDELETE transaction.
2.4 Components based on non-active InfoProviders
Queries or query components which are assigned to the InfoProviders which do not exist in the system in the active version. Queries without active InfoProvider are not available in Open Dialogs of frontend applications. In case, an affected query is technically consistent, an attempt to execute it in transaction RSRT will return the message 'Activate the XXX InfoCube / InfoProvider again. Message #BRAIN 056'. Quite often this error is combined with other errors like missing GENUNIID in the RSRREPDIR or other inconsistencies. Each case has to be investigated in order to get the current status of this object. If the affected query is useless, it can be deleted from the system using transaction RSZDELETE.
The check is available only for the query elements in object version 'A' (active).
3. Table RSZCOMPDIR
The table RSZCOMPDIR is the directory table containing the main properties of all reusable components.
The following errors can be found:
- duplicated technical names (COMPID);
- components with inconsistent definition;
- components without InfoProvider assignment;
- components with missing OWNER.
3.1 Duplicated technical names (COMPID)
The check outputs queries or other reusable query components which have duplicated technical names (COMPID).
The error does not cause any dumps in ABAP or terminations in Query Designer, but may cause several symptoms in different reporting areas:
different queries are available in BEX Analyzer and RSRT under the same name;
wrong query is used as Data Source for Web Template (Web Reporting, Reporting Agent, Broadcasting, MDX);
replacement of variables does not work... etc.
The recommended solution is to provide a new technical name for the duplicated component using corresponding procedure.
ATTENTION: in case when there are only 2 components with the duplicated technical name, only one of those 2 components can be renamed using the corresponding procedure.
The alternative solution for renaming the duplicated technical names is to use the ABAP report RENAME_DUPLICATE_ELEMENTS.
3.2 Components with inconsistent definition
Reusable query components which are not found in the element directory table RSZELTDIR are displayed. This situation may cause the short dump 'Exception condition INCONSISTENCY' during accessing the affected component in Query Designer or execution the affected query in RSRT. Further investigations are required at SAP. Create an OSS note for the SAP component BW-BEX-ET-QDEF.
3.3 Components without InfoProvider assignment
All reusable query component (except variables) should be assigned to a particular InfoProvider. This assignment is located in the table RSZCOMPIC. When the record is not found in this table, the affected component may become not available in Query Designer in the corresponding InfoProvider. In some cases the error message "Component XXX.. (version A) has no InfoCube assignment". Further investigations are required at SAP. Create an OSS note for the SAP component BW-BEX-ET-QDEF.
3.4 Components with empty ONWER field
Reusable components which have empty OWNER field in the table RSZCOMPDIR are accessible by users having $USER setting in the authorization object S_RS_COMP1 (users which are authorized to their own queries or query components). This leads to authorization concept violation.
For error solution the field OWNER in the RSZCOMPDIR should be filled with any value. Execute the corresponding edit mode in order to fill the empty field with user 'SAP'. This will prevent the potential authorization violation for users with $USER setting and will take no effect on the users without this setting.
4. Table RSZELTXREF
The table RSZELTXREF contains all links and dependencies between the query elements within a query or query component.
The following errors can be found:
- missing elements (INCONSISTENCY dump);
- not supported relations between query elements;
- extended RSZELTXREF check.
4.1 Missing elements
Missing elements are those query elements which exist as the dependant objects (field TELTUID) in the table RSZELTXREF, but not available in the element directory table RSZELTDIR in corresponding object version. In case, when such elements are used in any query or other query components (STR, CKF or RKF), this may lead to ABAP short dump with 'Exception condition INCONSISTENCY' error message in query run-time or design-time. Other known symptoms of this error is, that structures, calculated key figures or restricted key figures are not available in an Info Provider in Query Designer during design-time.
The missing elements which are in use in other queries or query components, can not be automatically repaired or deleted without components where those elements are used. In most cases the manual repair operations directly in the DB tables are required. Create an OSS message for SAP component BW-BEX-ET-QDEF for further investigations and creation of a repair plan.
The missing elements which are not in use in any query or query components, can be deleted from the system via corresponding delete procedure. This deletion will not affect any existing query or query component.
ATTENTION: if missing element is variable, it can be repaired in some cases automatically using the corresponding repair procedure. See table RSZGLOBV check 5.1. 'Variables with inconsistent definition' for details.
4.2 Not supported relations between query elements
Some relations between query elements which are not supported and can cause dumps in ABAP or terminations in Query Designer (for example link STR <--> VAR). Such cases have to be additionally investigated at SAP. Create an OSS message for SAP component BW-BEX-ET-QDEF.
4.3 Extended RSZELTXREF check
The extended RSZELTXREF check outputs 2 situations which, in combination with other conditions in the system, may be responsible for slow performance of all operations which involve select from the table RSZELTXREF and resolving the relations between query elements (query load, query generation, expanding of a variable list for corresponding InfoObject, expanding of a list of reusable components in Query Designer,... etc.):
- records with empty INFOCUBE field
- records which are not used in any query or query component
Records with empty INFOCUBE field
The current algorithm of resolving of relations between the query elements uses an optimization which allows to reduce the amount of data selected from the table RSZELTXREF during such operations are query load, query generate, expand a list of reusable components (STR, CKF, RKF) and so on. All relations between query elements within one reusable component based on one InfoProvider 'N' are also located within the same InfoProvider. The system has to select only records where the INFOCUBE field contain the same InfoProvider 'N' and in addition to this all other records where the INFOCUBE field is empty. This is necessary, because in all BW releases below 3.x the INFOCUBE field was not in the RSZELTXREF table and all components created before 3.x release have this field empty. Selection of records with empty INFOCUBE is required in order to ensure the consistency of processed query.
When the number of records with empty INFOCUBE is quite large (50.000 - 1 mln records), any simple operation which require resolving of the relations may take a long time, because those records are always being selected, loaded to Query Designer and processed in the design-time.
Records which are not used in any query or query component
The program makes a virtual attempt to reconstruct the table RSZELTXREF via resolving the relations between all reusable components existing in the system. All records which are not used in any query or query components are considered as non-used records. Usually these are fragments of old queries or other components which are not deleted due to former errors in the query delete algorithm.
The current version of the program contain only information about those 2 issues. See the OSS note 823804 for additional information.
ATTENTION: the extended RSZELTXREF check is recommended when all critical problems with reusable components are resolved and the system clean-up is done (no useless records in the tables, no useless non-executable queries or other affected query component available).
Starting from SP28 for BW 30B, SP22 for BW 31C and SP14 for BW 3.5 the Extended RSZELTXREF check detects and fixes the following situations:
records used in existing queries or query components with empty INFOCUBE field;
records used in existing queries or query components with wrong INFOCUBE assignment;
records with or without INFOCUBE assignment which are not used in any query or query component.
For further check details read the OSS note 859086.
5. Table RSZGLOBV
The table RSZGLOBV contains the definitions and technical properties of the variables.
The following errors can be found:
- variables with inconsistent definition;
- variables with missing or incorrect properties;
5.1 Variables with inconsistent definition. Variable not found in RSZELTDIR/RSZCOMPDIR tables.
The variable existing in the table RSZGLOBV, but not existing in the tables RSZELTDIR or RSZCOMPDIR have inconsistent definition. These situation may return 2 different error messages. When a variable is missing in RSZELTDIR table (or in both together), an attempt to expand a list of variable under a corresponding InfoProvider or a list of text/formula variables will return a message 'Inconsistency in loading...'. All variables which are created for corresponding InfoProvider, text/formula variable are not available. When a variable is missing in the RSZCOMPDIR table only the error message is 'Missing UID XXXXXX... in RSZCOMPDIR! You may continue to work, but this component is not loaded' in Query Designer.
In both cases the variables can be repaired via the corresponding procedure provided in the program under the technical name (COMPID) corresponding to the name in VNAM field in the table RSZGLOBV with the text 'REPAIRED BY SAP'.
As an alternative solution, when the affected variables which are not used in any query or query component can be deleted directly from the RSZGLOBV table. Both solutions will fix the reported symptoms.
ATTENTION: it is recommended to open a repaired variable in Variable Wizard of Query Designer and to adjust the definition of this variable, when it is necessary.
ATTENTION: deletion of the affected variables missing in the table RSZCOMPDIR is not possible using transaction RSZDELETE. An attempt to delete such variable will return the error message 'Component not found'.
5.2 Variables with missing or incorrect properties
Several errors can be found within this check. The variables of different type have their own sets of properties. Missing or incorrect properties may cause different error message during execution of a query where such variables are in use. In the case of the affect variables with processing type 'replacement' , the replacement may not work because of the problem.
Each case has to be investigated at SAP. Create an OSS message for SAP component BW-BEX-ET-QDEF.
6. Table RSZELTDIR
The table RSZELTDIR is the main directory table containing all query elements available in the system.
ATTENTION: the RSZELTDIR check may take a long running time depending upon the table size.
The following errors can be found:
- local elements not in use;
- reusable elements not in RSZCOMPDIR table;
- reusable elements not in RSZCOMPIC table;
- structure (STR) without structure members;
- selections or RKF without definition in RSZSELECT table;
- formulas or CKF without definition in RSZCALC table;
- variables (VAR) without definition in RSZGLOBV table;
- queries (REP) without entries in RSRREPDIR table.
6.1 Local elements not in use
Local elements (field REUSABLE = false) which are not used as dependant objects in the table RSZELTXREF. These elements are useless and not accessible from Query Designer. Usually these are fragments of the definitions of old queries accumulated in system because of different problems with save/delete procedures which are not accessible by the end users. The recommended solution is to delete those elements using the corresponding delete procedure.
6.2 Reusable elements not in RSZCOMPDIR table
Reusable elements (field REUSABLE = true) must have a corresponding entry in the table RSZCOMPDIR which contains the definition and properties of this reusable component. An attempt to load such component in Query Designer may cause the error message 'Missing UID XXXXXX... in RSZCOMPDIR! You may continue to work, but this component is not loaded'. Additional investigations are requires at SAP. Create an OSS message for BW-BEX-ET-QDEF.
ATTENTION: Deletion of such affected components is also not possible using transaction RSZDELETE. An attempt to delete will return the message 'Component not found'.
6.3 Reusable elements not in RSZCOMPIC table
Reusable elements (field REUSABLE = true), except variables (DEFTP = 'VAR'), must have a corresponding entry in the table RSZCOMPIC which contains an InfoProvider assignment for reusable components. When a reusable component has no InfoProvider assignment it may be not available in Query Designer during design-time. Additional investigations are required at SAP. Create an OSS message for BW-BEX-ET-QDEF. In case the affected component is useless, it can be also deleted from the system using transaction RSZDELETE.
6.4 Structures (STR) without structure members
Reusable and non-reusable structures (DEFTP = 'STR') should have dependant elements (structure members). When these structure members are not found a query containing this structure returns the error message 'Element structure not correct' during generation or execution in RSRT or BEx analyzer. The program outputs a query technical name where such structures are used or the technical name of an InfoProvider if the affected structure is reusable and not used in any query. In this case it can be accessed from any query created in the same InfoProvider in Query Designer. The solution is to open the affected structure in using the latest available version of Query Designer and to create the required structure members in order to avoid the error message.
In case, when the affecter structure is local (non-reusable) and is not used in any query, this structure is not accessible by frontend users and can be deleted from the system by corresponding procedure provided in the program.
6.5 Local selection of RKFs without records in RSZSELECT table
Local selections and reusable Restricted Key Figure (DEFTP = 'SEL') usually should have the corresponding records in the DB table RSZSELECT. The program outputs all selections found in the system which have no corresponding records in the RSZSELECT table.
Usually this issue has no impact on the existing queries and produces no error messages. There are 3 possible types of selections within a query:
Normal selection - this selection represents a characteristic in Row, Columns or Free Characteristics area, Conditions or Exceptions. This situation produces no error messages, but the selection is not taken into account by OLAP.
Dummy structure member - structure member type selection can be defined using Query Designer. Such structure member produces no selection and can be used only as place holder within a query. This situation produces no error messages during generation/execution of a query containing a structure with those dummy structure members.
Cell selection - this type of selection is usually used as Cell selection and can be defined using Cell Editor in Query Designer. This situation produces no error messages, but the selection is not taken into account by OLAP.
If it is necessary, the selection definition can adjusted using the latest available version of Query Designer. The affected local selections can be accessed from the queries presented in the WHERE-USED (INFOCUBE/QUERY). The Restricted Key Figures are available in Query Designer from any query created on the corresponding InfoProvider.
In case, when a local selection is not used in any query or query components the recommended solution is to delete this selection using the corresponding delete procedure.
6.6 Local formulas of CKFs without records in RSZCALC table
Local formulas (DEFTP = 'FML') or Calculated Key Figures (DEFTP = 'CKF') should contain definition of the calculations in the table RSZCALC. When such definition is not found in the table RSZCALC the queries or query components which include those affected objects can not be generated or executed by OLAP. An attempt to generate such query returns the error message 'The (sub) formula XXX... is not available'.
The definitions of the affected formulas or Calculated Key Figures can be adjusted using the latest available version of Query Designer. The adjustment of a local formula is possible from the corresponding query listed presented in the program. The Calculated Key Figures are available in Query Designer from any query created on the corresponding InfoProvider.
In case, when a local formula is not used in any query or query components the recommended solution is to delete this formula using the corresponding delete procedure.
6.7 Variables without records in RSZGLOBV table
Variables (DEFTP = 'VAR') should exist in the table RSZGLOBV. The table RSZGLOBV contains all processing properties and definition of the variables. Query where such variables are used can not be executed without problems.
The repair procedure is not possible, because of missing definition. In case, when such variable is not used in any query, the recommended solution is to delete it from the system in order to avoid potential problems. If the affected variable is already used in other queries or query components, create an OSS message for SAP component BW-BEX-ET-QDEF. Further investigations and possible repair plan have to be created at SAP.
6.8 Queries without records in RSRREPDIR table
Queries (DEFTP = 'REP') should exist in the table RSRREPDIR. The table RSRREPDIR is a header table of generated reports and also a part of the database view V_REP_JOIN which provides data for the BEx Open/Save Dialogs.
A query which does not exist in the table RSRREPDIR is not accessible via RSRT transaction (error message 'GENUNIID not found') and not displayed in the Open/Save Dialogs of fronted applications.
The recommended solution is to delete such queries using the corresponding procedure provided in the program and similar to RSZDELETE.
In some cases the repair procedure is also possible. The success of the repair procedure depends upon the consistency of the affected query, the existence of a valid InfoProvider for this query and some other factors. For repair attempt create an OSS message for the SAP component BW-BEX-ET-QDEF.
hope this helps. -
How to fix this error: IMP-00003: ORACLE error 1435 encountered
Hello,
I am new to oracle database. I am trying import a data dump file *.dmp into my test database. I am using Oracle Database 11g. I have created "datatest" to be the user and I granted all possible rights that was there. :) but still getting this error message.
Does Oracle has a GUI tool somewhere I can try or how I can fix this issue? PLEASE HELP.
Below are the actions taken:
=========================================================================
C:\app\Administrator\admin\ORCLENT1\dpdump>imp
Import: Release 11.2.0.1.0 - Production on Wed Aug 29 22:32:39 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: datatest
Password:
Connected to: Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Import data only (yes/no): no > no
Import file: EXPDAT.DMP > expdat.dmp
Enter insert buffer size (minimum is 8192) 30720> 8299
Export file created by EXPORT:V11.02.00 via conventional path
Warning: the objects were exported by SYSTEM, not by you
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no > no
Ignore create error due to object existence (yes/no): no > no
Import grants (yes/no): yes > yes
Import table data (yes/no): yes > yes
Import entire export file (yes/no): no > yes
. importing SYSTEM's objects into DATATEST
. importing DW_OWNER's objects into DW_OWNER
IMP-00003: ORACLE error 1435 encountered
ORA-01435: user does not exist
Import terminated successfully with warnings.
=============================================================Thanks for helping with the script. It is very helpful, especially for newbie like me. :) When I run the script, there seems to be a lot of error during this process. Here is the log. Any suggestions how I can fix this?
=====================================================
Connected to: Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
Warning: the objects were exported by SYSTEM, not by you
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. . importing table "MVW_MATCH_STATS" 335481 rows imported
. . importing table "MVW_PLAYER_AGG" 34937 rows imported
. . importing table "MVW_PLAYER_TOURNAMENT_AGG" 519174 rows imported
. . importing table "MVW_TOURNAMENT_AGG" 12785 rows imported
. . importing table "MVW_UT_AGG1" 8 rows imported
. . importing table "TMP_CATEGORY_ATP" 29999 rows imported
. . importing table "TMP_CATEGORY_WTA" 29999 rows imported
. . importing table "TMP_IMPORT_STATS_PLAYER1" 32578 rows imported
. . importing table "TMP_MATCH_COURT_TYPE" 335562 rows imported
. . importing table "TMP_PLAYER_ATP" 47070 rows imported
. . importing table "TMP_RESULT_COMBINATIONS" 16889 rows imported
. . importing table "TMP_STADIA" 852 rows imported
. . importing table "TMP_TOUR_ATP" 16762 rows imported
. . importing table "TMP_TOUR_STADIA" 5222 rows imported
. . importing table "TMP_TOUR_WTA" 9000 rows imported
. . importing table "W_COURT_TYPE_D" 7 rows imported
. . importing table "W_DATE_D" 22330 rows imported
. . importing table "W_MATCH_D" 506408 rows imported
. . importing table "W_MATCH_F" 1012812 rows imported
. . importing table "W_MINUTE_D" 1440 rows imported
. . importing table "W_PLAYER_D" 35305 rows imported
. . importing table "W_PLAYER_D_F" 23538 rows imported
. . importing table "W_PLAYER_D_M" 45804 rows imported
. . importing table "W_ROUND_D" 19 rows imported
. . importing table "W_STADIUM_D" 428 rows imported
. . importing table "W_TOURNAMENT_D" 12882 rows imported
. . importing table "W_TOURNAMENT_F" 433111 rows imported
IMP-00017: following statement failed with ORACLE error 959:
"CREATE TABLE "W_USAGE_TRACKING" ("USER_NAME" VARCHAR2(128), "REPOSITORY_NAM"
"E" VARCHAR2(128), "SUBJECT_AREA_NAME" VARCHAR2(128), "NODE_ID" VARCHAR2(15)"
", "START_TS" DATE, "START_DT" DATE, "START_HOUR_MIN" CHAR(5), "END_TS" DATE"
", "END_DT" DATE, "END_HOUR_MIN" CHAR(5), "QUERY_TEXT" VARCHAR2(1024), "QUER"
"Y_BLOB" CLOB, "QUERY_KEY" VARCHAR2(128), "SUCCESS_FLG" NUMBER(10, 0), "ROW_"
"COUNT" NUMBER(10, 0), "TOTAL_TIME_SEC" NUMBER(10, 0), "COMPILE_TIME_SEC" NU"
"MBER(10, 0), "NUM_DB_QUERY" NUMBER(10, 0), "CUM_DB_TIME_SEC" NUMBER(10, 0),"
" "CUM_NUM_DB_ROW" NUMBER(10, 0), "CACHE_IND_FLG" CHAR(1) NOT NULL ENABLE, ""
"QUERY_SRC_CD" VARCHAR2(30), "SAW_SRC_PATH" VARCHAR2(250), "SAW_DASHBOARD" V"
"ARCHAR2(150), "SAW_DASHBOARD_PG" VARCHAR2(150), "PRESENTATION_NAME" VARCHAR"
"2(128), "ERROR_TEXT" VARCHAR2(250), "IMPERSONATOR_USER_NAME" VARCHAR2(128),"
" "NUM_CACHE_INSERTED" NUMBER(10, 0), "NUM_CACHE_HITS" NUMBER(10, 0), "QUERY"
"_DATE_WID" NUMBER(10, 0)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 ST"
"ORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS"
" 1 BUFFER_POOL DEFAULT) TABLESPACE "DW_DATA" NOLOGGING NOCOMPRESS LOB ("QUE"
"RY_BLOB") STORE AS BASICFILE (TABLESPACE "DW_DATA" ENABLE STORAGE IN ROW C"
"HUNK 8192 RETENTION NOCACHE NOLOGGING STORAGE(INITIAL 65536 NEXT 1048576 "
"MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))"
IMP-00003: ORACLE error 959 encountered
ORA-00959: tablespace 'DW_DATA' does not exist
. . importing table "W_USER" 8 rows imported
IMP-00017: following statement failed with ORACLE error 942:
"CREATE SNAPSHOT "MVW_UT_AGG1" ( "USER_NAME","QUERY_COUNT","ROW_COUNT" ) US"
"ING ("MVW_UT_AGG1", (9, 'ORCL', 1, 0, 0, "DW_OWNER", "W_USAGE_TRACKING", '2"
"012-05-31:23:56:48', 8, 74659, '2012-05-31:23:56:48', '', 1, '0280', 281368"
"84, 0, NULL), 2101313, 10, ('1950-01-01:12:00:00', 25, 0, 0, 28136884, 0, 2"
"098180, 2, NULL, NULL)) REFRESH COMPLETE AS"
"SELECT "
"user_name,"
"count(*) as query_count,"
"sum(row_count) as row_count"
"FROM W_USAGE_TRACKING "
"group by user_name"
IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00017: following statement failed with ORACLE error 12003:
"ALTER SNAPSHOT "MVW_UT_AGG1" COMPILE"
IMP-00003: ORACLE error 12003 encountered
ORA-12003: materialized view "YANXIZAOTENNIS"."MVW_UT_AGG1" does not exist
About to enable constraints...
Import terminated successfully with warnings.
============================== -
How to Use dyanamic table in query?
Hi,
can you please tell.in query -
1] if we define a varibale and in that varibale we have to speacfy the dynamic table name can it's possible.
2] I tried but it's not working
3] Every year i have taken a backup table and from that backup table i feteched the data.But i want to do this programmatically
e.g. Table name is pf_emp_pf_txn20122013 but this is "20122013" this dynamic .How we use in query that dyanamic table .
Kindly Suggest,
Regards,
SachinRHELSENSEI wrote:
Your EXEC executes in a different context, therefore it is not aware of any variables that have been declared in your original context. You should be able to use a temp table instead of a table variable as shown in the simple demo below.
create table #t (id int)
declare @value nchar(1) set @value = N'1'
declare @sql nvarchar(max)
set @sql = N'insert into #t (id) values (' + @value + N')'
exec (@sql)
select * from #t
drop table #t
Epic. Fail.
SQL-Server syntax and features for an Oracle problem. Features that are not relevant at all to Oracle, but the very reason why SQL-Server is technically inferior to Oracle...
Are you a professional idiot, or just a very gifted amateur? -
Oracle equivalent to SQL Server Table Variables ?
Does Oracle have anything equivalent to SQL Server table variables, that can be used in the JOIN clause of a select statement ?
What I want to do is execute a query to retrieve a two-column result, into some form of temporary storage (a collection ?), and then re-use that common data in many other queries inside a PL/SQL block. I could use temporary tables, but I'd like to avoid having to create new tables in the database, if possible. If I was doing this in SQL Server, I could use a table variable to do this, but is there anything similar in Oracle ? SQL Server example:
use Northwind
DECLARE @myVar TABLE(CustomerID nchar(5), CompanyName nvarchar(40))
INSERT INTO @myVar(CustomerID, CompanyName)
select CustomerID, CompanyName
from Customers
--Join the variable onto a table in the database
SELECT *
FROM @myVar mv join Customers
on mv.CompanyName = Customers.CompanyName
The closest I've found in Oracle is to use CREATE TYPE to create new types in the database, and use TABLE and CAST to convert the collection to a table, as shown below. I can't see anyway without creating new types in the database.
CREATE TYPE IDMap_obj AS Object(OldID number(15), NewID number(15));
CREATE TYPE IDMap_TAB IS TABLE OF IDMap_obj;
DECLARE
v_Count Number(10) := 0;
--Initialize empty collection
SourceIDMap IDMap_TAB := IDMap_TAB();
BEGIN
--Populate our SourceIDMap variable (dummy select statement for now).
FOR cur_row IN (select ID As OldID, ID + 10000000 As NewID From SomeTable) LOOP
SourceIDMap.extend;
SourceIDMap(SourceIDMap.Last) := IDMap_obj(cur_row.OldId, cur_row.NewId);
END LOOP;
--Print out contents of collection
FOR cur_row IN 1 .. SourceIDMap.Count LOOP
DBMS_OUTPUT.put_line(SourceIDMap(cur_row).OldId || ' ' || SourceIDMap(cur_row).NewId);
END LOOP;
--OK, can we now use our collection in a JOIN statement ?
SELECT COUNT(SM.NewID)
INTO v_Count
FROM SomeTable ST JOIN
TABLE(CAST(SourceIDMap As IDMap_TAB)) SM
ON ST.ID = SM.OldID;
DBMS_OUTPUT.put_line(' ' );
DBMS_OUTPUT.put_line('v_Count is ' || v_Count);
END;Hi, got this from our plsql guys:
The term "table function" is a bit confusing here. In Oracle-speak, it means a function that can be used in the from list of a select statement thus:
select * from Table(My_Table_Function()),..
where...
The function's return type must be a collection that SQL understands. So for the interesting case -- mimicking a function with more than one column -- this would be a nested table of ADTs where both the ADT and the nested table are defined at schema level. PL/SQL -- by virtue of some clever footwork -- allows you to declare the type as a nested table of records where both these types are declared in a package spec. This alternative is generally preferred, especially because the nested table can be of Some_Table%rowtype (or Some_Cursor%rowtype if you prefer).
As I understand it from our man on the ANSI committee, our use terminology follows the standard.
The construct below seems to be a bit different (though there are similarities) because it appears from your code sample that it's usable only within procedural code. And the object from which you select is a variable rather than a function.
So, after that preamble... the answer would be:
No, we don't have any constructs to let you "declare" something that looks like a regular schema-level table as a PL/SQL variable -- and then use (static) SQL on it just as if it were a schema-level table.
But yes, you can use PL/SQL's pipelined table function to achieve much of the same effect.
Look at the attached Table_Function.sql.
It shows that you can populate a collection of records using ordinary PL/SQL code. You can't use SQL for insert, update, or delete on such a collection. I see that SQL Server lets you do
insert into Program_Variable_Table select... from Schema_Level_Table
The PL/SQL equivalent would be
select...
bulk collect into Program_Variable_Collection
from Schema_Level_Table
The attached shows that once you have populated your collection, then you can then query it with regular SQL -- both from inside PL/SQL code and from naked SQL.
and the code is here
CONNECT System/p
-- Drop and re-create "ordinary" user Usr
EXECUTE d.u
CONNECT Usr/p
create table Schema_Things(ID number, Description Varchar2(80))
create package Pkg is
subtype Thing_t is Schema_Things%rowtype;
type Things_t is table of Thing_t; -- index by pls_integer
Things Things_t;
-- PLS-00630: pipelined functions must have
-- a supported collection return type
-- for "type Things_t is table of Thing_t index by pls_integer".
function Computed_Things return Things_t pipelined;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer);
end Pkg;
create package body Pkg is
function Computed_Things return Things_t pipelined is
Idx pls_integer;
Thing Thing_t;
begin
Idx := Things.First();
while Idx is not null loop
pipe row (Things(Idx));
Idx := Things.Next(Idx);
end loop;
end Computed_Things;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer) is
begin
Things := Things_t();
Things.Extend(No_Of_Rows);
for j in 1..No_Of_Rows loop
Things(j).ID := j;
Things(j).Description := To_Char(j, '00009');
end loop;
insert into Schema_Things
select * from Table(Pkg.Computed_Things());
end Insert_Schema_Things;
end Pkg;
-- Test 1.
begin Pkg.Insert_Schema_Things(100); end;
select * from Schema_Things
-- Test 2.
begin
Pkg.Things := Pkg.Things_t();
Pkg.Things.Extend(20);
for j in 1..20 loop
Pkg.Things(j).ID := j;
Pkg.Things(j).Description := To_Char(j, '00009');
end loop;
for j in 1..5 loop
Pkg.Things.Delete(5 +2*j);
end loop;
end;
select * from Table(Pkg.Computed_Things())
/ -
Using Table Variables MSSQL with xMII 11.5
I was trying an experiment with a query today where instead of creating a temp table in SQL, I used the T-SQL table variable. For a simple example:
DECLARE @ProductTotals TABLE
( ProductID int, Revenue money)
INSERT INTO @ProductTotals (ProductID, Revenue)
SELECT ProductID, SUM(UnitPrice * Quantity)
FROM [Order Details]
GROUP BY ProductID
SELECT *
FROM @ProductTotals
Well, this works fine in SQL Query Analyzer , but not in xMII. I get a message that says "no results returned from this query" So you ask, "why not just use a temp table" Well on the real application, the query can take up to 30 seconds to run, and I have the chance of having multiple users execute the same query in that time, in which my temp table will get stomped on creating an error. So I thought of using table variables as a possible alternative to avoid this.
I have already figured a work around, I put this code into a stored procedure and call that. I could also do a similar workaround using separate queries / BLS. However, I'm curious why xMII wouldn't execute this in the first place, being that it worked fine in Query Analyzer against the exact same database.Doug,
I tried on my box with the "sqljdbc.jar" from 11.08.2006 (German Dateformat dd.MM.yyyy) and works also.
For my test I had using the following SQL-Statement:
DECLARE @ProductTotals TABLE
( ProductCount int, ProductID int, Revenue money)
INSERT @ProductTotals
SELECT count(O.ProductID) as ProductCount, P.ProductID, SUM(O.UnitPrice * O.Quantity)
FROM [Order Details] O
INNER JOIN Products P
ON O.ProductID = P.ProductID
GROUP BY P.ProductID
SELECT *
FROM @ProductTotals
Did you get a result back in MII only for the SELECT statement
SELECT count(O.ProductID) as ProductCount, P.ProductID, SUM(O.UnitPrice * O.Quantity)
FROM [Order Details] O
INNER JOIN Products P
ON O.ProductID = P.ProductID
GROUP BY P.ProductID
? My opinion is, that your select brings nothing back.
Regards
Pedro -
Can i change table in query as per user given data
hi master
sir,
can i change table in query as per user given data
see
select * from @variable
i need use in lov
please give me idea
thankingyou
AamirYou cant directly use in sql instead you can write an anonymous block and frame the query as per the input table name and then use execute immediate to execute the query.
Something like this
declare
qry_table varchar2(30);
qry_stmt varchar2(1000);
type typ_sample is table of VARCHAR2(100) index by binary_integer;
tab_sample typ_sample ;
begin
qry_table := &Table_name
qry_stmt := 'select a from '||qry_table;
execute immediate qry_stmt bulk collect into tab_sample ;
end;
Message was edited by:
Shasi
Maybe you are looking for
-
I was having a problem installing the latest version of Firefox. ZZXC gave me a link and I downloaded it. I installed it and was asked to see if it was the latest verson by clicking on the Firefox link. When I did that, chat shut down and I don't kno
-
My PROs And CONs Opinion of This New Forum
Hello, Since I've only been a member for a short time; my exposure has been limited; however, my opinions follow: PROs This forum has excellent support from "volunteer moderators" and Lenovo Staff. They are literally "all over the place" trying to as
-
G5 Power Mac will not turn on.
I have a G5 dual 1.8, one of the earlier models, and I'm guessing the ram restart thing will not work on it. I was just using Safari, and the computer completely shut down, since then, I have not been able to turn it back on, I've tried using a diffe
-
I have a G4 that my kids use, I am not even sure of the OS, though it is at least 10.2. I was on it today and noticed Software update had a security update, so I did it. Now the the computer will not reboot. There is no tone, just frozen on the gray
-
When I activated VoiceOver, capital s was used to start reading. I cannot turn it off so as to be able to use capital s in ordinary utilities (Word, textedit..) Restarting did not help.