How do I use a parameter within BI Publisher to update the table name I am querying in an Oracle Data set - oracle

I am trying to create a BI Publisher data model which runs the Oracle query below -
SELECT *
FROM audit_YYYYMM
(this should be the YYYYMM of the current date)
How do I setup a parameter default value within the datamodel to grab the YYYYMM from the SYSDATE?
How do I append this parameter within the data set SQL Query?
I tried SELECT * FROM audit_:Month_YYYYMM
(where I had a string parameter called Month_YYYMM)
This did not work.

You are going to have to use something like EXECUTE_IMMEDIATE. And you may have to make a separate PL/SQL package to launch rather than use the built in data definition stuff.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm

Related

How to resolve Information - Not a valid month error?

When running a PowerCenter session that uses an Oracle database view as a source the session fails with one of the following errors:
ORA-01843: Not a valid month.
In SqL developer it runs without any issues
Column : Report_date : Data Type : date.
In mapping parameter variable defined as String
Passing report date dynamically using param file &Control table
Select * from ABC
Where report_date=to_char(31-MAR-21,'DD-MON-RR')
--Error: not valid month
Could you please advise on it
You need to put single quotes around infa mapping parameter. Like this -
First calculate Report_Date and put the value in infa param file in correct format. You can use control table too. But you need to create a param file from that.
param file should look like
[folder.workflow.session]
$$Report_Date='21-Oct-2021'
Then in mapping you can call it in source qualifier as -
Select * from ABC Where report_date=to_char('$$Report_Date','DD-MON-RR')
single quote will ensure your data is passed as string.
Now, if youdont want to use param file, you can use control file as a new source and join with the SQL above to get desired result. But first approach is faster.

Create parameterized view in Impala

My goal is to create a parameterized view in Impala so users can easily change values in a query. If I run below query, for example, in HUE, is possible to introduce a value.
SELECT * FROM customers WHERE customer_id = ${id}
But I would like to create a view as follows, that when you run it, it asks you for the value you want to search. But this way is not working:
CREATE VIEW test AS SELECT * FROM customers WHERE customer_id = ${id}
Someone know if it is possible?
Many thanks
When you creating a view, it takes the actual variable's value.
Two workarounds exist:
Create a real table where you will store/update the parameter.
CREATE VIEW test AS SELECT * FROM customers JOIN id_table ON customer_id = id_tableid
Pass a parameter into the view with the help of the user-defined function(UDF). Probably you will need two UDFs set and get. Set UDF will write UDF on HDFS and Get UDF will read the variable from HDFS.
Two above mentioned workarounds work but not ideal. My suggestion is to use Hive for parametrized view creation. You can create a GenericUDF via which you can access hive configuration and read the variable and perform filtration. You can't use it for Impala.
SELECT Generic_UDF(array(customer_id)) FROM customers
GenericUDFs has method configure you can use it to read the hive variable:
public void configure(MapredContext mapredContext) {
String name = mapredContext.getJobConf().get("name");
}
You could do the opposite, e.g. parameterize the query on the view instead

Unable to pass parameters with periods in Oracle APEX / REST

Using Oracle APEX 5.0.4, with Oracle 12c. I am trying to write a REST service in Oracle APEX. I have a SQL statement...
select * from <my_table> where company_name = 'GOOGLE INC.'
When run from a straight SQL prompt, this runs and returns data. I have tried to implement this in a REST service, specifically using a URI template. I am using a bind variable, so my query now looks like.
select * from <my_table> where company_name = :ACCT_NAME;
Both the space and the period in my company name are causing me problems, returning no rows. If my BIND VARIABLE is a single word, then no problems. I found UTL_URL.UNESCAPE, and have tried to use that. This seems to solve the problem of having a space, but does not fix issue when the company name contains a period.
I rewrote my SQL Statement to
select * from <my_table> where company_name = UTL_URL.UNESCAPE(:ACCT_NAME);
The query will work if the BIND VARIABLE (aka company name) is multiple words, but NOT containing a period. For example, I can look up 'GOOGLE INC' by setting my bind variable = 'GOOGLE%20INC' . I need to be able to look up 'GOOGLE INC.' [notice the period at the end of INC] so I set my bind variable = 'GOOGLE%20INC%2E' and I consistently get 'BAD REQUEST'. It appears that the URI template is not valid.
If I pass this in via a straight SQL statement (aka OUTSIDE of the REST service), my data is found...
select * from <my_table> where company_name = UTL_URL.UNESCAPE('GOOGLE%20INC%2E');
There is something unique about the PERIOD character... Any ideas?

Provide dynamic value to sql file from sql-maven-plugin

I have set of oracle database view creation script files, which needs schema name as dynamic parameter while getting executed bt maven-sql-plugin. How do I pass this parameter using "sql-maven-plugin".
This is an example :
CREATE OR REPLACE VIEW MY_VIEW AS SELECT * FROM FROM &SCHEMA_NAME.MY_TABLE.
Here I want to pass &SCHEMA_NAME from sql-plugin, is it possible to do?

Oracle generated column aliases different on two DB's

We have a legacy application we cannot modify that connects to Oracle 11g and at some point runs a query and returns a result. The application however is using the "generated" column name from Oracle to read the result.
Consider the following query:
select nvl(1,0.0) from DUAL;
As this query does not specify an alias, the generated column name would be "nvl(1,0.0)"
However on another server the generated column name is "nvl(1,0)" (notice 0 and not 0.0) and the application fails.
Is there a configuration that can be changed for Oracle? I've searched for formatting and locale configurations and they are equal on both servers.
Any help would be appreciated
It turns out there's a parameter called cursor_sharing that was set to FORCE instead of EXACT
select nvl(1,0.0) from DUAL;
The query above returns the following depending on the value of the parameter:
FORCE=NVL(1,0)
EXACT=NVL(1,0.0)

Resources