this is the code in Oracle:
pUsuario IN SAV_CAMPANAS_ENCA.USUARIO_CREA%TYPE,
pCodTipo IN SAV_TIPOS_CAMPANA.COD_TIPO%TYPE,
pCantidadRegistros IN SAV_CAMPANAS_ENCA.CANTIDAD_REGISTROS%TYPE,
pPrograma IN SAV_CAMPANAS_ENCA.PROGRAMA%TYPE,
pCodPais IN SAV_PAIS.COD_PAIS%TYPE,
pNumeroIntentos IN SAV_CAMPANAS_ENCA.MAXIMO_INTENTOS%TYPE,
SQL Server doesn't have anchored type declarations-- you can't do the equivalent of <<table>>.<<column>>%TYPE. You'd need to determine the actual data types of the underlying columns and use those. Of course, that means that if you change the data type of some column, you'd need to go through your code to change the data type of the variables that need to reference that column.
Related
We are using a software that has limited Oracle capabilities. I need to filter through a CLOB field by making sure it has a specific value. Normally, outside of this software I would do something like:
DBMS_LOB.SUBSTR(t.new_value) = 'Y'
However, this isn't supported so I'm attempting to use CAST instead. I've tried many different attempts but so far these are what I found:
The software has a built-in query checker/validator and these are the ones it shows as invalid:
DBMS_LOB.SUBSTR(t.new_value)
CAST(t.new_value AS VARCHAR2(10))
CAST(t.new_value AS NVARCHAR2(10))
However, the validator does accept these:
CAST(t.new_value AS VARCHAR(10))
CAST(t.new_value AS NVARCHAR(10))
CAST(t.new_value AS CHAR(10))
Unfortunately, even though the validator lets these ones go through, when running the query to fetch data, I get ORA-22835: Buffer too small when using VARCHAR or NVARCHAR. And I get ORA-25137: Data value out of range when using CHAR.
Are there other ways I could try to check that my CLOB field has a specific value when filtering the data? If not, how do I fix my current issues?
The error you're getting indicates that Oracle is trying to apply the CAST(t.new_value AS VARCHAR(10)) to a row where new_value has more than 10 characters. That makes sense given your description that new_value is a generic audit field that has values from a large number of different tables with a variety of data lengths. Given that, you'd need to structure the query in a way that forces the optimizer to reduce the set of rows you're applying the cast to down to just those where new_value has just a single character before applying the cast.
Not knowing what sort of scope the software you're using provides for structuring your code, I'm not sure what options you have there. Be aware that depending on how robust you need this, the optimizer has quite a bit of flexibility to choose to apply predicates and functions on the projection in an arbitrary order. So even if you find an approach that works once, it may stop working in the future when statistics change or the database is upgraded and Oracle decides to choose a different plan.
Using this as sample data
create table tab1(col clob);
insert into tab1(col) values (rpad('x',3000,'y'));
You need to use dbms_lob.substr(col,1) to get the first character (from the default offset= 1)
select dbms_lob.substr(col,1) from tab1;
DBMS_LOB.SUBSTR(COL,1)
----------------------
x
Note that the default amount (= length) of the substring is 32767 so using only DBMS_LOB.SUBSTR(COL) will return more than you expects.
CAST for CLOB does not cut the string to the casted length, but (as you observes) returns the exception ORA-25137: Data value out of range if the original string is longert that the casted length.
As documented for the CAST statement
CAST does not directly support any of the LOB data types. When you use CAST to convert a CLOB value into a character data type or a BLOB value into the RAW data type, the database implicitly converts the LOB value to character or raw data and then explicitly casts the resulting value into the target data type. If the resulting value is larger than the target type, then the database returns an error.
Using Visual Studio 2015 Enterprise
I'm trying to change a few values inside the Script Transformation Editor but they are grayed out and I can't modify them.
Here I'm trying to change ScriptLanguage to Microsoft Visual Basic:
Here I would like to change the length of this HashValue column
I've tried restarting visual studio as well as removing the script and adding it back to no avail.
EDIT: I figured out the second one by changing the data type to DT_WSTR
First Issue
Note: Once you accessed the script editor window you cannot change the it's language.
But you can change your scripts default language from visual studio options. All you have to do is go to Tools and select Options.... Under the Business Intelligence Designers option, select Integration Services Designer and change the script language to whichever you prefer your default to be.
Second Issue
You cannot change the length column of type Integer:
DT_I1 is relative to Sql tinyInt data type (0 to 255)
DT_I2 is relative to Sql Smallint data type (-2^15 (-32,768) to 2^15-1 (32,767))
DT_I4 is relative to Sql Int data type (-2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647))
DT_I8 is relative to Sql Big Int data type (-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807))
Only length for DT_STR and DT_WSTR can be changed
MSDN articles about SSIS and Sql data types:
https://msdn.microsoft.com/en-us/library/ms141036(v=sql.120).aspx
https://msdn.microsoft.com/en-us/library/ms187752.aspx
https://msdn.microsoft.com/en-us/library/ms187745.aspx
Script Component Language
The Script Component ScriptLanguage property should generally be editable, UNTIL you have used the 'Edit Script...' dialog (since this builds up the backing project which can't be converted automatically). Try creating a new Script Component and editing this value first, but I was not able to replicate this being disabled at the start with my copy of VS2015.
Data Type Properties
Data type properties are controlled mainly by the selected DataType. In this case, you have a four-byte signed integer (DT_I4), which doesn't have any other settings. Other data types have different properties, i.e.:
DT_STR (string) can set Length and CodePage (character set),
DT_WSTR (Unicode string) can only set Length,
and DT_NUMERIC can set Scale and Precision.
Our application updates and accesses data using SQL Server 2014.
I have a table of which the last column ('Contents') is created as VARCHAR(MAX).
We are using Delphi XE8, and are using a FireDAC TFDQuery component to update this column.
.....
FDquery.ParamByName('Contents').AsString:=Contents;
FDquery.ExecSQL;
When running this update, I get the following error:
Exception raised with message [FireDAC][Phys][ODBC]-345. Data too large for variable [CONTENTS]. Max len = [8002], actual len = [13829] Hint: set the TFDParam.Size to a greater value.
'Contents' can be string of varying length.
Browsing the web, the only reasonably simple solution that I found is changing the query as follows:
FDquery.ParamByName('Contents').AsWideMemo:=Contents;
FDquery.ExecSQL;
Is this acceptable, or should I be handling this differently?
There is nothing fancy with 'Contents', as I mentioned, it is simply a long string.
Is it acceptable to access a VARCHAR(MAX) type field parameter value by the AsWideMemo property?
Not especially. For VARCHAR(MAX) field parameter use AsMemo access. It is because you could be sending to your DBMS Unicode values to a non Unicode field. From the reference:
The Unicode encoded parameter value is converted to a Unicode
character set, which is supported by the DBMS, and sent to the DBMS.
This does not depend on a client character set or on a Delphi version.
If your field would be NVARCHAR(MAX), using AsWideMemo access to the parameter value would be the right choice.
Why am I getting “data too large for variable” error when having assigned a more than 8k chars long string by the AsString property?
Some background to why this happens. By accessing a certain parameter value by As<T> property, the engine also sets the parameter DataType, if you don't explicitly do that before. In this particular case you hinted the engine that it's fine for you if it sets the parameter data type to ftWideString or ftString just by accessing parameter value by the AsString property.
And thanks to data type mapping such parameter is treated as the VARCHAR[n] or NVARCHAR[n] data type including its limits (hence you got a string length limit error here).
Similar, just more specific data type hint is used when you access the parameter value by AsMemo property, it defaults to ftMemo data type which maps to VARCHAR(MAX). And as you may predict,
AsWideMemo access defaults to ftWideMemo which maps to NVARCHAR(MAX) data type. If you don't want to explicitly set the parameter data types but use this hinting, consult the manual to see how each used access property sets the default parameter data type.
So in my Source Table from Excel I have a Column called real/min/max that counts population and I want to split this into 3 columns called ActualPop, MinPop, MaxPop.
So an example would be
real/min/max
33/1/50
And I would need this to populate in the new Columns as
ActualPop
33
MinPop
1
MaxPop
50
I tried the following Expressions:
ActualPop: TOKEN([real/min/max],"/",1)
MinPop: TOKEN([real/min/max],"/",2)
MaxPop: TOKEN([real/min/max],"/",3)
The issue is when I try to do my mapping to the SQL destination, I get an error about the Data Types. The destination has INT data types mean while in the Derived Column Editor I see the Data Types are Unicode String. I have tried to use the Data Conversion but that still does not work.
You can change the data type of the 3 derived columns using the Advanced Editor on the Derived Column.
then.... select four-byte signed integer [DT_I4] for each of your INTs.
See: Changing Datatype in SSIS Derived column
I'm trying to run an INSERT query but it asks me to convert varchar to null. Here's the code:
INSERT Runtime.dbo.History (DateTime, TagName, vValue)
VALUES ('2015-09-10 09:00:00', 'ErrorComment', 'Error1')
Error message:
Error converting data type nvarchar to (null).
The problem is at the vValue column.
column vValue(nvarchar, null)
How it looks in the database:
The values inside vValue are placed by the program I'm using. I'm just trying to manually insert into the database.
Last post was with the wrong column, I apologize.
After contacting Wonderware support i found out that INSERT is not supported on the vValue column by design. It’s a string value and updates are supposed to carry out via the StringHistory table.
What is the type of the column value in the database ?
If it's float, you should insert a number, not string.
Cast "error1" to FLOAT is non-sense.
Float is a number exemple : 1.15, 12.00, 150.15
When you try to CAST "Error1" to float, he tries to transform the text "error1" to number and he can't, it's logic.
You should insert a number in the column.
I think I can help you with your problem since I've got a decent test environment to experiment with.
Runtime.dbo.History is not a table you can interact directly with, it is a View. In our case here the view is defined as:
select * from [INSQL].[Runtime].dbo.History
...Which I believe implies the History data you are viewing is from the Historian flat file storage itself, a Wonderware Proprietary system. You might see some success if you expand the SQL Server Management Studio's
Server Objects -> Linked Servers -> INSQL
...and play with the data there but I really wouldn't recommend it.
With that said, for what reason do you need to insert tag history? There might be other workarounds for the purpose you need.