SQL temp table creation with parameter in FastReport VCL 5 - sql

since several request in my report use the same subquery, I wrote a DBXQuery named qCreateTemp that prepares a temporary table:
CREATE TEMP TABLE temp AS SELECT * FROM acomplexrequest WHERE afield = :avalue
I defined avalue as an (integer) parameter of the request with value.
First I linked it to a dummy MasterData band, but FastReports complains the request doesn't return a Cursor.
So I tried to call it explicitly from the script code, first simply as:
qCreateTemp.ExecSQL;
Then noticing the request's parameter was not passed, I tried:
qCreateTemp.Params.ParamByName('avalue').Value := <avariable>;
qCreateTemp.ExecSQL;
but I get an error "Could not convert a variant of type (Null) into type (Integer)"
What's the best/correct way to do this ? Thanks !

Related

SQL Error 'ORA-00904' When Retrieving Data From an XML File Via XMLQuery

I've been trying for days now to retrieve data from an XML file with a SELECT statement in SQL Developer but I constantly get the 'ORA-00904' when trying to execute the statement. So far, these are the steps I've been following:
Create the table and directory where I want the XML data to be stored in:
CREATE TABLE PLAYER OF XMLTYPE; / CREATE DIRECTORY PLDIR AS 'C:\Users\marta\OneDrive\Escritorio\UOC\Sem3\ABD\PR2'; /
Insert into my PLAYER table said data:
INSERT INTO PLAYER VALUES (XMLTYPE(bfilename('PLDIR', 'InfoPlayersWPT.xml'),nls_charset_id('AL32UTF8')))
/
So far so good. The issue appears when I try to execute the SELECT statement
What could it be? I've changed the $Name parameter a million times as well as the Name field but nothing changes. The thing is that in the XML file, these are the fields:
--Update--
I've modified a little bit the structure and this is the new error I get:
enter image description here
I've reached a point where I don't get if there could be a problem with my database connection or if the variable are incorrect.
Any form of help would be much appreciated.
Your table doesn't have a name or id column. Your query is trying to get those, while also transforming the XML to an info node making the id a node rather than an attribute, but you still don't extract the values from that new XML. You don't need to though.
If the document only has one player (which seems unlikely with the outer node 'Players') then you can get the data with an XMLQuery call for each value:
select XMLQuery('/Players/Player/#id' passing p.object_value returning content) as id,
XMLQuery('/Players/Player/Name/text()' passing p.object_value returning content) as name
from player p
ID
NAME
1
Francinsco Navarro Compán
But it's a bit simpler, particularly if you add more data items, to use a single XMLTable instead:
select x.id, x.name
from player p
cross apply XMLTable(
'/Players/Player'
passing p.object_value
columns id number path '#id',
name varchar2(30) path 'Name'
) x
ID
NAME
1
Francinsco Navarro Compán
fiddle
... which would also handle multiple players in each XML document.

how to update in-memory table dynamically using dolphindb database

Is there any way to update an in-memory table dynamically using dolphindb? I need more suggestions to write a dynamic update function. Now I can only get the table name returned. I tried several methods to update the data for a specified table but failed.
Script 1:
table1=table(1..6 as id,2..7 as v, 3..8 as v1, 4..9 as v2, 5..10 as v3 );
share table1 as t1;
tableName ="t1";
update!(tableName, `v, 666);
Error report:
Read only object or object without ownership can't be applied to mutable function update!
Script 2:
updateSql = "update t1 set v = 999;";
parseExpr(updateSql).eval;
Error report:
Invalid expression: update t1 set v=999;
What's the correct syntax to update a specified table?
Use DolphinDB's function update! to update the columns in an existing table:
update!(table, colNames, newValues, [filter])
Here table is a DolphinDB table. The error occurs because your script defines the table type to be of STRING type. Use objByName to change it:
update!(objByName(tableName), `v, 666);
If you want to know more about dynamical expression generation, meta programming will be of help.

Oracle SQL: create a dumy table from a substitution variable

In Oracle SQL, I can create a dummy table thanks to the code shown below:
select crca.*
from my_real_table real_table,
table(ntde.ENCRYPT_ALL(:inputParam)) enc
where
...
I would like to be able to do same thing without using ntde.ENCRYPT_ALL, I would like to do something like that:
select crca.*
from my_real_table real_table,
table(:inputParam) enc
where
...
It does not work and I get this error:
00000 - "cannot access rows from a non-nested table item"
*Cause: attempt to access rows of an item whose type is not known at
parse time or that is not of a nested table type
*Action: use CAST to cast the item to a nested table type
Do you know how to do that please?
As the exception says, use CAST:
SELECT c.*
FROM my_real_table r
CROSS JOIN TABLE( CAST(:inputParam AS your_collection_type) ) c
This assumes that:
the bind variable contains an collection (and not a string); and
the bind variable is being passed from an application (this is a Java example); and
you have created an SQL collection type to cast the bind variable to. For example:
CREATE TYPE your_collection_type AS TABLE OF NUMBER;
Or, instead of creating your own collection type, you could use a built in collection (or VARRAY) such as SYS.ODCIVARCHAR2LIST.

passing an array into oracle sql and using the array

I am running into the following problem, I am passing an array of string into Oracle SQL, and I would like to retrieve all the data where its id is in the list ...
here's what i've tried ...
OPEN O_default_values FOR
SELECT ID AS "Header",
VALUE AS "DisplayValue",
VALUE_DESC AS "DisplayText"
FROM TBL_VALUES
WHERE ID IN I_id;
I_id is an array described as follows - TYPE gl_id IS TABLE OF VARCHAR2(15) INDEX BY PLS_INTEGER;
I've been getting the "expression is of wrong type" error.
The I_id array can sometimes be as large as 600 records.
My question is, is there a way to do what i just describe, or do i need to create some sort of cursor and loop through the array?
What has been tried - creating the SQL string dynamically and then con-cat the values to the end of the SQL string and then execute it. This will work for small amount of data and the size of the string is static, which will caused some other errors (like index out of range).
have a look at this link: http://asktom.oracle.com/pls/asktom/f?p=100:11:620533477655526::::P11_QUESTION_ID:139812348065
effectively what you want is a variable in-list with bind variables.
do note this:
"the" is deprecated. no need for it
today.
TABLE is it's replacement
select * from TABLE( function );
since you already have the type, all you need to do is something similar to below:
OPEN O_default_values FOR
SELECT ID AS "Header",
VALUE AS "DisplayValue",
VALUE_DESC AS "DisplayText"
FROM TBL_VALUES
WHERE ID IN (select column_value form table(I_id));

How to send record(which is a weblink) from a table to the value of the variable in SSIS package and send that weblink through an email?

I have table called Table1 with columns, col1 and col2 with col1 having weblinks for the report and col2 the name of the report. Now, i have a package with a variables var1 and var2 which should get the col1 and col2 values respectively from table1 and send it through an email. if the weblink gets updated in the table, package should send the updated link. i know the reverse way of it but trying to do somethig like this.
Appreciate any help from you guys.
Thanks
There are a few ways you can do this. You can try one of the following based on whether you are processing one row or many rows.
One-Row Solution
If you are running the SSIS package so that it will process one and only one row from the table, you can use the Execute SQL Task to get the values from your table. Begin by adding your two variables
In the task, specify the connection to your SQL Server and enter a SQL statement like this.
SELECT col1, col2
FROM Table1
WHERE <your condition to retrieve one row>
Also, on the General tab, set the ResultSet value to Single row.
On the Result Set tab, add two elements. The first row should be Result Name of 0, Variable Name of Var1. The second row will be Result Name 1, Variable Name Var2.
When the task runs, the results of the SQL statement will be stored to the variables.
Multi-Row Solution
If the SSIS package must return multiple rows, then you need a different approach. First, you will need to create another variable that is an Object data type. The SQL results will be saved to this variable.
You will have an Execute SQL Task that is similar to the one above. However, your SQL statement should return all rows to be processed. The ResultSet property should be set to Full result set. On the Result Set tab, there should be one result set, with 0 as Result Name and your new object variable as the Variable Name. Close the Execute SQL Task editor.
Add a Foreach Loop Container. Edit the container and select the Collection tab. Set the Enumerator property to Foreach ADO Enumerator. Under the Enumerator configuration, set your object variable as the ADO object source variable.
On the Variable Mappings tab, add to rows. The first row will have a Variable Var1 and Index 0, and the second row will have Variable Var2 and Index 1. The Foreach Loop Container will process each for in the result set and assign the column values to your variable. You can add any tasks in the container and they will run once for each row in the result set.