'create columns with a where clause' in MDB
Hi allI have a question on the OBI EE meta data layer.
We have OBIEE sitting on a with a star schema data warehouse.
Our fact table contains the following fields...
EmployeeID
CompanyID
ID of the measure
The measure name
MEASURE
That's what we have in the physical layer, layer MDB and the presentation layer, but I want to be able to "create columns with a where clause.
So my table of facts in the presentation layer would look like this
Quantity sold
Unit cost
Amount of the company
I thought I could just create a logical with column
Quantity = measurement
where as name = "quantity".
But I can't find any to do so.
Any ideas?
Thank you
Hello
I think that what you want to achieve must be done in the physical layer and not the business layer.
Instead of using your physical table directly from the DB, you must create a physical table based on an SQL statement.
GO to the physical layer you / create the new object table in Table type choose "Select" and then you write your select statement as you want.
Once this is done to create your physical joins and import your table into your business layer and create your complex joins
This should do the trick.
It may be useful
Concerning
Tags: Business Intelligence
Similar Questions
-
How to create a procedure for REF CURSOR output with any WHERE clause?
I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.
I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.
i.e.
The foregoing gives an error.PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS BEGIN OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause; END;
How to handle such a situation? Any help would be greatly appreciated.Hello
Channa wrote:
... However, when I change the procedure like this:PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y'; OPEN p_out_cursor FOR v_stmt using p_where_cluase; END;
And run this block of code:
declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
I get the error:
[1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?
A bind variable, such as: it, represents a single value.
If: is the VARCHAR2 '1 = 1', thenSELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
takes the value
SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
I think you want something like this:
CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST ( p_where_clause IN VARCHAR2 , p_out_cursor OUT SYS_REFCURSOR ) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND ' || p_where_clause; OPEN p_out_cursor FOR v_stmt; END; / show errors SET SERVEROUTPUT ON declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
Output:
ALLEN WARD MARTIN BLAKE CLARK ADAMS JAMES
-
Need help with dynamic where clause.
Hello world. I'm kind of a novice with PL/SQL, so please be patient with me. I am building a web application using Weblogic Oracle 11 g and Oracle database.
To make a long story short, I need to generate the complex dynamic WHERE clause. I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.
I'm not 100% certain, but I think I need to use dynamic SQL statements. Unless there is a better way to do it.
I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation. I would like to use bind variable if possible.
In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...
bv1 := 'colA = 5 and colB >= 9'; query_str := 'SELECT * FROM view WHERE :bv1'; OPEN CUR FOR query_str USING bv1;
The code above pours out when I try to run it.
Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?
Thank you
Hello. I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.
Can you give us an explanation or an example of how to use it to accomplish what I need to do?
Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?
Variable bind offer performance when the same query is executed several times with different values for bind variables.
Select * from emp where empno =: v_empno
After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.
Select * from emp where empno =: v_empno;
Select * from emp where ename =: v_ename;
Select * from emp where sal =: v_sal;
Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.
So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.
The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.
So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.
Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal
-
XMLTable with a WHERE clause?
I have a table that looks like this race under Oracle 11.2.0.3.4:
.. and I'm trying to run a query like this:CREATE TABLE book_master OF XMLTYPE XMLTYPE COLUMN STORE AS SECUREFILE BINARY XML;
He played really bad, and then I realized that he returned each row in the table for each iteration of the query. Is XMLExists the only way possible to return a single line, assuming that ISBN_NBR and PROD_ID are unique? Can the clause WHERE cannot be used as a discriminator at all?SELECT e.title, e.isbn_nbr, e.prod_id, e.ctry_code, e.mkt_nbr, e.invt_data FROM book_master g, XmlTable( XmlNamespaces('http://www.mrbook.com/InventoryData/book' AS "bk", 'http://www.mrbook.com/InventoryData' AS "invtdata"), '/invtdata:INVENT_DATA' PASSING g.OBJECT_VALUE COLUMNS title PATH '@title', isbn_nbr VARCHAR2(64) PATH 'bk:BOOK_ID/bk:ISBN', prod_id VARCHAR2(64) PATH 'bk:BOOK_ID/bk:PROD_ID', ctry_code NUMBER PATH 'bk:BOOK_ID/bk:CTRY_CODE', mkt_nbr NUMBER PATH 'bk:BOOK_ID/bk:MKT_NBR', invt_data XmlType PATH '.' ) e WHERE e.isbn_nbr = ?
Published by: KnightOfBlueArmor on 29 April 2013 11:57 (added Oracle version)KnightOfBlueArmor wrote:
He played really bad, and then I realized that he returned each row in the table for each iteration of the query. Is XMLExists the only way possible to return a single line, assuming that ISBN_NBR and PROD_ID are unique? Can the clause WHERE cannot be used as a discriminator at all?I don't know what you're asking.
The WHERE clause filters the result correctly?
I'm curious to see an example, if this is the case. -
Details on the order of columns in a Where Clause
Thank youHi All My both Quarries are giving same record count . so can i say that the order of the columns("msib.inventory_item_id=pol.item_id" AND" pol.item_id=msib.inventory_item_id ") in the where clause doesn't effect the query result in any situation {code } select count(*) from po_headers_all poh ,po_vendors pv ,po_lines_all pol ,po_line_locations_all pll ,mtl_system_items_b msib where poh.vendor_id = pv.vendor_id and poh.po_header_id = pol.po_header_id and pol.po_line_id = pll.po_line_id and pll.ship_to_organization_id = msib.organization_id ----------------1 and msib.inventory_item_id=pol.item_id --------------------------2 and poh.type_lookup_code = 'STANDARD' and pv.vendor_name = 'Star Gate Ltd' group by 1 select count(*) from po_headers_all poh ,po_vendors pv ,po_lines_all pol ,po_line_locations_all pll ,mtl_system_items_b msib where poh.vendor_id = pv.vendor_id and poh.po_header_id = pol.po_header_id and pol.po_line_id = pll.po_line_id and pol.item_id = msib.inventory_item_id ----------------------------------2 and pll.ship_to_organization_id = msib.organization_id -----------------------------1 and poh.type_lookup_code = 'STANDARD' and pv.vendor_name = 'Star Gate Ltd'
Published by: vijay539 on November 20, 2009 09:17
Published by: vijay539 on November 20, 2009 09:18
Published by: vijay539 on November 20, 2009 09:19
Published by: vijay539 on November 20, 2009 09:19Hello
Right; the order in which the columns appear in the SELECT clause has nothing to do with the lines that are in the result set.
In fact, unless you say SELECT DISTINCT , I don't think there's anything (except to trigger an error) you can do in the SELECT clause, which would change the lines are selected.
Published by: Frank Kulash, November 20, 2009 12:45
Sorry, I misread the question. You may have about the order of the conditions in the WHERE clause, not the SELECT clause.
The answer in short is the same:
Right.Unless you mix ANDS and ORs (no one should ever do and that you are not), the order of the conditions will make no difference in the results.
-
How to set a null column in a where clause clause involving a statement box
In oracle APEX, I a (selection list) element called: P32_STATUS. It contains two values of interest (for this discussion): 'Available' and 'checked '. In my report, I have a column called vc_status that contains two values: "Checkbox" and NULL. In my application I want to use a case statement in my where clause similar to the lines of
where
.
.
.
AND (vc_status = CASE WHEN: P32_STATUS = "Checkbox" THEN : P32_STATUS )
WHEN : P32_STATUS = 'Available' THEN NULL END)
The 'box' filtering works but the filtering to try to vc_status the NULL value does not work. Can someone help me? Thank you!
(P.S. My intuition says that there because I can not put vc_status = NULL, but I must say that vc_status IS NULL... However, I don't know how to do execution IS ZERO inside a CASE statement)
Hello
Your intuition is right...
In Oracle NULL is a bit special:
NULL = NULL is false
NULL <> NULL is false
Thus, instead of the parameter a NULL value in the CASE WHERE there is just set a value on the other side:
NVL (vc_statut, 'Available') =: P32_STATUS
That's all! Simple, clean and functional
-
T/t with the WHERE clause using a list breaks
Hello, all,.
I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking. I don't know what I'm doing wrong.
For some pseudo-code, do I have a complete query of a database called 'people '. A list of values for the t/t with the first query; the second query is my t/t:
<cfquery name="getDIR" datasource="#request.THISDSN#"> SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />) </cfquery> <cfquery name="people" database="people"> SELECT colA, colB, colC, colD FROM people WHERE 1=1 AND ( div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) ) </cfquery>
I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".» Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »
Can support _not_ QoQ lists of WHERE clauses?
V/r,
^_^
SMH - so much... I just found.
I forgot to give the lists in the second query bracket.
(The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)
* headdesk * headdesk * headdesk * headdesk *.
V/r,
^_^
-
How to filter the result with a where clause clause?
Hello
I have a nice sql query. I would like to include a where clause with a joker clause.
If the user selects for example a "AGENT_ID", then where clause would include the AGENT_ID, otherwise, every thing would appear.
The WHERE clause:SELECT "FICHE"."FICHE_ID" "FICHE_ID", "FICHE"."AGENT_ID" "AGENT_ID", "FICHE"."EQUIPE_ID" "EQUIPE_ID", "FICHE"."DATE_ACTIVITE" "DATE_ACTIVITE", "FICHE"."DATE_CREATION" "DATE_CREATION", "FICHE"."TYPE_FICHE" "TYPE_FICHE", "FICHE"."FICHE_CREE_PAR" "FICHE_CREE_PAR", "FICHE"."TOTAL_HEURES" "TOTAL_HEURES", "FICHE"."TOTAL_HEURES_EXCEPTIONNELLES" "TOTAL_HEURES_EXCEPTIONNELLES", "FICHE"."DATE_MODIFICATION" "DATE_MODIFICATION" FROM "FICHE"
WHERE AGENT_ID = ' * ' if nothing is selected.
WHERE AGENT_ID = "4290" If an agent ID is selected.
Hope I'm clear that English is not my mother tongue.
Thanks for you help.
ChristianHello
Try this
WHERE "FICHE".AGENT_ID like NVL(:val, '%')
see you soon
VT
-
Download data from an external table with a where clause clause
Hello
How can I insert data in an external table into a table already created in the database where person_id = person - _id on the external table?
Example:
External table
XX_EXTERNAL_TBL (Person_id, emp_number, emp_name)
Internal table
XX_SQL_LOADER_TEST (Person_id, emp_number, emp_name)
ID of the person already exists on the inner table (want only the last column to import where the ID of the person are the same)
Thank youYou talk of * 'Update' * (Fanfarrias y tambores)
Update XX_SQL_LOADER_TEST SLT
Set emp_number = (SELECT emp_number from XX_EXTERNAL_TBL WHERE AND.) Person_id = HI. PERSON_id)
, emp_name = (SELECT XX_EXTERNAL_TBL emp_name AND where AND.) Person_id = HI. PERSON_id) -
A CASE statement with additional where clause
Hi all
I need assistance in which this obligation clause
Table:-balance_table
Columns:-balance_type, balance_amount, balance_month, budget_name
balance_type column had given 'Real' OR 'Budget '.
Now I am trying to extract data such as: if: entered_month is Mar-2009 then before and including Mar-2009 will show real balance sheet Date and after Mar-2009 will show budget data.
It works fine, I need to add a condition more restrict the budget name, there are several budget_name in the table for balance_type = 'Budget '.
SELECT SUM (balance_amount), balance_type, balance_month
OF balance_table
WHERE balance_type =
(CASE
WHEN balance_month < =: entered_month
THEN 'real '.
ANOTHER 'Budget '.
END
)
AND budget_name = 'BUDGET1.
Balance_type GROUP, balance_month
Stated above is erroneous because ' AND budget_name = ' BUDGET1 "clause restricts the set of data."
Please help in contrcuting where clause 1) to sort the data according to Budget/actual and 2) for specific budgets, so budget_type = Budget
Thank you
BobinThat should do it.
SELECT SUM (balance_amount), balance_type, balance_month FROM balance_table WHERE (balance_type = 'Actual' and balance_month <= :entered_month ) or (balance_type = 'Budget' and balance_month > :entered_month and budget_name = :entered_budget_name ) GROUP BY balance_type, balance_month ORDER BY 2
See you soon
Sarma. -
Several SELECT statements with COUNTY with different WHERE clauses.
OK, so for a bit of background on what this is trying to accomplish...
I have a small group of people in my team and I will use GROUP BY for their names.
If each person will be on their own line. Next to their names, I want to be able to have several columns that use the ACCOUNT for the different search criteria (no duplicates)Overall, it should have their names, and I would like to add the number of tickets that each person has which meet certain criteria (all in different columns)
I have applications that can do each of these tasks, but is it possible that I can group together on a single table statements, or use subqueries for these results?Do you mean you want something like that?
SQL > ed
A written file afiedt.buf1 with the team (emp_id, emp_name)
2 (select 1, 'Fred' from dual union all
3. Select 2, 'Bob' Union double all the
4. Select 3, 'Jim' to double
5 )
6, tickets (emp_id, ticket_type, ticket_id, ticket_desc)
7 (select 1, 1, 'BUG', 'First billet Freds' double Union all)
8. Select 2, 1, 'CHANGE', "Freds second ticket" of all the double union
9 select 3, 1, 'BUG', ' Freds third ticket "of any double union
10. Select 4, 2, "CHANGE", "Bobs first ticket" of any double union
11. Select 5, 3, "CHANGE", "Jims first ticket" of any double union
12. Select 6, 3, "BUG", "Jims second ticket" of all the double union
13. Select 7, 1, 'BUG', ' Freds fourth ticket ' from dual
14 )
15-
16 END OF TEST DATA
17-
18 select emp_name
19, count (case when ticket_type = 'BUG' then 1 end to another null) and bugs
20, count (case when ticket_type = 'CHANGE' then 1 end to another null) as changes
21 of the team t
22 a left join external tickets tk (t.emp_id = tk.emp_id)
23 * emp_name group
SQL > /.EMP_ CHANGES OF BUGS
---- ---------- ----------
Bob 0 1
Fred 3 1
Jim 1 1 -
I am trying to retrieve records from a table of unique composition based on the following criteria:
-members belong to 2 different associations (coded: Association = 1 or 2)
-Some members have no postal addresses (coded: adresse_rue) and will not send mail.
-Some members Association = 1 don't you mail (coded: D or V or W, X or Z)
-No member of the Association 1 with cur_bal_2 = < gets 10 mail
-No member of the Association 2 with cur_bal_2 = <-1 get mail
-cur_bal_2 field is a numeric value in the table.
I tested
WHERE (Mbr_Scat = 'P' AND Association = 2 AND adresse_rue <>' ' AND cur_bal_2 > = - 1) by itself results accurate/w
I tested
WHERE (Mbr_Scat <>had ' AND Mbr_Scat <>'V' and 'W' AND Mbr_Scat <>'X' <>Mbr_Scat ' AND cur_bal_2 >-20 AND adresse_rue <>' ") by itself, results also w/accurate
But-
When I combine the above to:
WHERE
(Mbr_Scat = 'P' AND Association = 2 AND adresse_rue <>' ' AND cur_bal_2 > = - 1).
OR
(Mbr_Scat <>had ' AND Mbr_Scat <>'V' and 'W' AND Mbr_Scat <>'X' <>Mbr_Scat ' AND cur_bal_2 >-20 AND adresse_rue <>' ")
the part of the WHERE the criteria cur_bal_2 > = - 1 is not running (ONLY this part of the statement fails - members whose balances is less than-1 selecting.)
I get no error message.
Suggestions?
Best regards and thank you all,.
Tom Smith
Try this:
WHERE adresse_rue <> "
AND
((Association = 1 AND Mbr_Stat pas dans (serait ', 'V', 'W', 'X', 'Z') AND cur_bal_2 > = - 10) OR (Association = 2 AND cur_bal_2 > = - 1))
-
Columns in the WHERE clause - order affect the output?
I work on some queries to feed a DWH and stumbled upon this question. Let's say I have this query:
The exit will happen anyway if I do like this:(SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1 where aa.artid=tc1.artid and t.tocid=tc1.tocid and aa.abocod=c.abocod and aa.artconcod=c.concod and aa.percod=a.percod and aa.ArtAboFlgA='S' ) Tarjeta
I guess what he used, or at least I him did not change with the data that I use, but I thought to check here once just to have peace of mind. Maybe it's not the happiest example, but I guess the question is clear(SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1 where aa.artid=tc1.artid and a.percod=aa.percod and aa.ArtAboFlgA='S and tc1.tocid=t.tocid and c.abocod=aa.abocod and aa.artconcod=c.concod ) Tarjeta
No difference.
-
Problem with a Where Clause in report
Hi all
I have a simple report on the EMP table with a form of parameter to select employees of a particular or all departments.
It works fine if I'm in one or all the departments in the report. The SQL code for the report is the following:
SELECT
EMPNO,
ENAME,
HIREDATE,
SAL,
DEPTNO
Of
EMP
WHERE
DEPTNO LIKE "%" | : P68_DEPTNO | » %'
Now, I have added another element of setting labeled "category". If you select the category 'OFFICE', she must return employees of departments 10 and 20, if selected from category 'FIELD', he has to return employees to Department 30 and 40. But if you select the category ALL then he must return the employees of all departments.
Anyone would be able to advise me on the correct approach to achieve the above?
You can view the report by clicking on this link: http://apex.oracle.com/pls/otn/f?p=43368:68
Thank you
Zahid
Published by: Zahid Khan on April 15, 2009 16:20Something like:
SELECT
EMPNO,
ENAME,
HIREDATE,
SAL,
DEPTNO
Of
EMP
WHERE
DEPTNO LIKE "%" | : P68_DEPTNO | » %'
AND
((: P68_CATEGORY = 'OFFICE' AND deptno IN (10,20)))
OR (: P68_CATEGORY = 'FIELD' AND deptno IN (30, 40))
OR: P68_CATEGORY = "ALL".
)But what happens if the user chooses the category OFFICE and Deptno 30? What needs to happen next? The query above will return any given - no one is in the two 30 and Department 10 or 20!
-
I have a Select statement where I want to select rows where weighs only 1 of the selected date 3 columns is null. Is this possible?
Select rec_date, prior_rec_date2, prev_rec_date3
of my_receipts
where (not more than 1 or the date 3 fields is null)
Any help would be greatly appreciated.Hello
WHERE NVL2 (rec_date, 1, 0) + NVL2 (prior_rec_date2, 1, 0) + NVL2 (prev_rec_date3, 1, 0) >= 2
Maybe you are looking for
-
This connection is not approved
I change the time before that, but I'm not sure how im going to redefine the time and get back to work as usual.What should I do?
-
After the passage of my gmail for authentication OAuth2 account setting, whenever I send an email from my gmail, it appears to have been sent from another account I have on Thunderbird? Big problem because they are separate customers of mine. Any ide
-
I'm working on an upcoming project that will need to use a loop of producer/consumer structure. Right now, I have added a simple test of how I want the VI to work, but I'm having a problem. When I run the VI, the "elements of # in the queue" increase
-
Cannot find/establishment of eFax on my 8600 new ProPlus
-
I had repaired my Hp laptop, but he lost all the records I had, He had a virus I don't know how to get these data again