Oracle SQL: Extracting rows data into multiple columns using SQL - oracle

I have one scenario where data are in table as follows:
Ser_num File_name
1 DBA OBJECT~ALL_OBJECT
2 ./outfile_26094843.txt
3 ./outfile_26094844.txt
4 ./DataFile.txt
5 DBA OBJECT~AP_INVOICES_ALL
6 ./XXFA_GL_ICOMP_JOURNAL.rdf
7 ./outfile_26094844.txt
I have to extract data as follow
ALL_OBJECT
outfile_26094843.txt
outfile_26094844.txt
DataFile.txt
AP_INVOICES_ALL
XXFA_GL_ICOMP_JOURNAL.rdf
outfile_26094844.txt
please advise me SQL for this.

Related

Cross lookup in oracle without creating a table

I have a list of 20 records mapping year to a number from 2001 to 2021. For a couple of reasons these can not be loaded into a table, and I do not have permissions to create temporary tables. This lookup means I can't just run a single query in oracle - I have to export and join with a script. Is there a way I could just do a lookup in memory? I could do a CASE WHEN statement to handle each of the 20 cases. But is there some other smoother way to check values against a list in Oracle when you can't write to a table in between?
If I understood you correctly, a CTE might help:
SQL> with years as
2 (select 2000 + level as year
3 from dual
4 connect by level <= 21
5 )
6 select year
7 from years
8 /
YEAR
----------
2001
2002
2003
2004
<snip>
2020
2021
21 rows selected.
SQL>
You'd now join years with other tables, e.g.
with years as
...
select y.year, e.hiredate
from years y join employees e on e.year = y.year
where ...

Rows not copied to destination table from source table using oracle sqlplus copy command

I am using this copy command.
COPY FROM username/[pwd]#identifier INSERT SCHEMA_NAME.TABLE_NAME
USING SELECT * FROM SCHEMA_NAME.TABLE_NAME;
Note : Both the source and target tables are in different databases. The source table has around 19 million records. Both tables have 198 columns.
and I am getting the below message when the copy command is executed (I am not seeing any error message but no rows are copied).
Array fetch/bind size is 5000. (arraysize is 5000)
Will commit after every 100 array binds. (copycommit is 100)
Maximum long size is 80. (long is 80)
0 rows selected from username/[pwd]#identifier.
0 rows inserted into SCHEMA_NAME.TABLE_NAME.
0 rows committed into SCHEMA_NAME.TABLE_NAME at DEFAULT HOST connection.
Please help me on this or any possible guidance to tackle above issue is deeply appreciated.
I tried it on my local 11g XE database; it works OK.
SQL> create table test as select * From dept where 1 = 2;
Table created.
SQL> copy from scott/tiger#xe insert test using select * from dept;
Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
4 rows selected from scott#xe.
4 rows inserted into TEST.
4 rows committed into TEST at DEFAULT HOST connection.
SQL> select * From test;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
Your query selected nothing and inserted nothing, which looks as if query doesn't do what you thought it would. Did you make sure that it is correctly written and that it fetches some rows?
As of disadvantages: Oracle 19c documentation says that
The COPY command will be deprecated in future releases of SQL*Plus. After Oracle 9i, no new datatypes are supported by COPY.
so you'd probably rather use other options to move data around. That would be e.g.
INSERT INTO
MERGE
data pump export & import

Oracle Applications - How to get the value of zd_edition_name

In Oracle Applications 12c release 1 there is a new column that forms part of many primary keys called zd_edition_name. This relates to editions that you can have for keeping the database up during changes. So you would have two editions, you can make changes to the non-live on and then just live swap over when you are done (my limited understanding - I am not a dba).
My questions is how can I get the value of zd_edition_name, since this is now part of the primary key and also because tables like fnd_descr_flex_col_usage_tl would bring back two rows instead of one if you don't pass the value of zd_edition_name.
Also what does the zd stand for?
EBS and Edition Base Redefinition and Online Patching
The column, zd_edition_name, is just a component of the edition based redefinition feature of an Oracle 11G 2 (or greater) database as you have indicated.
Oracle Applications does not leverage this edition based redefinition database feature until 12.2 EBS.
The apps owned synonym will display the run time value, SET1 or SET2. It will be one value. For EBS 12.1, I would expect the run time value to be SET1.
APPS#db> select
2 zd_edition_name
3 from
4 fnd_descr_flex_col_usage_tl
5 group by zd_edition_name;
ZD_EDITION_NAME
SET1
With the editionable view and the table, we do not have that restriction:
APPS#db>SELECT
2 zd_edition_name
3 FROM
4 applsys.fnd_descr_flex_col_usage_tl
5 GROUP BY
6 zd_edition_name;
ZD_EDITION_NAME
SET2
SET1
In EBS 12.2, one could identify the active file system which should have a correspondence with SET1/SET2 through logging in to the Oracle Apps server(s) and echoing the environment variables:
$FILE_EDITION = patch
$RUN_BASE = /u01/R122_EBS/fs1
$PATCH_BASE = /u01/R122_EBS/fs2
By querying the apps owned synonym, this is unnecessary to know the value of ZD_EDITION_NAME (it is a value associated with the run edition which will be the value).
You can view the editionable objects associated with table with a query like this:
APPS#db>VAR b_object_name varchar2(30);
APPS#db>EXEC :b_object_name:= 'FND_DESCR_FLEX_COL_USAGE_TL';
PL/SQL procedure successfully completed.
APPS#db>SELECT
2 ao.owner,
3 ao.object_name,
4 ao.object_type
5 FROM
6 all_objects ao
7 WHERE
8 1 = 1
9 AND owner IN (
10 'APPS',
11 'APPLSYS'
12 )
13 AND ao.object_name IN (
14 :b_object_name,
15 substr(:b_object_name,1,29)
16 || '#'
17 );
OWNER OBJECT_NAME OBJECT_TYPE
APPLSYS FND_DESCR_FLEX_COL_USAGE_TL TABLE
APPLSYS FND_DESCR_FLEX_COL_USAGE_TL# VIEW
APPS FND_DESCR_FLEX_COL_USAGE_TL SYNONYM
Here are list of versions existing in an EBS instance:
APPS#db>SELECT
2 level,
3 de.edition_name,
4 de.parent_edition_name
5 FROM
6 dba_editions de
7 START WITH
8 de.edition_name = 'ORA$BASE'
9 CONNECT BY
10 PRIOR de.edition_name = de.parent_edition_name
11 ORDER BY
12 de.edition_name;
LEVEL EDITION_NAME PARENT_EDITION_NAME
1 ORA$BASE
2 V_20160703_2120 ORA$BASE
3 V_20160708_1723 V_20160703_2120
...
29 V_20180117_1118 V_20171206_1115
30 V_20180130_0107 V_20180117_1118
For an 12.1 EBS environment, I would expect the starting edition, ORA$BASE, to be the only edition.

How to combine 2 columns from 2 database sources in Informatica Powercenter (9.1)

I am using Informatica PowerCenter 9.1 and am trying to combine 2 columns from 2 sources. Basically trying to create a report that will show all users and the roles they have on 2 separate databases. They could be in one database and not the other so I have to account for that as well.
So if I had this output:
DATABASE 1 (Oracle)
User 1 = Role A
User 2 = Role B
DATABASE 2 (Sybase)
User 1 = Role C
User 3 = Role D
I want the output to look like this:
User 1 = Role A --- Role C
User 2 = Role B --- N/A
User 3 = N/A --- Role D
Any help in figuring this out would be greatly appreciated.
You can us joiner transformation to link them together and then use expression to concat.
Read from database using 2 separate source qualifier transformation and join them using joiner.
Join condition would be user_id. Join type should be full outer join. Full join will pick up all data (matching and not-matching) in either table.
Then pickup user_id, role1(Oracle) and role 2 (Sybase) and concat them with IFNULL logic like this -
IIF (ISNULL(role1), 'N/A', role1)||IIF (ISNULL(role2), 'N/A', role2)
To concatenate two columns from two different tables into a single column at target will not work in Informatica. You can combine only columns in a single table. But there is a work around and it is using "Post SQL" query and here you can write a database JOIN query.

How can I get several oracle rows into one?

In this oracle situation, how can I get the following results in a single query?
Table 1
Customer | Order_Number
1 1
1 2
2 1
Table 2
Customer | Order_Number | Employee | Tag
1 1 Bob on hold
1 1 Larry shipped
1 2 Larry shipped
Results
Customer | Order_Number | Tags
1 1 Bob - on hold; Larry - shipped
1 2 Larry - shipped;
2 1 (Empty or null)
I'm getting tripped up on returning the tags as a single string.
You have not mentioned your DB version. So the answer would completely depend on which version are you on.
If you are on 11g and up, use LISTAGG.
However, if you are on pre 11g release, then you have the following options :
ROW_NUMBER() and SYS_CONNECT_BY_PATH functions in Oracle 9i
COLLECT function in Oracle 10g
STRAGG function suggested by Tom Kyte here http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:2196162600402
Note : Never use WM_CONCAT in production system, it is undocumented. Just raise a SR to Oracle support and say you used it, and see the response. And it doesn't exist in 12c.
More examples here http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php
You're in need of LISTAGG.
If your Oracle version is old enough, it can be replaced with user-defined aggregate function, WM_CONCAT or SYS_CONNECT_BY_PATH.

Resources