Fetch multi output from SQL Transformation at Informatica - sql

I want to fetch query result from informatica SQL Transformation.
I get a sql query to an input port(QUERY) also want to fetch sysdate
SELECT (~QUERY~),SYSDATE FROM DUAL;
But it does not let me to fetch such a result as 2 output column.
When I write
~QUERY~
it is giving me result, but I need 2nd or 3rd column.
Thanks

Ok, first try putting sysdate into the query as one of the columns rather than encapsulating and selecting from dual
e.g. SELECT A.COLUMN, A.COLUMN2, SYSDATE, A.COLUMN3 FROM TABLENAME A WHERE CONDITION
Then if you want a multi row return you can use an inline lookup configured to return multiple rows (cant select from dual in a lookup). The one gotcha is that you must be on powercenter 9.1 or higher... otherwise you'll need to put that query in a source qualifier and use a joiner to bring it into the main pipeline. Why sysdate from the database rather than the native informatica SYSTIMESTAMP function?

My code was working with 9.5.1, have problem with 9.6.1
SELECT (~QUERY~),SYSDATE FROM DUAL;
You can put as statement to assign column to output port. Assume that outport port is RESULT and DATETIME
SELECT (~QUERY~) RESULT ,SYSDATE DATETIME FROM DUAL;

Related

Select from nothing in Oracle without referencing the dual table?

selecting from nothing in Oracle SQL happens while referencing the dual table, like
SELECT sysdate FROM dual;
Now I'd like to have a query that also works for PostgreSQL, but selecting from dual there isn't possible. I know that I can drop the whole FROM part, but then it won't work in Oracle.
I've also tried things like SELECT CURRENT_TIMESTAMP FROM VALUES(1)) V(C);, but Oracle can't do this, either.
So is there a way to select from nowhere without using the dual table in Oracle SQL?
Alternatively, create a table named dual in Postgres, made of 1 row and 1 column
create table dual as (select 1);
and you can use it in Postgres as you would in Oracle
select 'whatever' from dual;
?column?
-----------
whatever
sysdate in Oracle is a built-in function, i.e. not a database table column. You can use any table as long as the query returns precisely one row, e.g.
select sysdate from EMP where rownum < 2
If you have a small table, TABLE_B, with at least one row, you could try selecting a single row from it.
select sysdate from TABLE_B where rownum < 2;
The contents of the table don't matter because you won't be selecting any of its columns.
The below code generates a fake row in both Oracle and Postgres (10+), using the XMLTABLE function. This code is pretty weird but it doesn't require any custom objects.
--Generate a fake row in either Oracle or Postgres.
select *
from xmltable
(
--The expression syntax is different for Oracle and Postgres.
--Oracle can use a literal, Postgres must reference the XML.
--The string '' is null in Oracle but not null in Postgres.
case when '' is null then '1' else '/a' end passing '<a>1</a>'
columns test int path '.'
);
test
----
1

Firebird SQL: pass multi-row data in the query text

is it possible to use an array of elements as a select statement?
I know it is possiible to get rows based on static elements like this:
SELECT 405, CAST('4D6178' AS VARCHAR(32)), CAST('2017-01-01 00:00:00' AS TIMESTAMP) FROM rdb$databas
That will give you a table select with one row.
Now I would like to get this as table with n rows, but I don't know how to achieve this. Due to the fact that firebird doesn't allow multiple select statements I cannot only append n times a selec.
Info : Firebird 2.1
Use UNION ALL clause.
https://en.wikipedia.org/wiki/Set_operations_(SQL)#UNION_operator
Select x,y,z From RDB$DATABASE
UNION ALL
Select a,b,c From RDB$DATABASE
UNION ALL
Select k,l,m From RDB$DATABASE
Notice however that this should only be used for small data. Firebird query length is limited to 64KB and even if that would not be so - abusing this method to inject lots of data would not be good.
If you really need to enter lot of similar (same structure) data rows - use Global Temporary Tables
The following discussion hopefully would give you more insights:
https://stackoverflow.com/a/43997801/976391

decimal data type in Oracle

My database table contains one column of varchar2(20,10), but since it is a total amount field I need currency data type. (If I enter 1235.5 it should take it as 1235.50.)
I tried changing to type number(20,2), I am not able to do this with number(20,2) in Oracle 10g.
I guess you need not bother about insert, as long you have a precision of atleast 2. When you are fetching using select query, try using the select query as :
Select to_char(1234.4, 'fm9999999.00') from dual;
Select to_char(1234.45, 'fm9999999.00') from dual;
Select to_char(1234,'fm9999999.00') from dual;
Select to_char(1234.4567, 'fm9999999.00') from dual;

query oracle database for availability

Is there a lightweight sql statement that I can against an oracle database to test if the database is up, available and able to exceute sql?
SELECT 1
FROM dual
is a common one. You could select any constant value from DUAL as well.
If you don't want to connect first, you could query through a link, for example, I have a set of links to an external system and I run SQL of the following form:
select * from global_name#myLink01.WORLD;
If you write the sql statement to describe dual table, then also you will get to know it whether db is up and running.
desc dual;

SQL to return fixed data in both SQL Server and Oracle

I need a common select statement that returns a fixed value / row without the need of tables, which has to work with both Oracle & Sql Server.
eg for Oracle I know I can use:
select 'O' AS INDICATOR from DUAL;
But this won't work on Sql Server.
Can this be done with the same SQL on both Oracle & SQL Server?
AFAIK, you'll need different queries, unless you can find a table that exists both on the SQL Server and on the Oracle Server.
Oracle uses the DUAL table for dummy queries, while the syntax to just select a constant on SQL server is a bit simpler:
select 'O' as Indicator
will return a one-row recordset.
P.S. If you intend to write just standard SQL and have it work on both SQL Server and Oracle, note that there are lots and lots of differences, even if you do not use database-side code (stored procedures and functions).
Off the top of my head, some things that are different:
Case statement syntax
NVL vs IsNull
Null sorting behaviour
Data conversion functions
String manipulation functions
etc, etc.
You can't select data in Oracle without from statement. So you need to have a table in Oracle (common practice is to use standard table - Dual). The best solution if you really need to run same query on both database servers is to create Dual table with only one row in MS SQL. But really it's better to use different queries for different servers (maybe via some abstraction layer).
Use a common table expression (CTE) e.g.
WITH D (INDICATOR)
AS
(
SELECT *
FROM (
VALUES ('O')
) T (c1)
)
SELECT INDICATOR
FROM D;
Or more simply in line:
SELECT *
FROM (
VALUES ('O')
) D (INDICATOR)
You can create the DUAL table in SQL Server:
CREATE TABLE DUAL (DUMMY NVARCHAR(1) NOT NULL);
INSERT INTO DUAL VALUES ('X');
and then use the same query as in Oracle:
select 'O' AS INDICATOR from DUAL;