Temporary Table in Bi Publisher - oracle

I need to run a a script for the temporary table before running the report in the BI Publisher.
I would like to know the step by step procedure on how to create and populate a TEMPORARY TABLE in the Bi Publisher. I tried to search but there's no clear steps on how to do it. Please give a simple example.
Thanks in advance!

You can create table temporary
--Create table
create global temporary table XX_TEST_TMP
(
ID NUMBER,
CUSTOMER_NAME VARCHAR2(150)
)
on commit preserve rows;
--Create package with function execute insert data to table
create package xxx_test_pkg as
function insert_table_tmp.....
...
insert into XX_TEST_TMP values(....);
commit
end;
In the data source XMLP then add more to execute insert data to table temp.
<dataTrigger name="beforeReport" source="xxx_test_pkg.insert_table_tmp" />
After that select data on the table XX_TEST_TMP to show on your report.

Related

How to create Oracle event trigger that will log table creations

I am trying to write a trigger that fires after user creates a new table, and logs the creation of table into an audit table.
I have the below starter code:
CREATE OR REPLACE TRIGGER create_table_trigger
AFTER CREATE
ON SCHEMA
BEGIN
INSERT INTO TABS_MODS (ID,ACTION) VALUES (1, 'CREATE TAB');
END;
TABS_MODS is a global temporary table like below:
CREATE GLOBAL TEMPORARY TABLE TABS_MODS (
id NUMBER,
action VARCHAR2(20)
) ON COMMIT PRESERVE ROWS;
But on creating table I am not seeing anything in the TABS_MODS table.
Use Oracle's built-in auditing features to do this. Audit the "CREATE TABLE" and "CREATE ANY TABLE" privileges. You didn't specify which version of Oracle you're using, but you can start here and search for more version-specific examples if you need them: https://docs.oracle.com/database/121/DBSEG/auditing.htm

Add partition to hive table with no data

I am trying to create a hive table which has the same columns as another table (partitioned). I use the following query for the same
CREATE TABLE destTable STORED AS PARQUET AS select * from srcTable where 1=2;
Apparently I cannot use 'PARTITIONED BY(col_name)' because destTable must not be partitioned. But I want to mention that destTable should be partitioned by a column (same as srcTable) before I add data to it.
Is there a way to do that?
As you mentioned, destTable can not be a partitioned table so there is no way to do this directly. Also, destTable can not be an external table.
In this situation you will need to create a temporary "staging_table" (un-partitioned and a Hive-managed table) to hold the data.
Step 1: Transfer everything from srcTable to the staging_table
Step 2: Create a partitioned destTable and do:
INSERT OVERWRITE TABLE destTable PARTITION(xxxx)
SELECT * FROM staging_table;
Hope this helps.

Is there a way to log table creation and column modification in a table with the one who execute it, in oracle schema?

I am searching for a way, to store only the tables and columns that are added in the database with the one who created it (nachine_name) in a log table.
I tried to add a trigger on sys table user_tab_cols but I cannot do that Why cannot I create triggers on objects owned by SYS?
The system table user_objects will give me the date when a table created, but I want also to know which machine created it. and I also want to track the column creation and modification and log them in a table.
Is that possible ? is there a way for that ?
you can create a database event trigger:
CREATE OR REPLACE TRIGGER log_ddl_event_trg
AFTER DDL
ON DATABASE
DECLARE
v_sql_list ora_name_list_t;
v_sql_txt VARCHAR2(2500);
BEGIN
FOR i in 1..ORA_SQL_TXT(v_sql_list) LOOP
v_sql_txt := v_sql_txt || v_sql_list(i);
EXIT WHEN length(v_sql_txt ) >= 2000;
END LOOP;
...
END;
/
in the Trigger, you can get the executed ddl-statement using the ORA_SQL_TXT() Funktion, and then log it in the table together with the other data (log_date, user etc.).

ORACLE PL/SQL - SCHEDULE CREATE TABLE

I need to create a table every morning based on overnight generated data from a massive table. This will then be accessed by a handful of users form Excel.
My initial approach was to use a materilazed view and when this was rejected (for political reasons) to used Managed XLL but this was rejected for other reasons. I don't want to get messed up with Temporary tables and so really just need to know how to schedule an Oracle Create Table statement as our DBA says it can't be done.
My faith in SO users sasy otherwise though!
I don't see why you have to create a new table every morning and not use an existing one?
This creates your table from PL/SQL. Is this what you want?
CREATE OR REPLACE PROCEDURE make_table AS
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE your_table ( column_1 INT PRIMARY KEY, column_2 VARCHAR2(10) )';
END make_table;
/
EXEC make_table;
Your user needs to have the necessary grants, grants given by role don't apply to compiled PL/SQL code.

Stored Procedure for copying data from one table to another

I have pairs of tables in the format TABLE and TABLE_TWIN now
TABLE is the main table with lots of data
TABLE_TWIN is a table with the exact same fields with a little data (different data)
Now I would like to copy all rows from TABLE_TWIN to TABLE using a stored procedure. I have many such tables and could like the stored procedure to take the table name(s) as parameter(s) so that I can use the same procedure for each table pair. I do not want to write long INSERT statements because these tables have around 50 attributes each.
I am not good with PL/SQL so I need some help here.
Thanks!
SQL is not so long... But if you prefer a procedure, here it is:
create or replace procedure table_copy(
p_tab_from varchar2,
p_tab_to varchar2)
is
begin
execute immediate 'insert into '||p_tab_to||' (select * from '||p_tab_from||')';
end;
insert into table_twin (select * from table)
should do it

Resources