How to rewrite dynamic SQL built using IF clauses, as static SQL?
Hi folks
I have some Dynamic SQL that I would like to rewrite as static.
The original PL/SQL code contains a number of IF clauses that I would normally replace with CASE statements in the static code, but I am wondering if I'm doing it the best way as although it works, I am not that happy with it for reasons described below.
[Please excuse any remaining syntax errors, I have tried to reduce them but we have no Oracle on our internet network and I can't CutnPaste from the dev network.]
So...
An example of what I would normally do.
A silly example, I admit, but it's just for demo.
Original Dynamic Code:
PROCEDURE GET_EMP_NAMES(p_job_title IN VARCHAR2 := NULL
,p_car_class IN NUMBER := NULL
,p_REF_CURSOR OUT CURVAR)
Purpose: Provide names of all employees. But if MANAGERS only is requested,
then limit the result set to those employees with the car class specified.
Fields in table emp: first_name, fam_name, car_class(NUMBER)
AS
v_str VARCHAR2(1000);
BEGIN
v_str := 'select e.first_name, e.fam_name FROM emp e WHERE 1=1 ';
IF p_job_title = 'MANAGER' and p_car_class IS NOT NULL THEN
v_str := v_str || ' AND e.car_class = ' || p_car_class;
END IF;
OPEN p_REF_CURSOR FOR v_str;
END;My usual rewrite:
BEGIN
OPEN p_REF_CURSOR FOR
SELECT e.first_name, e.fam_name
FROM emp e
WHERE e.car_class =
CASE WHEN p_job_title = 'MANAGER' AND p_car_class IS NOT NULL
THEN p_car_class
ELSE e.car_class
END;
END;My problem with this is that some employees may have an e.car_class of NULL.
In this case the WHERE clause will evaluate to NULL = NULL, and so they will not be included in the result set.
So I usually defend with NVL() and some fictive constant for the NVL result, ie:
AS
k_dummy_val CONSTANT NUMBER(20) := 56394739465639473946;
BEGIN
OPEN p_REF_CURSOR FOR
SELECT e.first_name, e.fam_name
FROM emp e
WHERE NVL(e.car_class,k_dummy_val) =
CASE WHEN p_job_title = 'MANAGER' AND p_car_class IS NOT NULL
THEN p_car_class
ELSE NVL(e.car_class,k_dummy_val)
END;
END;But now I have had to decide what to use for k_dummy_val. I need to choose some fictive number that is not and will not EVER be used as a car class. This is a problem as I do not know this.
So this makes me think that my technique is incorrect.
Do you have any suggestions?
Many thanks
Assaf
Edited by: user5245441 on 03:55 24/04/2011
Hi,
Assaf wrote:
... if I were to do the following then it would be a mess, right? Barckets are needed and if I have many such conditions and make a mistake with the brackets, then... :(Brackets may be needed, but they're a good idea even if they are not needed.
WHERE p_job_title != 'MANAGER'
OR 'X' || TO_CHAR (car_class)
= 'X' || TO_CHAR (p_car_class)
AND p_yet_another_param != 'SOMETHING ELSE'
OR 'X' || TO_CHAR (another_field)
= 'X' || TO_CHAR (p_another_param)What do you think?Using parenetheses, that would be:
WHERE ( p_job_title != 'MANAGER'
OR 'X' || TO_CHAR (car_class)
= 'X' || TO_CHAR (p_car_class)
AND ( p_yet_another_param != 'SOMETHING ELSE'
OR 'X' || TO_CHAR (another_field)
= 'X' || TO_CHAR (p_another_param)
)I find this clearer than CASE expressions, but I won't be maintaining your code.
This is one place where implicit conversions won't hurt you. Both operands to || have to be strings. If you use a NUMBER as an operand to ||, then it will be implicitly converted to a string. Usually, it's better to make this clear by using TO_CHAR, and converting the NUMBER to a string explicitly, but in this case you might gain clarity by not using TO_CHAR.
Put comments in your code where you think they'll help someone to read and understand it.
WHERE
-- p_car_class only applies to MANAGERs
( p_job_title != 'MANAGER'
OR 'X' || car_class
= 'X' || p_car_class
AND ( p_yet_another_param != 'SOMETHING ELSE'
OR 'X' || another_field
= 'X' || p_another_param
... I avoid dynamic whenever possible, leaving it for use only in situations where things such as Table Names are unknown at compile time. I find it complex and error prone, and especially difficult for another developer to support at a later date.I agree. I agree especially with being concerned about the developer who has to modify or debug the code in the future, regardless of whether it's you or another.
Similar Messages
-
How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?
How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?
Here is a fictional sample layout of the data I have from My_Source_Query:
Customer | VIN | Year | Make | Odometer | ... followed by 350 more columns/fields
123 | 321XYZ | 2012 | Honda | 1900 |
123 | 432ABC | 2012 | Toyota | 2300 |
456 | 999PDQ | 2000 | Ford | 45586 |
876 | 888QWE | 2010 | Mercedes | 38332 |
... followed by up to 25 more rows of data from this query.
The exact number of records returned by My_Source_Query is unknown ahead of time, but should be less than 25 even under extreme situations.
Here is how I would like the data to be:
Column1 |Column2 |Column3 |Column4 |Column5 |
Customer | 123 | 123 | 456 | 876 |
VIN | 321XYZ | 432ABC | 999PDQ | 888QWE |
Year | 2012 | 2012 | 2000 | 2010 |
Make | Honda | Toyota | Ford | Mercedes|
Odometer | 1900 | 2300 | 45586 | 38332 |
... followed by 350 more rows with the names of the columns/fields from the My_Source_Query.
From reading and trying many, many, many of the posting on this topic I understand that the unknown number or rows in My_Source_Query can be a problem and have considered working with one row at a time until each row has been converted to a column.
If possible I'd like to find a way of doing this conversion from rows to columns using a query instead of scripts if that is possible. I am a novice at this so any help is welcome.
This is a repost. I originally posted this question to the wrong forum. Sorry about that.The permission level that I have in the Oracle environment is 'read only'. This is also be the permission level of the users of the query I am trying to build.
As requested, here is the 'create' SQL to build a simple table that has the type of data I am working with.
My real select query will have more than 350 columns and the rows returned will be 25 rows of less, but for now I am prototyping with just seven columns that have the different data types noted in my sample data.
NOTE: This SQL has been written and tested in MS Access since I do not have permission to create and populate a table in the Oracle environment and ODBC connections are not allowed.
CREATE TABLE tbl_MyDataSource
(Customer char(50),
VIN char(50),
Year char(50),
Make char(50),
Odometer long,
InvDate date,
Amount currency)
Here is the 'insert into' to populate the tbl_MyDataSource table with four sample records.
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
SELECT "123", "321XYZ", "2012", "Honda", "1900", "2/15/2012", "987";
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("123", "432ABC", "2012", "Toyota", "2300", "1/10/2012", "6546");
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("456", "999PDQ", "2000", "Ford", "45586", "4/25/2002", "456");
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("876", "888QWE", "2010", "Mercedes", "38332", "10/13/2010", "15973");
Which should produce a table containing these columns with these values:
tbl_MyDataSource:
Customer VIN Year Make Odometer InvDate Amount
123 | 321XYZ | 2012 | Honda | 1900 | 2/15/2012 | 987.00
123 | 432ABC | 2012 | Toyota | 2300 | 1/10/2012 | 6,546.00
456 | 999PDQ | 2000 | Ford | 45586 | 4/25/2002 | 456.00
876 | 888QWE | 2010 | Mercedes | 38332 | 10/13/2010 | 15,973.00
The desired result is to use Oracle 9i to convert the columns into rows using sql without using any scripts if possible.
qsel_MyResults:
Column1 Column2 Column3 Column4 Column5
Customer | 123 | 123 | 456 | 876
VIN | 321XYZ | 432ABC | 999PDQ | 888QWE
Year | 2012 | 2012 | 2000 | 2010
Make | Honda | Toyota | Ford | Mercedes
Odometer | 1900 | 2300 | 45586 | 38332
InvDate | 2/15/2012 | 1/10/2012 | 4/25/2002 | 10/13/2010
Amount | 987.00 | 6,546.00 | 456.00 | 15,973.00
The syntax in SQL is something I am not yet sure of.
You said:
>
"Don't use the same name or alias for two different things. if you have a table called t, then don't use t as an alais for an in-line view. Pick a different name, like ordered_t, instead.">
but I'm not clear on which part of the SQL you are suggesting I change. The code I posted is something I pieced together from some of the other postings and is not something I full understand the syntax of.
Here is my latest (failed) attempt at this.
select *
from (select * from tbl_MyDataSource) t;
with data as
(select rownum rnum, t.* from (select * from t order by c1) ordered_t), -- changed 't' to 'ordered_t'
rows_to_have as
(select level rr from dual connect by level <= 7 -- number of columns in T
select rnum,
max(decode(rr, 1, c1)),
max(decode(rr, 2, c2)),
max(decode(rr, 3, c3)),
max(decode(rr, 4, c3)),
max(decode(rr, 5, c3)),
max(decode(rr, 6, c3)),
max(decode(rr, 7, c3)),
from data, rows_to_have
group by rnumIn the above code the "select * from tbl_MyDataSource" is a place holder for my select query which runs without error and has these exact number of fields and data types as order shown in the tbl_MyDataSource above.
This code produces the error 'ORA-00936: missing expression'. The error appears to be starting with the 'with data as' line if I am reading my PL/Sql window correctly. Everything above that row runs without error.
Thank you for your great patients and for sharing your considerable depth of knowledge. Any help is gratefully welcomed. -
Construct a Sql block using With Clause to improve the performance
I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
So I am trying to use the With Clause in order to club all those four Select Statements.
I would appreciate if anybody can help me to construct the Sql Block using With Clause.
My DB version is..
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
Four Diff cursors are defined below.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date;
CURSOR ewo_plant ( p_ewo_no IN IMPLMN_STEP_BREKPN.ewo_no%TYPE)
IS
SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no;
CURSOR iss_ewo_plnt (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);
CURSOR iss_ewo_plnt_count (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT COUNT(*)
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
select a.*,b.*,c.* from
( SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date) a,
( SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no) b,
( SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
plt_faclty_id IS NULL) c
where b.wo_no = c.ewo_no and
c.issue_id = a.issue_id ;
vinodh
Edited by: Vinodh2 on Jul 11, 2010 12:03 PM -
How to create dynamic HTML page using PL/SQL code in APEX.
hello,
I am woking on one APEX application in which i want to create one dynamic HTML page on button press using PL/SQL code.
ThanksIt is possible to create HTML page with dynamic content. One way would be creating hidden field (e.g. P1_HTML on page 1) with dynamic HTML and on button click you redirect to page 2 and pass P1_HTML item value to item P2_HTML on page 2. On page you must have PL/SQL region. You can then render your dynamic HTML with code:
htp.p(:P2_HTML);
Don use APEX URL for passing HTML value. Problem and solution is described here: http://blog.trent-schafer.com/2011/04/03/dont-pass-string-parameters-in-the-url-in-apex-its-a-bad-idea/
Edited by: MiroMas on 3.2.2012 3:20 -
How to edit a datagridview/textboxes using tableadapters in c# and sql
I am wondering what is the best way to edit a database that has multiple tables.
(Section 1) I have a Administration, Teacher and Student table that is linked up with the Person table which has a Primary Key.
The Person table consists of the general information of the person.
The Student table consists of information about the student; student ID and qualification code.
The Teacher table consists of information about the teacher; teacher ID, Reg No and password.
The Administration table consists of information about the admin; admin ID, Role and password.
As the Primary Key in the Person table is the ID, I have linked up with each of the other's table with their appropriate ID.
(Section 2) I have a Course and Qualification table that is linked up with the Student and Teacher table as well as each other.
The course table constists of the Course ID, Course Name ... and Teacher ID.
The Qualifications table consists of Qualification Code, Qualification Name and Duration.
There is a section where I have to create a view which shows just the Student ID, Course ID and has the Student's Marks in it.
I have got a combobox which then links up with the dgv(datagridview).
I have got insert and delete methods for both sections. Here is an example of the insert method into the Admin/Person table.
try
personTableAdapter.Insert(aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text);
administrationTableAdapter.Insert(Convert.ToInt32(aAID1.Text), aRole.Text, aPassword.Text);
MessageBox.Show(aFirstName.Text + " " + aSurname.Text + " has been added. Your ID is " + aAID1.Text);
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.administrationTableAdapter.Fill(this._30002195DataSet.Administration);
catch (Exception ex)
MessageBox.Show(ex.Message);
Here is an example of the delete method in the Admin/Person table.
try
personTableAdapter.Delete(Convert.ToInt32(aID.Text), aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text);
administrationTableAdapter.Delete(Convert.ToInt32(aAID.Text), aRole.Text, aPassword.Text);
MessageBox.Show("Person Deleted");
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.administrationTableAdapter.Fill(this._30002195DataSet.Administration);
catch (Exception)
MessageBox.Show("Cannot delete Person");
Those methods above are working fine, what I'm having problems with, is with the editing/updating part.
I have tried a few things and haven't worked.
Here's an example of an edit, while trying to use textboxes.
personTableAdapter.Update(aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text, Convert.ToInt32(aID.Text), aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text);
administrationTableAdapter.Update(aRole.Text, aPassword.Text, Convert.ToInt32(aAID.Text), aRole.Text, aPassword.Text);
personBindingSource.EndEdit();
administrationBindingSource.EndEdit();
administrationTableAdapter.Update(_30002195DataSet.Administration);
personTableAdapter.Update(_30002195DataSet.Person);
MessageBox.Show("Person Updated");
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.administrationTableAdapter.Fill(this._30002195DataSet.Administration);
Here I tried to do the new values/original values, while trying to use textboxes
personTableAdapter.Update(aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text, Convert.ToInt32(aID.Text), aFirstName.Text, aSurname.Text, Convert.ToDateTime(aDoB.Text), aPhone.Text, aAdd1.Text, aAdd2.Text, aSuburb.Text, aState.Text, aPostcode.Text, AdminType.Text);
administrationTableAdapter.Update(aRole.Text, aPassword.Text, Convert.ToInt32(aAID.Text), aRole.Text, aPassword.Text);
Trying to use the example through the mdsn, this is trying to use the datagridview.
this.Validate();
personBindingSource.EndEdit();
teacherBindingSource.EndEdit();
_30002195DataSet.PersonDataTable deletedPerson = (_30002195DataSet.PersonDataTable)
_30002195DataSet.Person.GetChanges(DataRowState.Deleted);
_30002195DataSet.PersonDataTable newPerson = (_30002195DataSet.PersonDataTable)
_30002195DataSet.Person.GetChanges(DataRowState.Added);
_30002195DataSet.PersonDataTable modifiedPerson = (_30002195DataSet.PersonDataTable)
_30002195DataSet.Person.GetChanges(DataRowState.Modified);
try
if (deletedPerson != null)
personTableAdapter.Update(deletedPerson);
teacherTableAdapter.Update(_30002195DataSet.Teacher);
if (newPerson != null)
personTableAdapter.Update(newPerson);
if (modifiedPerson != null)
personTableAdapter.Update(modifiedPerson);
_30002195DataSet.AcceptChanges();
catch (System.Exception ex)
MessageBox.Show(ex.Message);
finally
if (deletedPerson != null)
deletedPerson.Dispose();
if (newPerson != null)
newPerson.Dispose();
if (modifiedPerson != null)
modifiedPerson.Dispose();
MessageBox.Show("Updated");
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.teacherTableAdapter.Fill(this._30002195DataSet.Teacher);
Now because I am trying to edit a certain user which requires the Person table along with the other table, it just doesn't seem to work at all.
With the datagridview, I made a new view in the sql and it has both tables combined and shows when I bring it out from the datasource, but where I go into the dataset builder and try to create an update method, all I get is the "Update" not what
I would get when I created the update method from just the person's table by itself.
Can someone provide me with an example or help me out someway because I am struggling with this, I can't seem to find much information at all.
Thanks.I have used the designer to create a new datagridview, when using that dgv it doesn't want to update to the relevent tables in my database. So say you have the person and admin dgv together and you need to update it, how would you get it to work
to the database? I did just end up using 2 seperate dgv's but it won't get accepted.
try
_30002195DataSetTableAdapters.PersonTableAdapter personTableAdapter = new _30002195DataSetTableAdapters.PersonTableAdapter();
// person table
_30002195DataSetTableAdapters.AdministrationTableAdapter administrationTableAdapter = new _30002195DataSetTableAdapters.AdministrationTableAdapter();
// admin table
ViewSetTableAdapters.AdminViewTableAdapter adminviewTableAdapter = new ViewSetTableAdapters.AdminViewTableAdapter();
// tried using this for both the admin/person tables together but didn't work?
this.Validate();
adminViewBindingSource.EndEdit(); //both
personBindingSource.EndEdit();
administrationBindingSource.EndEdit();
personTableAdapter.Update(_30002195DataSet.Person);
administrationTableAdapter.Update(_30002195DataSet.Administration);
MessageBox.Show("Updated");
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.administrationTableAdapter.Fill(this._30002195DataSet.Administration);
catch (Exception ex)
MessageBox.Show(ex.Message);
So, how would I write the code so it edits both the tables from just the one dgv?
Hello,
Based on these words above, it seems that the key issue is that you want to display and edit the data of two tables with a single datagridview, right? If so, I am afraid that I would recommend you consider using code other than designer to get that done.
Are these table store in the same database?
If so, then you could consider getting that done with ADO.NET, we could getting the data of multiple table with sql query. You could consider
using sql query to get all data from multiple tables
of database, and then fill them to a single datatable.
For query issue, you could consider getting help from
Transact-SQL forum.
If not, then we need to create update query for both table and execute these queries with sperate connection strings.
Regards,
Carl
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to generate dynamic HTML pages using Swing Application?
Hello,
I am writing a Java application to connect to a local light-weight java database. I would like to generate and present a HTML on the fly after selecting records from a database. At server side, I could easily use JSP/Servlet to do this. How can I do this on a desktop client machine using Java application? I do not want to install Apache web server on the desktop machine. Any help will be greatly appreciated. Thanks in advance.
DominicThe way u need to generate your html pages depened on what u want to generate,
anyway what i can help with, is how to display a generated page.
u have to use JEditorPane with HTMLEditorKit and HTMLDocument to display any HTML.
also u can use the methods provided with the above objects to generate your html format.
I hope I helped. -
Studio 12.0, how to create dynamic sections to use in Workstation?
Hi,
I come from the 11.X world and I've worked mostly with Sections. I haven't worked with Paragraphs even in 11.X. I got a project coming up that requires 12.0 and want to get my feet wet by asking a question about how to construct what will need to be done.
This corr system will be working with Workstation. What I'm trying to do is allow the user to select from either a choice (A or B, Y or N), or a checkbox list (where they can pick more then one), and based on the selected choices, either one or many sections will populate the form and the user can interact with the newly appended sections.
What's the best way to go about this?
I'm looking at the "Documaker Studio User Guide, version 12.0", chapter 6. On page 252, "Creating Paragraph Lists", and this sounds like what I'll need to do. I would then click on the "Select One" checkbox when creating a multiline field to append these 'paragrahs' into.
Right now I'm just trying to get an early feel to what my options are as far as doing what I need. I feel I'm on the right track but was wondering if there are other options available.
thanks!Thank you Gaetan, I appreciate your response. One last question.
Pretend I have a ParagraphList with 4 paragraph choices. In two of those paragraph choices, I need each of them to have another 2 paragraph choices EACH.
So I know that you can't insert more MLT fields in paragraphs. Because of this, I don't think I'll be able to use PSL's and PAR's if I have multi level selections. Can anyone verify that this is correct? or am I missing something?
Since I will need a table selection for multiple sections, and those sections needs to be able to call additional tables for for more sections, I'm thinking TERSUB is probably my best bet. This could go on for three or so levels.
Any inputs? thanks. -
Can window and aggregate SQL functions used in Pro*C embedded SQL?
It appears that the window functions such as dense_rank() over(partition by ... order by ...) are not available in Pro*C embedded SQL. Can somebody please confirm that that is really the case?
Thanks
Rawender GuronPlease refer to this thread: "Is this forum also used for Pro*'C Questions? "
Is this forum also used for Pro*'C Questions? -
How to pass dynamically constructed string to where clause
select name from mytable
where l_condition
and sal=20;
l_condition is value coming from the function.
ex: l_condition is first_name='abc' and last_name='xyz' and first_name='def' and last_name='zef'Dynamic SQL can help in this case:
variable ref refcursor
DECLARE
l_condition VARCHAR2(1000) :=
' salary > 3000 and first_name like ''L%''';
BEGIN
OPEN :REF FOR
' SELECT first_name, salary FROM hr.employees ' ||
' WHERE ' || l_condition;
END;
print :ref;
FIRST_NAME SALARY
Laura 3630
Lindsey 8800
Lex 18700
Luis 7590
Louise 8250
Lisa 12650 -
PL/SQL function: using parameter of type PL/SQL record?
Hi,
Is it possible to call the following function from within c#:
CREATE FUNCTION myfunc (par1 table%ROWTYPE) RETURN <sometype>
IS ...
Can ODP.Net handle rowtype records? I have found no hints in the manuals.
thanks,
stephanHello Stephan,
Can ODP.Net handle rowtype records?ODP does not currently support %rowtype (or object) types.
PLSQLAssociativeArray is the only supported collection type at this time.
- Mark -
How to use database control to execute sql queries which change at run time
Hi all,
I need to execute sql queries using database controls , where the sql changes
at run time
based on some condition. For eg. based on the condition , I can add some where
condition.
Eg. sql = select id,name from emp where id = ?.
based on some condition , I can add the following condition .
and location = ?.
Have anybody had this kind of situation.
thanks,
sathishFrom the perspective of the database control, you've got two options:
1) use the sql: keyword to do parameter substitution. Your observation
about {foo} style sbustitution is correct -- this is like using a
PreparedStatement. To do substitution into the rest of the SQL
statement, you can use the {sql: foo} substitution syntax which was
undocumented in GA but is documented in SP2. Then, you can build up
the filter clause String yourself in a JPF / JWS / etc and pass it into
the DB control.
For example:
* @jc:sql statement="select * from product {sql: filter}"
public Product[] getProducts(String filter) throws SQLException;
This will substitute the String filter directly into the statement that
is executed. The filter string could be null, "", "WHERE ID=12345", etc.
2) you can use the DatabaseFilter object to build up a set of custom
sorts and filters and pass that object into the DB control method.
There have been other posts here about doing this, look for the subject
"DatabaseFilter example".
Hope that helps...
Eddie
Dan Hayes wrote:
"Sathish Venkatesan" <[email protected]> wrote:
Hi Maruthi,
The parameter substituion , I guess is used like setting the values for
prepared
statements.
What I'm trying to do , is change the sql at run time based on some condition.
For example ,
consider the following query :
select col1,col2 from table t where t.col3 > 1
At run time , based on some condition , I need to add one more and condition.
i.e. select col1,col2 from table t where t.col3 > 1 and t.col4 < 10.
This MAY not address your issue but if you are trying to add "optional" parameters
you may try including ALL the possible parameters in the SQL but send in null
for those params that you don't want to filter on in any particular case. Then,
if you word your query
as follows:
select col1, col2 from table t where t.col3 > 1 and (t.col4 = {col4param} or
{col4param} is null) and (t.col5 = {col5param} or {col5param} is null) ...
you will get "dynamic" filters. In other words, col4 and col5 will only be
filtered if you send in non-null parameters for those arguments.
I have not tried this in a WL Workshop database control but I've used
this strategy dozens of times in stored procedures or jdbc prepared statements.
Good luck,
Dan -
Dynamic sql versus static sql in a loop
I have a loop that loops around 10 million times.Inside the loop I have a insert statement . To build this insert statement wondering if a) I should use Dynamic sql using bind variables or b) static sql.
I am aware that static sql is always faster than dynamic sql(using bind variable)....but wanted to get some opinion
Please help.mmm some solution could be to write the same insert with decode/case statement and put there the conditions that you want.
maybe something like this:
SQL> ed
Wrote file afiedt.buf
1 begin
2 for i in 1..10 loop
3 insert into t1 (col1,col2,col3)
4 values (i,
5 decode (mod (i,2),0,i,null),
6 decode (mod (i,3),0,i,null));
7 end loop;
8* end;
SQL> /
PL/SQL procedure successfully completed.
SQL> select * from t1;
COL1 COL2 COL3
1
2 2
3 3
4 4
5
6 6 6
7
8 8
9 9
10 10
10 rows selected.
SQL> truncate table t1;
Table truncated.
SQL> insert into t1 (col1,col2,col3)
2 select rownum,
3 decode (mod (rownum,2),0,rownum,null),
4 decode (mod (rownum,3),0,rownum,null)
5 from dual
6 connect by rownum <=10;
10 rows created.
SQL> select * from t1;
COL1 COL2 COL3
1
2 2
3 3
4 4
5
6 6 6
7
8 8
9 9
10 10
10 rows selected.forgot that you are not using anymore the loop :)
Message was edited by:
Delfino Nunez -
I am not able to run a SQL query using where clause.
the query is as follows:
I extract the text input by the user in a text field say 'a' and
store it in string 'y'.
String y= a.getText();
//running the query
Select A from B where B.x=y;
how do we run a where clause when y is a string variable instead of value?Use the following :
String y = a.getText();
String query ="select A.CODE from Port A where A.NAME=" + "'" + y + "'" ;
ResultSet rs= stmt.executeQuery(query); -
Execute Dynamic SQL statement using procedure builder
i want to execute a dynamic SQL statment using procedure builder not using forms
because my statement depending on a variable table name
i know that i can do that from forms using
FORMS_DDL('SQL_STAT');
but i wanna to use the procedure builder
which function i should use and how?
please explain in example if you don't mind.
thanksHi,
You can very well use DBMS_SQL Package supplied by Oracle for doing this.
Search for DBMS_SQL in OTN. You will get all info regarding this.
Regards.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
i want to execute a dynamic SQL statment using procedure builder not using forms
because my statement depending on a variable table name
i know that i can do that from forms using
FORMS_DDL('SQL_STAT');
but i wanna to use the procedure builder
which function i should use and how?
please explain in example if you don't mind.
thanks<HR></BLOCKQUOTE>
null -
How to dynamically update columns in a where clause to a SQL query in OSB?
Hi Gurus,
I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
For example:
If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
Thanks in advance
SuryaI solved my problem.
In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
Thank you to who took some time to think about it.
Marc
Maybe you are looking for
-
Synced times in ical between iphone and Macbook not the same
I have tried syncing my ical to my iphone using itunes and the times on my iphone are not the same as my ical. for example 1.30 pm for an appointment in my ical reads as 4.00am and the next day on my iphone calendar. How do I fix this?
-
AS 2.0 Control Movie Via Dragable Clip
I was trying to see if I could get a scrubber-like button to control movie playback. For instance I want to place button that you can drag along a bar to move the movie along frame by frame. I think I have seen this done somewhere but I was wondering
-
One month ago, my macpro start to work to slow, some apps it not working well. I already use the test hardware and software of apple. the results is the mac pro don´t have any problem. But still working slow and when i open a program or app the mac s
-
Adobe Download Assistant Issues
Im trying to download Light room trial and download assistant freezes when i try to log in. Ive set the permissions uninstalled and reinstalled adobe air and assitant manager... What can be done? Also when i uninstall it, i get: Warning 1910. Could n
-
Oracle SQL Developer에서 CVS사용자를 한글로 하였을 경우 접속오류
Oracle SQL Developer Version 1.5.1 사용환경 : 클라이언트 Windows XP, CVS 서버 Windows2003 CVS 영문으로 등록된 사용자를 설정하면 정상적으로 작동이 되지만 한글 사용자를 등록하는 경우 Test Connection에서 암호가 맞으면 상태창에 다음과 같은 내용이 나오고 Testing connection... Connection test failed: could not authenticate use