How to declare variable in table valued function
hello.
i have the following code to define a inline table valued function
but the use of cmn.ReshteId('Lf_WL') as a function in where clause is not good performance.
Alter function lf.fn_WholeLifeBn_GetForm(@ViewKind tinyint, @CurrentLocation int) returns table
as
return
select B.*
from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
where Reshte = cmn.ReshteId('Lf_WL')
for better performance following code is good:
declare @Reshte smallint
set @Reshte = cmn.ReshteId('Lf_TS')
select B.*
from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
where Reshte = @Reshte
but can not use it as the first code block in inline function.
please help for define a good function.
What do you think about Multi-Statement Table-Valued UDFs?
create function Func(@Var int)
returns @T table(ColName int)
as
begin
insert into @T(ColName) values (@Var)
return
end
select * from Func(10)
select * from Func(20)
---or
alter function Func()
returns @T table(ColName int)
as
begin
declare @Var int
set @Var = 10
insert into @T(ColName) values (@Var)
return
end
select * from Func()
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
How to declare variable for Table type in the ABAP Editor
Hi!
I have Table Type 'FIELDNAME_TAB' (Table of fieldnames). I want to pass the list of fieldnames to this Table Type in the ABAP Editor.
Can anyone help me in this?You would declare the internal table like so.
data: itab type FIELDNAME_TAB.
data: wa like line of itab.
wa = 'This_value'.
append wa to itab.
Regards.
Rich Heilman
Message was edited by:
Rich Heilman -
How to migrate SQL serveer table-valued functions into Oracle 10g
hi ,
i'm trying to migrate from SQL server to Oracle. There are some Table_valued functions ( Function that returns table). while migrating using SQL Developer it uses cursor for every table query. is this is the only solution to migrate functions returning table? This tables contains more than LAKH of records? so if there any other solution on this please reply. the sample code is bellow.
CREATE function FU_AIG_S_GET_LOG
returns TABLE
as
RETURN
SELECT U_AIG.T_AIG_LOG.AIG_LOG_NB_IDLOG,
U_AIG.T_AIG_LOG.AIG_LOG_NB_EVTSUIVI,
U_AIG.T_AIG_LOG.AIG_LOG_NB_CODELOG,
U_AIG.T_AIG_LOG.AIG_LOG_DT_CREATION,
U_AIG.T_AIG_LOG.AIG_LOG_CL_XMLEVT,
U_AIG.T_AIG_TYPELOG.AIG_TYPELOG_VC_NOMLOG
FROM U_AIG.T_AIG_LOG INNER JOIN U_AIG.T_AIG_TYPELOG
ON U_AIG.T_AIG_LOG.AIG_LOG_NB_CODELOG =
U_AIG.T_AIG_TYPELOG.AIG_TYPELOG_NB_CODELOG
WHERE AIG_LOG_NB_LU = 0;
thanks
sush
Message was edited by:
user610355
Message was edited by:
user610355I don't think there's good work around over that. Mysql .sql file syntax is a little different from Oracle. Especially the DDLs.
Unless you are willing to blindly run the .sql file and fix the one failed manually. -
SQL: Issue with running out of storage on server when running table-valued function
SQL Version: 2008 (not r2)
Problem: I'm getting the following error message when running a table-valued function:
Msg 1105, Level 17, State 2, Line 1
Could not allocate space for object 'dbo.SORT temporary run storage: 141072001204224' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files
to the filegroup, or setting autogrowth on for existing files in the filegroup.
Request: Could anyone tell me if there are modifications that I could make to my SQL code to avoid this storage issues?
Thanks,
....bob sutor
Code Facts:
The JCCD table is a large table 2MM records
The other tables in the JOINS are very small 15 records or less
SQL Function Code:
ALTER FUNCTION [dbo].[xcft_XAWP_GLBalance_JCCD_Detail]()
RETURNS @JCGLDetail TABLE
JCCo tinyint
, Job varchar(10)
, PostingSource varchar(10)
, CostToDate numeric(12,2)
, Phase varchar(20)
, EarnType smallint
, LiabilityType smallint
, CostType tinyint
, ControllingSetting varchar(30)
, GLAccountCharged varchar(20)
, DeptNum varchar(10)
, DeptDesc varchar(30)
, JCDC_CostType tinyint
, CostTypeGL_Open varchar(20)
, CostTypeGL_Closed varchar(20)
, JCDO_ExcludePR varchar(1)
, JCDO_Phase varchar(20)
, PhaseGL_Open varchar(20)
, PhaseGL_Closed varchar(20)
, JCDL_LiabType smallint
, LiabTypeGL_Open varchar(20)
, LiabTypeGL_Closed varchar(20)
, JCDE_EarnType smallint
, EarnTypeGL_Open varchar(20)
, EarnTypeGL_Closed varchar(20)
AS
BEGIN
DECLARE
@WIPMonthCurrent date
SET @WIPMonthCurrent = (Select TOP 1 WIPMonth FROM udxcWIPMonths WHERE ActiveWIPPeriod = 'Y')
INSERT INTO @JCGLDetail
JCCo
, Job
, PostingSource
, CostToDate
, Phase
, EarnType
, LiabilityType
, CostType
, DeptNum
, DeptDesc
, JCDC_CostType
, CostTypeGL_Open
, CostTypeGL_Closed
, JCDO_ExcludePR
, JCDO_Phase
, PhaseGL_Open
, PhaseGL_Closed
, JCDL_LiabType
, LiabTypeGL_Open
, LiabTypeGL_Closed
, JCDE_EarnType
, EarnTypeGL_Open
, EarnTypeGL_Closed
SELECT
JCCD.JCCo, JCCD.Job, JCCD.Source, sum(JCCD.ActualCost) AS CostToDate, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
, JCDM.Department, JCDM.Description
, JCDC.CostType AS JCDC_CostType, JCDC.OpenWIPAcct AS CostTypeGL_Open, JCDC.ClosedExpAcct AS CostTypeGL_Closed
, JCDO.ExcludePR AS JCDO_ExcludePR, JCDO.Phase AS JCDO_Phase, JCDO.OpenWIPAcct AS PhaseGL_Open, JCDO.ClosedExpAcct AS PhaseGL_Closed
, JCDL.LiabType AS JCDL_LiabType, JCDL.OpenBurdenAcct AS LiabTypeGL_Open, JCDL.ClosedBurdenAcct AS LiabTypeGL_Closed
, JCDE.EarnType AS JCDE_EarnType, JCDE.OpenLaborAcct AS EarnTypeGL_Open, JCDE.ClosedLaborAcct AS EarnTypeGL_Closed
FROM JCCD
LEFT JOIN JCJP ON JCCD.JCCo = JCJP.JCCo AND JCCD.Job = JCJP.Job
LEFT JOIN JCCM ON JCJP.JCCo = JCCM.JCCo AND JCJP.Contract = JCCM.Contract
LEFT JOIN JCDM ON JCCM.JCCo = JCDM.JCCo AND JCCM.Department = JCDM.Department
LEFT JOIN JCDC ON JCDM.JCCo = JCDC.JCCo AND JCDM.Department = JCDC.Department AND JCCD.CostType = JCDC.CostType
LEFT JOIN JCDE ON JCDM.JCCo = JCDE.JCCo AND JCDM.Department = JCDE.Department AND JCCD.EarnType = JCDE.EarnType
LEFT JOIN JCDO ON JCDM.JCCo = JCDO.JCCo AND JCDM.Department = JCDO.Department AND JCCD.Phase = JCDO.Phase
LEFT JOIN JCDL ON JCDM.JCCo = JCDL.JCCo AND JCDM.Department = JCDL.Department AND JCCD.LiabilityType = JCDL.LiabType
LEFT JOIN xcft_XAWP_FiscalPeriodCutoffs_ForWIPMonth() AS cutoffs ON JCCD.JCCo = cutoffs.GLCo
WHERE
JCCD.Mth <= cutoffs.FiscalYear_LastMonth
AND JCCD.Job IN(SELECT JobNum FROM budxcWIPData_SQL WHERE WIPMonth = @WIPMonthCurrent)
AND JCCD.JCCo IN(SELECT JCCo FROM JCCO WHERE udExcludeFromWIP <> 'Y' or udExcludeFromWIP IS NULL)
--AND LTRIM(RTRIM(JCCD.Job)) = '71-'
GROUP BY
JCCD.JCCo, JCCD.Job, JCCD.Source, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
, JCDM.Department, JCDM.Description
, JCDC.CostType, JCDC.OpenWIPAcct, JCDC.ClosedExpAcct
, JCDO.ExcludePR, JCDO.Phase, JCDO.OpenWIPAcct, JCDO.ClosedExpAcct
, JCDL.LiabType, JCDL.OpenBurdenAcct, JCDL.ClosedBurdenAcct
, JCDE.EarnType, JCDE.OpenLaborAcct, JCDE.ClosedLaborAcct
UPDATE @JCGLDetail
SET
ControllingSetting =
CASE WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'N' THEN 'PhaseOverride-PR Excluded'
WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'Y'
AND EarnType NOT IN(Select EarnType FROM JCDE WHERE JCDE.JCCo = JCCo AND JCDE.Department = DeptNum)
AND LiabilityType NOT IN(Select LiabType FROM JCDL WHERE JCDL.JCCo = JCCo AND JCDL.Department = DeptNum)
THEN 'PhaseOverride-PR Not Excluded'
WHEN EarnType = JCDE_EarnType THEN 'Earn Type Override'
WHEN LiabilityType = JCDL_LiabType THEN 'Liability Type Override'
ELSE 'Cost Type' END
UPDATE @JCGLDetail
SET
GLAccountCharged =
CASE WHEN ControllingSetting = 'PhaseOverride-PR Excluded' OR ControllingSetting = 'PhaseOverride-PR Not Excluded'
THEN PhaseGL_Open
WHEN ControllingSetting = 'Earn Type Override' THEN EarnTypeGL_Open
WHEN ControllingSetting = 'Liability Type Override' THEN LiabTypeGL_Open
ELSE CostTypeGL_Open END
RETURN
END
Bob Sutorwell, did you either restart the instance or add another tempdb file (no restart required) to let other transactions continue on the server.
or check if autogrowth was limited, change that to unlimnited , to the transactions conintue..
the function may be dumping the data on to tempdb, how much data are you excepting back...what are indexes on the tables
Hope it Helps!! -
Whats the difference betweeen passing the table variable and table valued parameter?
Hi Everbody
Can someone one tell me what's the difference between passing a table variable and table valued parameter to a stored procedure or function? Can both be used to pass a table to a stored procedure/function?
Regards
RegardsThey are essentially the same. What we call a table variable is a local
variable. A table-valued parameter is an incoming parameter to the
procedure. The only difference is that the parameter is readonly.
When you call a stored procedure, you can pass a table variable as the
actual parameter. Or a table-valued parameter that you pass on.
CREATE PROCEDURE nisse_sp @tvp sometype READONLY AS
DECLARE @local someothertabletype
EXEC pelle_sp @tvp, @local
Erland Sommarskog, SQL Server MVP, [email protected] -
SQL Server Multiple JOINS with Table Value Function - query never ends
I have a query with 4 joins using a table value function to get the data and when I execute it the query never ends.
Issue Details
- Table value function
CREATE FUNCTION [dbo].[GetIndicator]
@indicator varchar(50),
@refDate datetime
RETURNS
TABLE
AS
RETURN
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
- Query
DECLARE @RefDate datetime
SET @RefDate = '30 April 2014 23:59:59'
SELECT DISTINCT OTHERTABLE.Id As Id
FROM
GetIndicator('ID#1_0#INDICATOR_X',@RefDate) AS OTHERTABLE
JOIN GetIndicator('ID#1_0#INDICATOR_Y',@RefDate) AS YTABLE
ON OTHERTABLE.SomeId=YTABLE.SomeId
AND OTHERTABLE.DateOfEntry=YTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_Z',@RefDate) AS ZTABLE
ON OTHERTABLE.SomeId=ZTABLE.SomeId
AND OTHERTABLE.DateOfEntry=ZTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_W',@RefDate) AS WTABLE
ON OTHERTABLE.SomeId=WTABLE.SomeId
AND OTHERTABLE.DateOfEntry=WTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_A',@RefDate) AS ATABLE
ON OTHERTABLE.SomeId=ATABLE.SomeId
AND OTHERTABLE.DateOfEntry=ATABLE.DateOfEntry
Other details:
- SQL server version: 2008 R2
- If I execute the table function code outside the query, with the same args, the execution time is less the 1s.
- Each table function call return between 250 and 500 rows.Hi,
Calling function in general is a costly query. And definitely joining with a function 5 times in not an efficient one.
1. You can populate the results for all parameters in a CTE or table variable or temporary table and join (instead of funtion) for different parameters
2. Looks like you want fetch the IDs falling to different indicators for the same @Refdate. You can try something like this
WITH CTE
AS
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1, T4.Name
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
SELECT * FROM CTE WHERE Name = 'ID#1_0#INDICATOR_X' AND Name = 'ID#1_0#INDICATOR_Y' AND Name = 'ID#1_0#INDICATOR_Z' AND Name = 'ID#1_0#INDICATOR_W' AND Name = 'ID#1_0#INDICATOR_A' AND ReferenceDate = @RefDate.
Or you can even simplify more depends on your requirement.
Regards,
Brindha. -
In which condition Table valued function should prefer over SP except use in joins?
Hi,
My requirements is:
Entity framework needs to call DB object (TVF or SP), which will provide some data to them and they'll work on it at app level.
DB object would be simple, one result set, it will join 5 tables and get around 30 columns to them. it would be parameterized query so can't use view.
Now my question is what DB object would be best to use, table valued function or store procedure. and why?
I google on it, I find some interesting links (example http://technet.microsoft.com/en-us/library/ms187650(v=sql.105).aspx)
they mentioned conditions to convert SP to TVF but not mentioned the reason, why I should convert?
Both have same cache plans strategy. SP has so many advantages over TVF, but I don't see any technical advantage of TVF over SP except it can be use in joins or so.
so In short my question is, why I can't use SP in all cases, why I would use TVF?, and which Table valued or multi-valued?
would appreciate your time and response.According to a few recent blogs you should be able to use TVP or stored procedure with EF 6.1.2 with ease. In our application we haven't switched yet to 6.1.2 (we're using 6.0.0) and there is no support for stored procedures or functions so we use StoreQuery.
I am wondering if you can share your experience of using EF with SP or TVP (and document the steps).
I am also wondering as how exactly it's working behind the scenes and where the full query is taking place. Say, in our case we may want to add some extra conditions after retrieving a set using, say, SP. Would the final query execute on the client (e.g.
SP executed on the server, result returned and then extra conditions executed on the "client")?
As I said, right now we're using StoreQuery which means that our extra conditions must be case - sensitive as opposed to SQL Server case insensitive. So, if someone already tried that scenario and can tell me how exactly it works, I would appreciate it.
Another question about EF - I defined a property as
[Column(TypeName = "varchar")]
public string PhoneNumber { get; set; } // area code + phone
and in the LINQ query as
var query = db.Accounts.Select(a => new AccountsList
AcctName = a.AcctName,
Contact = a.Contact,
FullName = a.FullName,
AreaCode = a.AreaCode,
Phone = a.Phone,
Hidden = a.Hide,
Hide = a.Hide,
PhoneNumber = a.AreaCode.Trim() + a.Phone.Trim(),
AcctTypeId = a.AcctTypeId
and I see that it's translated into CASE AreaCode IS NULL THEN N'' ELSE RTRIM(LTRIM(areaCode)) END + ...
My question is - why EF does it if there is no mentioning at all in the class as how NULL is supposed to be treated. Is it a bug?
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
SQL CLR Table-Valued Function System.NullReferenceException
Good day.
I wrote a clr table-valued function that gets the data from the sharepoint list using the client model.
Sometimes I get exception (When I calling this function I get 90000 rows and then I get this exception...):
Msg 6260, Level 16, State 1, Line 1
An error occurred while getting new row from user defined Table Valued Function :
System.NullReferenceException: Object reference not set to an instance of an object. System.NullReferenceException: v at SDS.FillRow(Object obj, SqlInt32& month, SqlString& datePlanSalary, SqlString& dilerCode, SqlString& dilerName, SqlString&
model, SqlInt32& countSalary).
How can I fix this issue?
My Code:
public class SDS
[SqlFunction(SystemDataAccess = SystemDataAccessKind.Read, FillRowMethodName = "FillRow")]
public static IEnumerable SDSItems(SqlString url, SqlString listName)
ClientContext context = new ClientContext(url.ToString());
List list = context.Web.Lists.GetByTitle(listName.ToString());
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection listItems = list.GetItems(query);
context.Load(list);
context.Load(listItems);
context.ExecuteQuery();
return listItems;
public static void FillRow(
object obj,
out SqlInt32 month,
out SqlString datePlanSalary,
out SqlString dilerCode,
out SqlString dilerName,
out SqlString model,
out SqlInt32 countSalary
item = (ListItem)obj;
month = Convert.ToInt32(item["_x041c__x0435__x0441__x044f__x04"]);
datePlanSalary = Convert.ToString(item["_x0414__x0430__x0442__x0430__x000"]);
dilerCode = Convert.ToString(item["_x041a__x043e__x0434__x0020__x04"]);
dilerName = Convert.ToString(item["_x041d__x0430__x0437__x0432__x04"]);
model = ((FieldLookupValue)item["_x041c__x043e__x0434__x0435__x04"]).LookupValue;
countSalary = Convert.ToInt32(item["_x041a__x043e__x043b__x0438__x04"]);That's not a lot of information to go on, but...
Can you put a check in your FillRow method for a null object (or one of your fields being null) and put out diagnostic information? Or is it happening in the ListItemCollection iterator itself? (i.e. before it returns a row back to FillRow). If it's happening
in the iterator, perhaps you could subclass it and return diagnostics at that point.
I'm also wondering (if it actually always happen at row 90000) if you're hitting a limit in web service call, or iterator, or UDF code. Does the function ever return more than 90000 rows successfully?
Hope this helps, Bob -
Table-Valued function in oracle
Hi All,
I have a table-valued function in MS SQL Server, that I want to convert it.
How can I create table-valued function in Oracle 9.2.0.1.0
Thanks for your thoughtsJust so we are talking the same language, array-type constructs in Oracle are generally known as "collections", while "table" generally refers to a database table. Having said that, you may see references to "PL/SQL Tables" which was the old name for collections when they first came out, although this term has been mostly withdrawn as it's somewhat misleading and causes confusion (that's marketing for you).
Now I think about it we also have table functions, the official name for functions that return collections although IMO almost as misleading. Anyway my rambling point is that "function that returns a table" may cause confusion in Oracle circles. Or maybe it's just me.
There are loads of String To Table examples around:
* www.williamrobertson.net/documents/comma-separated.html
* www.oracle-developer.net/display.php?id=412
Couldn't you have the procedure accept an array in the first place and have something else do the string conversion before it reaches the procedure?
Edited by: William Robertson on Aug 29, 2008 5:39 PM -
Table-Valued Function not returning any results
ALTER FUNCTION [dbo].[fGetVendorInfo]
@VendorAddr char(30),
@RemitAddr char(100),
@PmntAddr char(100)
RETURNS
@VendorInfo TABLE
vengroup char(25),
vendnum char(9),
remit char(10),
payment char(10)
AS
BEGIN
insert into @VendorInfo (vengroup,vendnum)
select ks183, ks178
from hsi.keysetdata115
where ks184 like ltrim(@VendorAddr) + '%'
update @VendorInfo
set remit = r.remit
from
@VendorInfo ven
INNER JOIN
(Select ksd.ks188 as remit, ksd.ks183 as vengroup, ksd.ks178 as vendnum
from hsi.keysetdata117 ksd
inner join @VendorInfo ven
on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
where ksd.ks192 like ltrim(@RemitAddr) + '%'
and ks189 = 'R') r
on ven.vengroup = r.vengroup and ven.vendnum = r.vendnum
update @VendorInfo
set payment = p.payment
from
@VendorInfo ven
INNER JOIN
(Select ksd.ks188 as payment, ksd.ks183 as vengroup, ksd.ks178 as vendnum
from hsi.keysetdata117 ksd
inner join @VendorInfo ven
on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
where ksd.ks192 like ltrim(@PmntAddr) + '%'
and ks189 = 'P') p
on ven.vengroup = p.vengroup and ven.vendnum = p.vendnum
RETURN
END
GO
Hi all,
I'm having an issue where my Table-Valued Function is not returning any results.
When I break it out into a select statement (creating a table, and replacing the passed in parameters with the actual values) it works fine, but with passing in the same exact values (copy and pasted them) it just retuns an empty table.
The odd thing is I could have SWORN this worked on Friday, but not 100% sure.
The attached code is my function.
Here is how I'm calling it:
SELECT * from dbo.fGetVendorInfo('AUDIO DIGEST', '123 SESAME ST', 'TOP OF OAK MOUNTAIN')
I tried removing the "+ '%'" and passing it in, but it doesn't work.
Like I said if I break it out and run it as T-SQL, it works just fine.
Any assistance would be appreciated.Why did you use a proprietary user function instead of a VIEW? I know the answer is that your mindset does not use sets. You want procedural code. In fact, I see you use an “f-” prefix to mimic the old FORTRAN II convention for in-line functions!
Did you know that the old Sybase UPDATE.. FROM.. syntax does not work? It gives the wrong answers! Google it.
Your data element names make no sense. What is “KSD.ks188”?? Well, it is a “payment_<something>”, “KSD.ks183” is “vendor_group” and “KSD.ks178” is “vendor_nbr” in your magical world where names mean different things from table to table!
An SQL programmer might have a VIEW with the information, something like:
CREATE VIEW Vendor_Addresses
AS
SELECT vendor_group, vendor_nbr, vendor_addr, remit_addr, pmnt_addr
FROM ..
WHERE ..;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Problem with dg4msql and table-valued functions
Have configured dg4msql to connect from my oracle db to ms sql server.
Am able to do simple SELECTs from ms sql tables like:
select * from "sys"."procedures"@dg4msql;
or
select * from "dbo"."SomeTable"@dg4msql;
But am unable to do a SELECT from a table-valued function:
select * from "dbo"."GetData"@dg4msql('param1value');
or
select * from "dbo"."GetData"('param1value')@dg4msql;
In both cases I get:
ORA-00933: SQL command not properly ended
It does not like the parameters portion of the query ("('param1value')")
initdg4msql.ora:
HS_FDS_CONNECT_INFO=[svr1]//mydb
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_PROC_IS_FUNCT=TRUE
HS_FDS_RESULTSET_SUPPORT=TRUE
Have tried the other set of params:
HS_FDS_PROC_IS_FUNCT=FALSE
HS_FDS_RESULTSET_SUPPORT=TRUE
Same story. After changing the init*** file have bounced both Listeners (DB and Gateway), reconnected, and re-run the query.
Have I missed something?
Any help is greatly appreciated!Sorry, but for me it looks you did not get the problem.
Oracle® Database Gateway for SQL Server User's Guide,:
11g Release 2 (11.2)
Part Number E12069-02
*2 SQL Server Gateway Features and Restriction*
Result Sets and Stored Procedures
The Oracle Database Gateway for SQL Server provides support for stored procedures which return result sets.
By default, all stored procedures and functions do not return a result set to the user. To enable result sets, set the HS_FDS_RESULTSET_SUPPORT parameter value to TRUE.
PL/SQL Program Fetching from Result Sets in Sequential Mode
-- Execute procedure
out_arg := null;
refcurproc@MSQL('Hello World', out_arg, rc1);
Somewhere in this forum I've seen a message that the syntax "SELECT ... FROM sp@db(param1, param2)" works.
Anyway, even with the PL/SQL block the error message is the same - ORA-00933 "SQL command not properly ended"
and the cursor (* in SQL*PLUS) is put just at the first bracket.
Edited by: user636213 on Aug 10, 2012 5:17 AM -
How to declare variables in standard text - so10 t.code
Hello Friends,
How to declare variables in standard text - so10 t.code? Your response will be appreciated much.
Thanks
SriFor Script & Smartform Text - &VAR&
-
JDBC Adapter Call a Table-Valued Function
Hello to all,
we're using the JDBC adapter to access a MS SQL-Server 2008.
I have to call a "Table-Valued Function" via JDBC.
Has anybody done this?
I've tried to call it like a stored procedure with the following:
<ns1:LGBuchungSAP_REQ xmlns:ns1="http://xyz.de/pi/mav/kantine">
<fLGBuchungenSAP>
<Tablename action="execute">
<table>dbo.fLGBuchungenSAP</table>
</Tablename>
</fLGBuchungenSAP>
</ns1:LGBuchungSAP_REQ>
but I get following error:
com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser:
Error when executing statement for table/stored proc. 'dbo.fLGBuchungenSAP' (structure 'fLGBuchungenSAP'): com.microsoft.sqlserver.jdbc.SQLServerException:
Fehler bei der Anforderung für 'fLGBuchungenSAP' (Prozedur), weil 'fLGBuchungenSAP' ein Tabellenwertfunktion-Objekt ist.
Calling with a select-statement also fails:
<ns1:LGBuchungSAP_REQ xmlns:ns1="http://xyz.de/pi/mav/kantine">
<STATEMENT_NAME>
<Tablename action="SELECT">
<table>dbo.fLGBuchungenSAP('20101101 00:00:00', '20110101 00:00:00')</table>
</Tablename>
</STATEMENT_NAME>
</ns1:LGBuchungSAP_REQ>
with error:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Eingangs-Message -->
<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
<SAP:Category>XIAdapterFramework</SAP:Category>
<SAP:Code area="MESSAGE">GENERAL</SAP:Code>
<SAP:P1></SAP:P1>
<SAP:P2></SAP:P2>
<SAP:P3></SAP:P3>
<SAP:P4></SAP:P4>
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'dbo.fLGBuchungenSAP('20101101 00:00:00', '20110101 00:00:00')' (structure 'STATEMENT_NAME'): java.lang.IndexOutOfBoundsException: Index: 4, Size: 4</SAP:AdditionalText>
<SAP:Stack></SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
Please advice
Regards
ChristianHello to all,
I solved the problem.
You have to call it this way:
<ns1:LGBuchungSAP_REQ xmlns:ns1="http://xyzde/pi/mav/kantine">
<STATEMENT>
<LGBuchungSAP action="SQL_DML">
<access>select * from dbo.fLGBuchungenSAP('$DatumVon$', '$DatumBis$')</access>
<key>
<DatumVon>20101101 00:00:00</DatumVon>
<DatumBis>20110101 00:00:00</DatumBis>
</key>
</LGBuchungSAP>
</STATEMENT>
</ns1:LGBuchungSAP_REQ>
But I get the next error: "A result set was generated for the update task"
<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
<SAP:Category>XIAdapterFramework</SAP:Category>
<SAP:Code area="MESSAGE">GENERAL</SAP:Code>
<SAP:P1></SAP:P1>
<SAP:P2></SAP:P2>
<SAP:P3></SAP:P3>
<SAP:P4></SAP:P4>
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'LGBuchungSAP' (structure 'STATEMENT'): com.microsoft.sqlserver.jdbc.SQLServerException: Es wurde ein Resultset für den Aktualisierungsvorgang generiert.</SAP:AdditionalText>
<SAP:Stack></SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error> -
How do i test split by value functionality in mesage mapping with multiple
how do i test split by value functionality in mesage mapping with multiple values ?
regards,
venkatrepeat your source node. in mapping editor you can view queues by right clicking to mapped element.. selecting Display Queues option.. this will show u your values .
You can also select this Display Queue option for splitByValue option
for example
source--->splitByValue>target
Try viewing your queues to each this step... for splitByValue in display Queue you will see context inserted(grey colour) accodingly -
How to declare variable in the scipt
data is coming from standard program .
rf140-stida key entry date.
bsik-bldat posting date
i want to display difference between rf140-stida and bsik-bldat in scipt form it will give number of days.
how can i declare variables for this.
how to write code in my form.Hi
U need to create a routine to calculate the difference:
/: DEFINE &DELTA& = SPACE
/: PERFORM <FORM NAME> IN PROGRAM <PROGRAN NAME>
/: USING &RF140-STIDA&
/: USING &BSIK-BLDAT&
/: CHANGING &DELTA&
&DELTA&
The routine has to be defined in your Z-PROGRAM and to have these interface:
FORM <FORM NAME> TABLES IN_TAB_EM STRUCTURE ITCSY
OUT_TAB_EM STRUCTURE ITCSY.
DATA: DELTA TYPE I.
DATA: DATE1 LIKE SY-DATUM,
DATE2 LIKE SY-DATUM.
* ---> Rembember the date has the ouput format, so it has to be converted in the
* input format
READ TABLE IN_TAB_EM WITH KEY NAME = 'RF140-STIDA'.
IF SY-SUBRC = 0.
DATE1(4) = IN_TAB_EM-VALUE+6(4).
DATE1+4(2) = IN_TAB_EM-VALUE+3(2).
DATE1+6(2) = IN_TAB_EM-VALUE(2).
ENDIF.
READ TABLE IN_TAB_EM WITH KEY NAME = 'BSIK-BLDAT'.
IF SY-SUBRC = 0.
DATE2(4) = IN_TAB_EM-VALUE+6(4).
DATE2+4(2) = IN_TAB_EM-VALUE+3(2).
DATE2+6(2) = IN_TAB_EM-VALUE(2).
ENDIF.
DELTA = DATE1 - DATE2.
READ TABLE OUT_TAB_EM WITH KEY NAME = 'DELTA'.
IF SY-SUBRC = 0.
WRITE DELTA TO OUT_TAB_EM-VALUE.
MODIFY OUT_TAB_EM INDEX SY-TABIX.
ENDIF.
ENDFORM.
Max
Maybe you are looking for
-
Porr Voice on outside call with CME using 7902 & 7970
Dear All, i'm working on a simple configuration. I'm using a 2801 with 14.4.t1 for CME 3.4. All is working fine inside, so i can call without problems others CME users. The problems come when i call outside trought a BRI, with these calls i hear a lo
-
Hi, We have migrated from 10G to 11G recenlty. There is a module called xreadlines which is used in a Jython procedure and the procedure was working fine in 10G. But in 11G its throwing an error: Import xreadlines not found. Note: This issue specific
-
Why not create an external camera for the first iPad ?
This will resolve the issue to upgrade IO6 and still available for everyone as supplemental device; this can be used for intrusion detection, or take care of the baby, for examples. Apple meet a problem, and can use it for the best of each other. I u
-
ME59N - club two PO in to single PO
Hi, We are using ME59N for PO creation. currently the system create two PO for single PR. based on the condidtion EBAN-KONNR For Item 20 EABN-KONNR values empty For Item 10 and 30 EABN-KONNR have some value. based on the above condition system creat
-
I'm just on the verge of purchasing a touchscreen monitor and a Mac Mini and installing Windows 8 using Bootcamp. I was just wondering if anybody knows how well supported Windows 8 is on Macs? I have a Macbook Air with Windows 7 and it runs exactly a