Dynamic PL SQL query
Hello
I want to run and store the results of a dynamic sql query in a strored procedure.
I get the following variables of the user running: v_column_names, v_table_name, v_col, v_value
The query will be like:
v_query: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;
for example v_column_names: = 'ACCOUNT_NUM, SYSTEM_ID, ENTITY_ID ';
v_table_name: = 'ACCOUNT '.
v_col: = 'COUNTRY_CODE ';
v_value: = "USA";
Here is what I tried
DECLARE
v_column_names VARCHAR (200): = 'ENTITY_ID, SYSTEM_ID, ACCOUNT_NUM;
v_table_name VARCHAR (200): = 'ACCOUNT '.
v_col VARCHAR (200): = 'COUNTRY_CODE ';
v_value VARCHAR (200): = "'USA"';
TYPE column_record () IS RENDERING
VARCHAR2 (200) C1: = null;
C2 VARCHAR2 (200): = null;
C3 VARCHAR2 (200): = null
);
TYPE st_table IS TABLE OF column_record INDEX DIRECTORY.
pk_table st_table;
NUMBER of v1: = 1;
BEGIN
v_select: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;
EXECUTE IMMEDIATE v_select COLLECT LOOSE pk_table.
I'm IN 1.pk_table.count LOOP
DBMS_OUTPUT. Put_line (pk_table (v1). (C1);
DBMS_OUTPUT. Put_line (pk_table (v1). (C2);
DBMS_OUTPUT. Put_line (pk_table (v1). (C3);
v1: = v1 + 1;
END LOOP;
END;
The number of column names in v_column_names is dynamic, so I need a way to store the results and then manipulate them.
I look forward to your reply.
EDIT: The real question:
1. in the settings I have pass the table name and the value of the primary key of the row I want to delete.
2. He then checks if this line is referenced anywhere, removes the reference, and then deletes the current line. This can go, until all the rows that are referenced are removed.
The above code, I have provided a small part of the largest of stored procedure.
Thank you all, I found the tips very helpful. I found a solution to my problem:
It generates all removal requests to remove a specific line. Not what I wanted, but this does not solve my problem.
The reason why is that I discovered that we do not use the ON DELETE CASCADE that we don't remove a record accidentally, I know we have an option to restore, but it is just in case something goes wrong.
Tags: Database
Similar Questions
-
A difficult dynamic SQL query problem
Hi all
I have a very interesting problem to work:
We have this special table defined as follows:
CREATE TABLE sales_data)
sales_id NUMBER,
NUMBER of sales_m01
NUMBER of sales_m02
NUMBER of sales_m03
NUMBER of sales_m04
NUMBER of sales_m05
NUMBER of sales_m06
NUMBER of sales_m07
NUMBER of sales_m08
NUMBER of sales_m09
NUMBER of sales_m10
NUMBER of sales_m11
NUMBER of sales_m12
sales_prior_yr NUMBER);
/
Columns ' sales_m01... sales_m12' represents aggregated monthly sales, what "sales_m01" is translated by "sales for the month of January, January is the first month,"sales_m02"in sales for the month of February and so on.»
The problem I encounter is that we have a project that requires that a parameter is passed to a stored procedure that represents the number of months which is then used to create a SQL query with aggregations of next mandatory field, which depends on the parameter passed:
Example 1: entry of parameter: 4
Should be built dynamically to SQL query:
SELECT
Sum (sales_m04) as CURRENT_SALES,
Sum (sales_m01 + sales_m02 + sales_m03 + sales_m04) SALES_YTD
Of
sales_data
WHERE
sales_id = '0599768';
Example 2: input parameter: 8
Should be built dynamically to SQL query:
SELECT
Sum (sales_m08) as CURRENT_SALES,
SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 +)
sales_m05 + sales_m06 + sales_m07 + sales_m08) SALES_YTD
Of
sales_data
WHERE
sales_id = '0599768';
So in a sense, the contents of SUM(sales_m01...n) would vary according to the parameter, which must be a number between 1... 12 what is a month, which in turn corresponds to a range of real field on the table itself. The resulting dynamic query should include only those columns/fields in the table that is within the range given by the input parameter and does not account for all the other columns/fields.
Any solution is greatly appreciated.
Thank you.SQL> declare cols long; param integer := 6; sales_id integer := 0599768; begin for i in 1..param loop cols := cols || 'sales_m' || to_char(i, 'fm00') || '+'; end loop; dbms_output.put_line('select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,'+') || ') sales_ytd from sales_data WHERE sales_id = :1'); end; / select sum(sales_m06) current_sales, sum(sales_m01+sales_m02+sales_m03+sales_m04+sales_m05+sales_m06) sales_ytd from sales_data WHERE sales_id = :1 PL/SQL procedure successfully completed.
Now it should be obvious:
Instead of dbms_output OPEN a refcursor:SQL> declare cols long; param integer := 6; sales_id integer := 0599768; cur sys_refcursor; begin for i in 1..param loop cols := cols || 'sales_m' || to_char(i, 'fm00') || ','; end loop; open cur for 'select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,',') || ') sales_ytd from sales_data WHERE sales_id = :1' using sales_id; ..... end; /
Published by: michaels2 on July 26, 2009 09:49
replaced ',' with ' + '.
-
Dynamic SQL query in the DB adapter
Hello
I want to use the following custom SQL query in the DB adapter:
SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)
the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case
Thank you
SunilUse the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)
Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)
Thank you
-Sreeny -
DA on updatable report items Sql query using the class
Request Express 4.2.5.00.08
10-11 g Oracle
I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.
However, I've now added some complex things.
for example. My region is based on the query of SQL Type (editable report).
SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;
I can also add a new line of course.
My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.
for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.
And now, I created the DA.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
1. action: set value
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
The element affected: P10_X1 (it is a hidden item)
2. action: Plsql Code
Code: start to null; end;
Page items to submit: P10_X1
3. action: Plsql Code
Code: start
If: P10_X1 between '03' AND '11' then
: P10_X1: = 'EARLIES ';
elsif: P10_X1 then '12' and '18'
: P10_X1: = 'LATES ';
on the other
: P10_X1: = 'NIGHTS';
end if;
end;
Page items to submit: P10_X1
NOW another DA
Event: change
Article (s) P10_X1
Condition (in list)
value (HASTY, LATES, NIGHTS)
Action:
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
Affected item:
Selection type: jQuery Selector
jQuery Selector:. Shift_time
Well, I look forward all the above work well, but I'm having a problem.
If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.
I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?
Help, please!
Kind regards
RI
I found the solution me thank you.
I removed all the DA mentioned above and created a new.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
Scope of the event: dynamic and light on page load.
Action (Javascript code)
ROW_ID = $(this.triggeringElement).attr('id').substr (4);
If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">=>
.Val ('EARLIES') $(«#f11_» + row_id);
}
ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">=>
.Val ('LATES') $(«#f11_» + row_id);
}
ElseIf (. val() > $19 (this.triggeringElement)) {}
.Val ('NIGHTS') $(«#f11_» + row_id);
}
also created another DA because I have a disabled report items.
Event: before the page is sent.
$('_:_disabled').removeAttr ("disabled");
and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).
Kind regards.
-
Hi all
I'm trying to find a solution to this problem
SELECT b.person,
tbl1.program_code,
TO_CHAR (to_date (tbl1.start_date, 'YYYYMMDD'), ' MM/DD/YYYY'),
TO_CHAR (to_date (tbl1.end_date, 'YYYYMMDD'), ' MM/DD/YYYY'),
TBL2.program_code,
TO_CHAR (to_date (TBL2.start_date, 'YYYYMMDD'), ' MM/DD/YYYY')
Person_table p,
(SELECT e.person,
e.program_code,
e.start_date,
e.end_date,
OF e program_table,.
a_program_table has,
WHERE the e.end_date BETWEEN: first_day_year AND: last_day_year
AND a.system_date > to_date (: last_run_date, 'YYYYMMDD')) tbl1.
(SELECT e.person,
e.program_code,
e.start_date,
e.end_date,
OF e program_table,.
a_program_table has,
WHERE the e.start_date BETWEEN: first_day_year AND: last_day_year
AND a.system_date > to_date (: last_run_date, 'YYYYMMDD')) tbl2
WHERE = tbl1.person p.person
AND tbl1.person = tbl2.person
AND to_date (tbl1.end_date, 'YYYYMMDD') < to_date (tbl2.start_date, 'YYYYMMDD')
ORDER BY tbl2.start_date asc, asc tbl1.end_date;
The tables look like this
Program_table
PERSON PROGRAM_CODE START_DATE END_DATE
------ ------------ ---------- ---------
20150115 20150101 17 A1
20150125 20150116 13 A1
20150210 20150126 3 A1
20150220 20150211 16 A1
22991231 20150221 13 A1
A_program_table
PERSON PROGRAM_CODE START_DATE END_DATE SYSTEM_DATE
------ ------------ ---------- --------- -----------
17 20150101 20150115 20150101 A1
13 20150116 20150125 20150116 A1
3 20150126 20150210 20150126 A1
16 20150211 20150220 20150211 A1
13 20150221 22001231 20150221 A1
OUTPUT_RESULT
PERSON PROGRAM_CODE START_DATE END_DATE PROGRAM_CODE START_DATE
------ ------------ ---------- -------- ------------ ----------
A1 3 26/01/2015 10/02/2015 13 21/02/2015 -the unwanted span
A1 3 26/01/2015 10/02/2015 16 02/11/2015
16/02/11/2015-02/20/2015 A1 13 21/02/2015
As you can see here, I'm recording a person of conversion from one program to the other, given that the query has been run since last month. The results I'm capture is for the month of February.
I wanted the transition of the program 3-16 and 16-13, but not from 3 to 13. I need to eliminate the transition from 3 to 13. The reason why is this makes its appearance is due to the line
AND to_date (tbl1.end_date, 'YYYYMMDD') < to_date (tbl2.start_date, 'YYYYMMDD').
I use this because I want the result spans compared dynamically.
I'm looking for change of this request (for example: we can have 10 entries on the table for a month, but have only 9 transitions listed in the final - either).
Note: I would like to have a single query while as noted above, no procedure or query.
Thanks in advance
Hello
Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.
Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
You said that this problem was "creation of the pl/sql query", but you have probably not all PL/SQL; just SQL.
2886750 wrote:
...
AND to_date (tbl1.end_date, 'YYYYMMDD')< to_date="" (tbl2.start_date,="">
Do not store information on dates in the string columns. Use the DATE columns. Then you won't need TO_DATE in conditions like this.
You do a join to match each row in each previous row for the same person. If I understand the problem, you don't want to compare with each previous line, you only want to compare with the last front row. That sound like a job for the analytic LAG function.
-
Hey guys,.
I'm using version 4.2.6 apex. The theme is 26.
IM also using Listener Oracle APEX.
I can print my classic report in PDF or CSV format.
But I need to export it as a .xls extension.
Report type: SQL (body of function from PL/SQL returning the SQL) query
I need is like this cause my 'where' clause type is dynamic.
Look at using this method: Tom's Blog: a non-standard export excel 2010 (.xlsx)
I do something similar for downloads to excel in my projects...
Thank you
Tony Miller
Software LuvMuffin
Ruckersville, WILL -
SQL Query + long running.
Dear gurus/masters/All,
I beg you all to help me with the setting of the SQL query that takes more time. DB version: 10.2.0.4
Query SQL WHERE condition:
Query execution plan:select column1, column2, ......... FROM SIEBEL.S_ORG_EXT T1, SIEBEL.S_PROD_INT T2, SIEBEL.S_VOD T3, SIEBEL.S_ORG_EXT T4, SIEBEL.S_ORG_EXT T5, SIEBEL.S_ORG_EXT_X T6, SIEBEL.S_PROD_LN T7, SIEBEL.S_ASSET_OM T8, SIEBEL.S_VOD_VER T9, SIEBEL.S_CTLG_CAT T10, SIEBEL.S_CONTACT T11, SIEBEL.S_PARTY T12, SIEBEL.S_PARTY T13, SIEBEL.S_PROD_INT T14, SIEBEL.S_ASSET_BU T15, SIEBEL.S_CTLG_CAT T16, SIEBEL.S_ORG_EXT T17, SIEBEL.S_ORG_EXT T18, SIEBEL.S_ASSET T19, SIEBEL.S_ADDR_PER T20, SIEBEL.S_ORG_EXT T21, SIEBEL.S_ASSET_X T22, SIEBEL.S_ASSET T23 WHERE T16.PAR_CAT_ID = T10.ROW_ID (+) AND T14.CG_PR_CTLG_CAT_ID = T16.ROW_ID (+) AND T3.ROW_ID = T9.VOD_ID AND T14.CFG_MODEL_ID = T3.OBJECT_NUM AND T23.OWNER_CON_ID = T11.ROW_ID (+) AND T23.OWNER_ACCNT_ID = T6.PAR_ROW_ID (+) AND T23.PER_ADDR_ID = T20.ROW_ID (+) AND T23.PROD_ID = T14.ROW_ID AND T23.OWNER_ACCNT_ID = T21.PAR_ROW_ID (+) AND T14.PR_PROD_LN_ID = T7.ROW_ID (+) AND T23.ROOT_ASSET_ID = T19.ROW_ID (+) AND T19.PROD_ID = T2.ROW_ID (+) AND T23.BILL_ACCNT_ID = T18.PAR_ROW_ID (+) AND T23.RTNG_DLR_ID = T1.PAR_ROW_ID (+) AND T23.PREF_SRV_DLR_ID = T17.PAR_ROW_ID (+) AND T23.DLR_ID = T4.PAR_ROW_ID (+) AND T23.ROW_ID = T22.PAR_ROW_ID (+) AND T23.ROW_ID = T8.PAR_ROW_ID (+) AND T23.PR_CON_ID = T12.ROW_ID (+) AND T23.BU_ID = T15.BU_ID (+) AND T23.ROW_ID = T15.ASSET_ID (+) AND T15.BU_ID = T13.ROW_ID (+) AND T15.BU_ID = T5.PAR_ROW_ID (+) AND ((T23.SERIAL_NUM IS NOT NULL AND T23.PAR_ASSET_ID IS NULL OR T23.X_PHONE_NUMBER IS NOT NULL AND T23.PAR_ASSET_ID IS NOT NULL) AND (T9.VER_NUM = :1));
PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 967177145 -------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 54117 | 92M| 4435K (1)| 01:58:43 | | 1 | NESTED LOOPS OUTER | | 54117 | 92M| 4435K (1)| 01:58:43 | | 2 | NESTED LOOPS OUTER | | 54117 | 87M| 4261K (1)| 01:54:04 | | 3 | NESTED LOOPS OUTER | | 54117 | 86M| 4154K (1)| 01:51:13 | | 4 | NESTED LOOPS OUTER | | 54117 | 85M| 4111K (1)| 01:50:03 | | 5 | NESTED LOOPS OUTER | | 54117 | 84M| 3980K (1)| 01:46:33 | | 6 | NESTED LOOPS OUTER | | 54117 | 83M| 3937K (1)| 01:45:24 | | 7 | NESTED LOOPS OUTER | | 54117 | 81M| 3763K (1)| 01:40:44 | | 8 | NESTED LOOPS OUTER | | 54117 | 81M| 3751K (1)| 01:40:25 | | 9 | NESTED LOOPS OUTER | | 54117 | 80M| 3621K (1)| 01:36:57 | | 10 | NESTED LOOPS OUTER | | 54117 | 73M| 3515K (1)| 01:34:07 | | 11 | NESTED LOOPS OUTER | | 54117 | 71M| 3410K (1)| 01:31:18 | | 12 | NESTED LOOPS OUTER | | 54117 | 69M| 3410K (1)| 01:31:18 | | 13 | NESTED LOOPS OUTER | | 54117 | 67M| 3410K (1)| 01:31:18 | | 14 | NESTED LOOPS OUTER | | 54117 | 66M| 3410K (1)| 01:31:18 | | 15 | NESTED LOOPS OUTER | | 54117 | 64M| 3324K (1)| 01:28:59 | | 16 | NESTED LOOPS OUTER | | 54117 | 62M| 3237K (1)| 01:26:40 | | 17 | NESTED LOOPS | | 54117 | 57M| 3106K (1)| 01:23:10 | | 18 | NESTED LOOPS OUTER | | 71 | 43665 | 381 (2)| 00:00:01 | | 19 | NESTED LOOPS OUTER | | 71 | 42316 | 323 (2)| 00:00:01 | | 20 | NESTED LOOPS OUTER | | 71 | 41322 | 322 (2)| 00:00:01 | | 21 | NESTED LOOPS | | 71 | 24708 | 265 (3)| 00:00:01 | | 22 | NESTED LOOPS | | 77 | 2772 | 141 (4)| 00:00:01 | |* 23 | TABLE ACCESS FULL | S_VOD_VER | 75 | 1350 | 72 (7)| 00:00:01 | | 24 | TABLE ACCESS BY INDEX ROWID| S_VOD | 1 | 18 | 1 (0)| 00:00:01 | |* 25 | INDEX UNIQUE SCAN | S_VOD_P1 | 1 | | 1 (0)| 00:00:01 | | 26 | TABLE ACCESS BY INDEX ROWID | S_PROD_INT | 1 | 312 | 2 (0)| 00:00:01 | |* 27 | INDEX RANGE SCAN | S_PROD_INT_F9 | 1 | | 1 (0)| 00:00:01 | | 28 | TABLE ACCESS BY INDEX ROWID | S_PROD_LN | 1 | 234 | 1 (0)| 00:00:01 | |* 29 | INDEX UNIQUE SCAN | S_PROD_LN_P1 | 1 | | 1 (0)| 00:00:01 | | 30 | TABLE ACCESS BY INDEX ROWID | S_CTLG_CAT | 1 | 14 | 1 (0)| 00:00:01 | |* 31 | INDEX UNIQUE SCAN | S_CTLG_CAT_P1 | 1 | | 1 (0)| 00:00:01 | | 32 | TABLE ACCESS BY INDEX ROWID | S_CTLG_CAT | 1 | 19 | 1 (0)| 00:00:01 | |* 33 | INDEX UNIQUE SCAN | S_CTLG_CAT_P1 | 1 | | 1 (0)| 00:00:01 | |* 34 | TABLE ACCESS BY INDEX ROWID | S_ASSET | 760 | 375K| 43753 (1)| 00:01:11 | |* 35 | INDEX RANGE SCAN | S_ASSET_U2 | 55873 | | 312 (3)| 00:00:01 | | 36 | TABLE ACCESS BY INDEX ROWID | S_ASSET_OM | 1 | 94 | 2 (0)| 00:00:01 | |* 37 | INDEX RANGE SCAN | S_ASSET_OM_U1 | 1 | | 2 (0)| 00:00:01 | | 38 | TABLE ACCESS BY INDEX ROWID | S_CONTACT | 1 | 39 | 2 (0)| 00:00:01 | |* 39 | INDEX UNIQUE SCAN | S_CONTACT_P1 | 1 | | 1 (0)| 00:00:01 | | 40 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 29 | 2 (0)| 00:00:01 | |* 41 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0)| 00:00:01 | | 42 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 | |* 43 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 44 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 | |* 45 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 46 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 | |* 47 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 48 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 36 | 2 (0)| 00:00:01 | |* 49 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 50 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 139 | 2 (0)| 00:00:01 | |* 51 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 52 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_X | 1 | 16 | 2 (0)| 00:00:01 | |* 53 | INDEX RANGE SCAN | S_ORG_EXT_X_U1 | 1 | | 2 (0)| 00:00:01 | |* 54 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1 | 12 | 1 (0)| 00:00:01 | | 55 | TABLE ACCESS BY INDEX ROWID | S_ASSET_BU | 1 | 34 | 3 (0)| 00:00:01 | |* 56 | INDEX RANGE SCAN | S_ASSET_BU_U1 | 1 | | 2 (0)| 00:00:01 | |* 57 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1 | 12 | 1 (0)| 00:00:01 | | 58 | TABLE ACCESS BY INDEX ROWID | S_ASSET | 1 | 37 | 2 (0)| 00:00:01 | |* 59 | INDEX UNIQUE SCAN | S_ASSET_P1 | 1 | | 2 (0)| 00:00:01 | | 60 | TABLE ACCESS BY INDEX ROWID | S_PROD_INT | 1 | 16 | 1 (0)| 00:00:01 | |* 61 | INDEX UNIQUE SCAN | S_PROD_INT_P1 | 1 | | 1 (0)| 00:00:01 | | 62 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 14 | 2 (0)| 00:00:01 | |* 63 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 | | 64 | TABLE ACCESS BY INDEX ROWID | S_ASSET_X | 1 | 93 | 3 (0)| 00:00:01 | |* 65 | INDEX RANGE SCAN | S_ASSET_X_U1 | 1 | | 2 (0)| 00:00:01 | -------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 23 - filter("T9"."VER_NUM"=TO_NUMBER(:1)) 25 - access("T3"."ROW_ID"="T9"."VOD_ID") 27 - access("T14"."CFG_MODEL_ID"="T3"."OBJECT_NUM") 29 - access("T14"."PR_PROD_LN_ID"="T7"."ROW_ID"(+)) 31 - access("T14"."CG_PR_CTLG_CAT_ID"="T16"."ROW_ID"(+)) 33 - access("T16"."PAR_CAT_ID"="T10"."ROW_ID"(+)) 34 - filter("T23"."PAR_ASSET_ID" IS NULL AND "T23"."SERIAL_NUM" IS NOT NULL OR "T23"."X_PHONE_NUMBER" IS NOT NULL AND "T23"."PAR_ASSET_ID" IS NOT NULL) 35 - access("T23"."PROD_ID"="T14"."ROW_ID") 37 - access("T23"."ROW_ID"="T8"."PAR_ROW_ID"(+)) 39 - access("T23"."OWNER_CON_ID"="T11"."ROW_ID"(+)) 41 - access("T23"."PER_ADDR_ID"="T20"."ROW_ID"(+)) 43 - access("T23"."RTNG_DLR_ID"="T1"."PAR_ROW_ID"(+)) 45 - access("T23"."DLR_ID"="T4"."PAR_ROW_ID"(+)) 47 - access("T23"."PREF_SRV_DLR_ID"="T17"."PAR_ROW_ID"(+)) 49 - access("T23"."BILL_ACCNT_ID"="T18"."PAR_ROW_ID"(+)) 51 - access("T23"."OWNER_ACCNT_ID"="T21"."PAR_ROW_ID"(+)) 53 - access("T23"."OWNER_ACCNT_ID"="T6"."PAR_ROW_ID"(+)) 54 - access("T23"."PR_CON_ID"="T12"."ROW_ID"(+)) 56 - access("T23"."ROW_ID"="T15"."ASSET_ID"(+) AND "T23"."BU_ID"="T15"."BU_ID"(+)) 57 - access("T15"."BU_ID"="T13"."ROW_ID"(+)) 59 - access("T23"."ROOT_ASSET_ID"="T19"."ROW_ID"(+)) 61 - access("T19"."PROD_ID"="T2"."ROW_ID"(+)) 63 - access("T15"."BU_ID"="T5"."PAR_ROW_ID"(+)) 65 - access("T23"."ROW_ID"="T22"."PAR_ROW_ID"(+)) Note ----- - dynamic sampling used for this statement 105 rows selected.
Hello
It is not necessary to display the trace file - everything is clear from the plans that you have posted. The optimizer is the selectivity calculation assuming the absence of correlation between the columns. You can do these calculations that yourself and you see that if the entries are correct and if the hypothesis of lack of correlation is also correct, then the results should be correct, too. Since they are not, it's one of two things: optimizer stats are wrong, or the columns are in fact related.
First of all check the optimizer statistics: i.e. take NUM_ROWS and NUM_NULLS of DBA_TAB_COL_STATISTICS and compare them with the actual rowcounts. If they are correct (in a reasonable error margin), then it means that the columns are correlated, and the optimizer will need additional assistance to obtain right of cardinalities.
Best regards
Nikolai -
Hi team,
For example if I have a demo table with 4 columns (A, B, C, D) DEMO.
I want a report on this table, such that the report contains the headers and the Details section.
For each unique combination of (A, B) I must first of all show header based on the header information I want to display the detailed section.
In my header section I want to display 2 columns (A, B) that are common to the detailed section. Remaining 2 columns in the detailed section.
Here is an example: -.
A B C D
1 5 9 3
1 5P8
1 5 P O
1-5-9
1 8 9
1 D * /
2 8 33 P
2 P O O
2 P L L
YOU WILL SEE
A AND B
1 5
C D
9 3
P 8
P O
A AND B
1 D
C D
5 9
8 9
* /
A AND B
2 P
C D
8 33
O O
L L
Please suggest the solution (sql query) for above the problem and how to nest gernerated headers dynamically in the report area.
I use APEX 4.0
Any position in this regard is very significant.
Thanks and greetings
RajendraTry this:
SQL> select * from tab; 1 5 9 3 1 5 P 8 1 5 P O 1 D 5 9 1 D 8 9 1 P 8 3 1 P O O 7 rows selected. SQL> select a,b from (select r,a,b from ( select to_char(rownum)||'a' r, 'A' a,'B' b from (select distinct a, b from tab order by a,b)) union ( select to_char(rownum)||'c' r, 'C' c,'D' d from (select distinct a, b from tab order by a,b)) union ( select to_char(rownum)||'b' r, a,b from (select distinct a, b from tab order by a,b)) union select parent.r, tab.c, tab.d from ( select to_char(rownum)||'d' r, a,b from (select distinct a, b from tab order by a,b)) parent , tab where parent.a=tab.a and parent.b=tab.b ) order by r ; A B 1 5 C D 9 3 P 8 P O A B 1 D C D 5 9 8 9 A B 1 P C D 8 3 O O
-
Analyze: Body of PL/SQL function returning a SQL query
I need to get the final SQL returned by the PL/SQL function.
I'll use this final SQL in a procedure.
Please provide only a few tips on how to get the SQL code. I already looked in the DBMS_SQL package, but I don't know if this is the right place to look.
Kind regards
Sumitdeclare l2 varchar2(2000); begin l2:= 'Select NAME,ORIGINATED,OWNER,ORIGINATOR,'; l2:= l2 || 'DESIGNATED_UNIT,SOURCE,'; l2:= l2 || 'REFERENCE'; l2:= l2 || ' from MV_DETAILED_DATA'; /* Copy dynamic query SQL to application item for later use. */ :app_item := l2; wwv_flow.debug('l2: ' || l2); return l2; end;
I always use a call of debugging in the region of body of the PL/SQL function returning a SQL query sources so the real generated SQL can be quickly entered via the debug mode.
-
PL/SQL Query return function, adding the column links
Hi all
I'm working on a SQL report with the area type = function from PL/SQL Query to return
All columns are generated dynamically based on my mapping table and a column of ID.
So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
So not only the columns are dynamic, but the order of the columns varies also.
But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.
I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
My pl/sql block is something like that...
Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, '; // g=a v_cols := 'contains all columns from the mapping table based on a ID(hidden item)'; v_from := 'FROM table'; v_where := 'where condition is put in here'; v_query := v_select||v_from||v_where; return v_query;
I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
How can I go to a column value to the function?
Thank you
DippyThis should work if all goes well:
v_select := q'[ SELECT '' as chart, ]';
Published by: Dimitri Gielis on May 20, 2010 20:10
-
Failed to parse the SQL query: ORA-00918: column ambiguously defined
I have an application that generates a report that says what indicator is connected to what size. For this, a package is created called and under this function is there that generates and returns a dynamic SQL strings that indicates which indicators depends on what size. In my report under the defination of region identification section, the type is mentioned the SQL (sql query return function body) and in the section source it returning
Thanks in advance. Any suggestions on this will be useful for me to traceout the issue.
Concerning
ADI
Published by: Adi on January 4, 2010 01:04
-
fix column names in a sql Query
Hi people,
I am upgrading an application and there are database columns that have major changes that could affect the production of reports. I want to the investigation from v$ SQL for a few days to see if these columns are affected. That is the problem.
Watching a SQL query to determine which columns are used is not nearly as easy as it sounds. Are there functions oracle or 3rd party tools that allows to display the columns used by a sql query? (this becomes extremely difficult when subqueries are involved)
For example.
Select
name, b.dep_id, employe_id
EMP a
Inner join v_department b on a.dep_id = b.dep_id
Used columns:+.
EMP. Name+.
Departments.dep_id (under the view).
EMP.employee_id+.
EMP.dep_id (from the join)+.If you are on > 10g, you can use dbms_xplan with option 'all '.
She has "projection column information" which is exactly what you want.UKJA@ukja102> set serveroutput on UKJA@ukja102> UKJA@ukja102> drop table t1 purge; Table dropped. Elapsed: 00:00:00.03 UKJA@ukja102> create table t1(c1 int, c2 int); Table created. Elapsed: 00:00:00.03 UKJA@ukja102> UKJA@ukja102> explain plan for 2 select 3 t1.c1, t1.c2, v.cnt 4 from t1, 5 (select /*+ no_merge */ c1, count(*) as cnt 6 from t1 7 group by c1) v 8 where 9 t1.c1 = v.c1 10 ; Explained. Elapsed: 00:00:00.01 UKJA@ukja102> UKJA@ukja102> @plan_all UKJA@ukja102> select * from table(dbms_xplan.display(null,null,'all')) 2 / PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 536125944 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 52 | 6 (34)| 00:00:01 | |* 1 | HASH JOIN | | 1 | 52 | 6 (34)| 00:00:01 | | 2 | TABLE ACCESS FULL | T1 | 1 | 26 | 2 (0)| 00:00:01 | | 3 | VIEW | | 1 | 26 | 3 (34)| 00:00:01 | | 4 | HASH GROUP BY | | 1 | 13 | 3 (34)| 00:00:01 | | 5 | TABLE ACCESS FULL| T1 | 1 | 13 | 2 (0)| 00:00:01 | ----------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 2 - SEL$1 / T1@SEL$1 3 - SEL$2 / V@SEL$1 4 - SEL$2 5 - SEL$2 / T1@SEL$2 Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("T1"."C1"="V"."C1") Column Projection Information (identified by operation id): ----------------------------------------------------------- 1 - (#keys=1) "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22], "V"."CNT"[NUMBER,22] 2 - "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22] 3 - "V"."C1"[NUMBER,22], "V"."CNT"[NUMBER,22] 4 - (#keys=1) "C1"[NUMBER,22], COUNT(*)[22] 5 - "C1"[NUMBER,22] Note ----- - dynamic sampling used for this statement 40 rows selected. Elapsed: 00:00:00.01 UKJA@ukja102> UKJA@ukja102> UKJA@ukja102> @end UKJA@ukja102> set echo off
Dion Cho
-
Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit
I have this SQL query:
DECLARE TABLE (@DataTypeTable)
Name varchar (128).
TypeID INT)-Add comma delimeted type data in the temporary table names
INSERT INTO @DataTypeTable (name)
SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')SELECT the name OF @DataTypeTable
That takes a comma delimited by the string and returns the string as a table. It works correctly in Microsoft SQL Server Management Studio. When I run this as a stored procedure I return nothing. There are no errors, SQL or otherwise. I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above). Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?
Thanks in advance.
-
HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.
As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock
There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
Help me pls!with respect,
Ray
Hello
You have two cases:
(1) connect to the database with string (link a string of connection information), and then type something like this:
Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)(2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.
There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl
Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.
Kind regards
-
I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.
I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.
Thanks in advance for your help,
Jim
Jim,
Just to be sure, have you used 'is' instead of '=' in this command?
This makes all the difference in this command.
Cerati
Maybe you are looking for
-
L7590 don't Print Full Black Ink, the darkness is uneven
I have an Officejet Pro L7590 and printing I cannot get all of the black ink level. This has happened actually came out of nowhere I remember not to proceed with changes in real system before the problem started. There are a few areas on the page t
-
Connect to SQL using SSL server
I am currently using a connection that is encrypted to a SQL Server database. I am able to do this by adding 'encrypt = true' for my channel connection and using a .pem file that I am able to apply using the Microsoft Management console. http://www.s
-
Hello I I32 table to display and I found nothing in Google. any expert here know if there is a way to display image I32? I tried to use Fillimage to see if there's a way to work around, see attachment with the data table. of the testDatadisplay.vi,
-
That is to say my vista is not genuine and it came on the computer
Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: You have problems with programs Error messages Recent changes to your computer What you have already tried to solve the problem
-
The data in the list scrolling
Hello world I use the normal list in my app, bt the problem is that the width of the list item. I have no problem with the list in landscape bt from potrait extra mode "".. "". are coming instead of data, Is it possible to scroll through the data in