SSIS sending query with data parameter to Oracle cloud VS-2019 and MS Oracle Source - oracle

Already checked this post: SSIS and sending query with date to Oracle
And I'm using variable query per below thread
SSIS - Using parameters in Oracle Query using Attunity Oracle Datasource
Tool used: VS-2019
Data flow: MS Oracle Source (for VS-2019)
My source is Snowflake cloud. I'm successfully able to get the max date from table and store in Object type variable (named:- #var_Snowflake_Table_maxDate). Then I use a script task to convert the value to string type.
Code for script task is:
public void Main()
{
OleDbDataAdapter A = new OleDbDataAdapter(); //using System.Data.OleDb; ADDED above in NAMESPACES
System.Data.DataTable dt = new System.Data.DataTable();
A.Fill(dt, Dts.Variables["User::var_Snowflake_Table_maxDate"].Value);
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
Dts.Variables["User::var_CreateDate"].Value = array[0].ToString();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
This sets my param of #var_CreateDate String type correctly. I tried this on local machine and was able to pass the value to a native instance of sql-server(yes NOT oracle). Just to test my parameters from script task works.
Finally: I'm using VS-2019's MS Oracle Source to pass the value into Oracle cloud server. Sample query's I have tried
"select * from Table where rownum <= 5 and NVL(CREATE_DATE,UPDATE_DATE) = " +"'05-09-2020'"
::::evals to::::
select * from relate.awd_acct_activity where rownum <= 5 and NVL(CREATE_DATE,UPDATE_DATE) = '2020-05-09'
and this works. But value is hard coded.
Try 2:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = " +"'#[User::var_CreateDate]'"
Try 3:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" +"'#[User::var_CreateDate]'"+")"
Try 4:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" +"'#[User::var_CreateDate]'"+",'YYYY-MM-DD')"
None of try 2 through 4 eval correctly. Can I have some guidance into how to pass this parameter to Oracle cloud.
Thanks.

I'm assuming you're trying to figure out the syntax for a variable, that would hold the query text. You can try something like this:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" + "'" + #[User::var_CreateDate] + "'" + ",'YYYY-MM-DD')"

Related

How to use prepare_statement with OCI Python SDK and NoSQL cloud service?

I am planning to use Oracle NoSQL Cloud Service on OCI using the OCI Python SDK. I did some tests using the API calls and I would like to do the same query but using the Python SDK.
How can I use prepared statement instead of regular statement (see below) and what values I need to set
print("second attempt")
table_name = 'table1'
statement = 'declare $id integer; select * from ' + table_name + ' where id=$id'
id_value = '1'
#nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement),
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$id': id_value}))# Get the data from response
print(query_response.data)
Currently I have the following error :
oci.exceptions.ServiceError:
{'opc-request-id': '94E0B7EA0C864B379D66ED1C5215652A',
'code': 'InvalidParameter',
'message': 'QUERY: Illegal Argument: Deserialize prep query failed: Hash provided for prepared query does not match payload', 'status': 400}
the problem is with the "statement" attribute of QueryDetails.
use the result of the nosqlClient.prepare_statement (take care with the comma at the end in your script)
call oci.nosql.models.QueryDetails with the following parameters statement=prepare_statement_response.data.statement, is_prepared=True and variables
table_name = 'table1'
statement = 'declare $Id long; select * from ' + table_name + ' where id = $Id'
id_value = 1
prepare_statement_response = nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement)
print(prepare_statement_response.data.statement)
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=prepare_statement_response.data.statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$Id': id_value}))
print(query_response.data)
Hope that this can help you

hive jdbc on java get count(*) of table rows

i am trying to get rows count of my table in my java project using jdbc connection to Hive database.
My code:
Statement s = con.createStatement();
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM TABLE_NAME");
r.next();
int count = r.getInt("rowcount") ;
r.close() ;
System.out.println("MyTable has " + count + " row(s).");
When i start this function, my project freeze and nothing happens. I tried to debug, the result was: when program reach this place
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM TABLE_NAME");
nothing happens and debuger shut down.
select * from TABLE_NAME
works fine, but counting rows from the same table doesnt work. Any ideas? :)

Query results in Oracle SQL Developer are different to those using .Net ODP

I have this query:
SELECT
case
when
AddressType IN (select code.codeid from code where code.codeset = AddressTypeCodeSet and code.description like 'Postal%')
then 'PostalAddress'
when
AddressType IN (select code.codeid from code where code.codeset = AddressTypeCodeSet and code.description like 'Email%')
then
'EmailAddress'
else
'OtherAddress'
end as AddressType
FROM VW_Address
WHERE AddressId=190000;
When I execute this query using SQL Developer, the result returned is OtherAddress. This is what I'm expecting. However, when I execute the same query via this code:
Dim cmd =
New Oracle.DataAccess.Client.OracleCommand(["SQL HERE]")
cmd.Parameters.Add(":p0", OracleDbType.Int32)
cmd.Parameters(0).Value = 190000
cmd.BindByName = True
Dim r = cmd.ExecuteReader()
I get a different result: EmailAddress
ODP is version 2.111.7.20, Oracle is 11g.

Update Datetime Values in all the Tables in the database

How can I update all the tables which have Datetime fields in a database?
Eg. My DB has 50 Tables which has a column in the 50 tables which is of DATETIME Type.
I need to update the Column of datetime type with a new value.
How can I write a generic query to update datetime column in all the tables in the DB with a new value of datetime?
While I question the value of this in an unprecedented way (you should be proud!), you can't write a generic query that does this without dynamic SQL.
DECLARE
#sql NVARCHAR(MAX) = N'',
#newDateTime DATETIME = '20131217 07:30';
SELECT #sql += N'
UPDATE ' + QUOTENAME(s.name) + '.' + QUOTENAME(t.name)
+ ' SET ' + QUOTENAME(c.name) + ' = #newDateTime;'
FROM sys.columns AS c
INNER JOIN sys.tables AS t ON c.[object_id] = t.[object_id]
INNER JOIN sys.schemas AS s ON t.[schema_id] = s.[schema_id]
WHERE c.system_type_id = 61;
EXEC sp_executesql #sql, N'#newDateTime DATETIME', #newDateTime;

row number with help of linq

my table consists of 3 columns(sno,name,age) now i am retrieving this table from the database with extra column(row number) ,i used the following code
select * from (
select ROW_NUMBER() over (order by SNo asc)as rowindex,SNo,Name,Age
from tblExample)
as example where rowindex between ((pageindex*10)+1) and ((pageindex+1)*10)
note:here pageindex is the varaible that takes some intger value which is passed by the user
my data base is sql server 2008, now i want to write the same query using linq
can any one please change the abovesql query into linq. iam unable to do it as iam new to linq. iam struck up with this problem please help me thank you in advance
You can write query as beow
var index=1;
var pageIndex=1;
var pageSize = 10;
data.Select(x => new
{
RowIndex = index++,
Sno = x.Sno,
Name = x.Name,
Age = x.Age
}).OrderBy(x => x.Name)
.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();

Resources