Preparing Dynamic SQL statement for inserting in Pro*C
Hi Friends,
From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
Can somebody go through my code and suggest me the rigth way of doing.
Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
Please help me.
Girish.
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *uid ="scott/tiger";
static char sqlstmt[129];
struct /* DEPT record */
int dept_num;
char dept_name[15];
char location[14];
} dept_rec;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL CONNECT :uid;
dept_rec.dept_num = 50;
strcpy(dept_rec.dept_name,"ADMIN");
strcpy(dept_rec.location,"IN");
strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
EXEC SQL COMMIT;
exit(0);
void sql_error()
printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK;
}
A bit rusty here but this is how I see it.
Think of it this way ..
all Oracle is going to see is:
UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
it doesnt go back and fill in those values.
You need something like
strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
strcat(sqlstmt,dept_rec.dept_name);
strcat(sqlstmt,"\" where DEPTNO = ");
strcat(sqlstmt,dept_rec.dept_num);
printf(sqlsmt); # Just to be sure the update statement look right during testing.
Similar Messages
-
TopLink does not generate SQL statements for inserting new objects
TopLink does not generate SQL statements for inserting new objects. Why?
Thanks in advance...Please see the response in
Why does not unitofwork.commit write data to the database?
Regards,
Chris -
Problem with SQL Statement for Result Filtering
Dear Visual Composer Experts,
Here is another Question from me: I have a SQL Query that is working as the data service
Select AB.AgingBandID, AB.AgingBand,
Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],
Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,
Sum(Case when priority='High' then '1' Else 0 End) as High,
Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,
Sum(Case when priority='Low' then '1' Else 0 End) as Low
from DimAgingBand AB left outer join
(Select AgingBandID , priority , yeardesc
from vNotifications where YearDesc = (select year(getdate())-1)) as vN
on AB.AgingBandID=vN.AgingBandID
where AB.AgingBandID<>'1'
Group by AB.AgingBandID, AB.AgingBand
Order by AB.AgingBandID
That would return me a table as in the following:
Agingband E U H M L
< 1week 0 0 0 0 1
1 - 2 weeks 0 0 0 0 0
2 - 4weeks 0 0 0 0 1
> 1month 8 2 1 1 6
Now that I would like to add some parameters to filter the result, so I modify the query and put it in the SQL Statement input port of the same data service. The query is like this:
"Select AB.AgingBandID, AB.AgingBand,Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,Sum(Case when priority='High' then '1' Else 0 End) as High,Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,Sum(Case when priority='Low' then '1' Else 0 End) as Low from DimAgingBand AB left outer join (Select AgingBandID , priority , yeardesc from vNotifications where YearDesc like '2009%' and Branch like '" & if(STORE@selectedBranch=='ALL', '%', STORE@selectedBranch) & "' and MainWorkCentre like '%') as vN on AB.AgingBandID=vN.AgingBandID where AB.AgingBandID<>'1' Group by AB.AgingBandID, AB.AgingBand Order by AB.AgingBandID"
However this input port query keeps giving me error as NullPointerException. I have actually specified a condition where the query will run if only STORE@selectedBranch != u2018u2019.
I have other filtering queries working but they are not as complicated query as this one. Could it be possible that query in the input port cannot handle left outer join?
Could it be anything else?
Help is very much appreciated.
Thanks & Regard,
SarahHi,
Thank you very much for your replys. I've tested if the dynamic value of the condition is integer, it's OK
But if the ClassID type is not integer, it's string, I write a SQL Statement like:
"Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '1' "
or with dynamic condition:
"Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '"&@ClassID&"'"
or I write the SQL Statement for insert/update/delete data,
I always have errors.
I've tested if the dynamic value of the condition is integer, it's OK
Do you know this problem ?
Thank you very much & kindly regards,
Tweety -
Proxy to JDBC scenario need dynamic sql query for sender .
Hi Experts,
I am developing proxy to jdbc scenario. in this i need to pass dynamic sql query whre we are passing classical method like below.
while we are passing select stmt in constant and mapped with access field and key field mapped with key field.
MY requirement is like instead of passing select stmt in constant where i can generate dynamically and passed in one field and mapped with access field.Hi Ravinder,
A simple UDF or use of graphical mapping functions in most cases should provide you everything you need to construct a dynamic SQL statement for your requirement.
Regards,
Ryan Crosby -
Concatenate problem for Dynamic SQL statements
Hi Experts ,
I am building Dynamic SQL statements depending on the values which the user enters into the select option parameters .This dynamic query is passed to cl_sql_connection object for querying from another databasse
So i wrote dynamic values for one select option spointof for the database field ppointofdelivery.
loop at spointof.
CONCATENATE ' pointofdelivery between ''' spointof-low''''
' AND ''' spointof-high''''
INTO where_clause .
endloop.
The whereclause has value pointofdelivery between '123' and '124'.(if the user has entered 123 and 124 as values)
This works fine . But my problem is I have to pass the fieldnames and operator dynamically into where_clause depending on User input.
when i am writing code like the below
field_name = ' pointofdelivery '.
operator = '='.
CONCATENATE field_name operator '''spointof-low''' INTO where_clause .
the where_clause contains value
pointofdelivery = ' spointof-low '
and not pointofdelivery = ' 123 ' as expected .
Do you know why this is haapening as it is not taking the value.
Thanks
ArshadHi,
there are lot of function modules..available...to build a where clause based on the select-options..
check the FM FREE_SELECTIONS_RANGE_2_WHERE
Thanks
Naren -
How can I open a cursor for dynamic sql statement
Hi,
I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
CREATE OR REPLACE FUNCTION DEMO
(MN_I in VARCHAR)
return AB_OWNER.ABC_Type.NonCurTyp is
RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
sql_stmt VARCHAR2(4000);
BEGIN
sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
OPEN RESULT1 FOR sql_stmt;
END IF;
return RESULT1;
END DEMO;
What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.Gangadhar Reddy wrote:
I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
Because this is what will happen when it runs a lot.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
Flushing Shared Pool regularly
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
>
Ok, this is an easy one to diagnose.
You are not using bind variables. This is terrible. Flushing the shared pool is a bad
solution -- you are literally killing the performance on your box by not using them.
If I was to write a book on how to build non scalable applications in Oracle, this
would be the first and last chapter. This is a major cause of performance issues and a
major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
important shared memory data structure) operates is predicated on developers using bind
variables. If you want to make Oracle run slowly, even grind to a total halt just
refuse to use them.
>
But, please feel free to go ahead with this successful implementation.
I just hope anyone else who reads this doesn't make the same mistake. -
Dynamic SQL with cursor variables in pro*c
Please, what I need to do in order to be able
to do something like this:
EXEC SQL DECLARE :c CURSOR FOR :s;
In other words: I want to use variables
in cursor names.
Is it possible ? How ?
Thank you.OK. Here is an example of a Dynamic SQL #4 program I wrote several years ago (It's still running in production). It is currently running on a Sun E10K with Oracle 8.1.5. This code is JUST the pro*c part of a program which uses IBM MQ Series. MQ passes this program a Select SQL statement (as well as other parameters) as an argument. The Pro*c code allocates the structures, parses, and fetches, and executes the statement. I realize that this will not be easy to read. There are SOME comments in the code. However, I realize that to read anyone elses code is a chore. When you add Dynamic #4 to the list, it becomes much more complicated. Anyway, you'll probably need to copy and paste the code to a text file. It will be easier to read.
==========================================
Code
==========================================
| Program: mqsql.pc |
| Creator: Jim Wartnick |
| Purpose: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| XXXXXXXXXXX |
| Date: 01/03/1997 |
| Modifications: |
#include"mqsql.h"
#define DEBUG
#ifdef DEBUG
FILE *fp=stdout;
#endif
int
disconnect_db() {
char msg[256], oraclmsg[256];
char buf[MAX_STRING_LENGTH+4];
int buf_len = 0, msg_len = 0;
EXEC SQL
COMMIT WORK RELEASE;
#ifdef DEBUG
fprintf(fp, " --> Disconnecting from database. RC: %d.\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
error("disconnect_db()", "disconnect", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
connect_db() {
char msg[256], oraclmsg[256];
char buf[MAX_STRING_LENGTH+4];
int buf_len = 0, msg_len = 0;
char user[4];
strcpy(user, "/");
EXEC SQL
CONNECT :user;
#ifdef DEBUG
fprintf(fp, " --> Connecting to database. RC is %d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
sprintf(Results, "%9d", sqlca.sqlcode);
error("connect_db()", "connect", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
allocate_sqlda() {
| Initialize the SQLDA structure. |
| We only need the select descriptor |
| because we do not have any bind |
| variables. |
if ((Select_da = sqlald(
MAX_COLUMN_COUNT,
MAX_COLUMN_STRING_LENGTH,
MAX_INDICATOR_VARS
)) == (SQLDA *) 0) {
#ifdef DEBUG
fprintf(fp, " Memory allocation for Select Descriptor failed.\n");
fflush(fp);
#endif
strcpy(Results, "000000001");
error("allocate_sqlda()", "create SQLDA", 0, "Memory Error");
return(FAILURE);
#ifdef DEBUG
fprintf(fp, " Memory allocation for Select Descriptor succeeded.\n");
fflush(fp);
#endif
Select_da->N = MAX_COLUMN_COUNT;
return(SUCCESS);
int
prepare_sql() {
char msg[256], oraclmsg[256];
int buf_len = 0, msg_len = 0;
| Prepare the Sql statement. |
EXEC SQL
PREPARE sql_stmt
FROM :Sql;
#ifdef DEBUG
fprintf(fp, " Prepared SQL: %s. RC: %d.\n", Sql, sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
sprintf(Results, "%9d", sqlca.sqlcode);
error("prepare_sql()", "Parse", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
declare_cursor() {
char msg[256], oraclmsg[256];
int buf_len = 0, msg_len = 0;
| Set up the cursor to loop through |
EXEC SQL
DECLARE sql_cursor
CURSOR FOR sql_stmt;
#ifdef DEBUG
fprintf(fp, " Declared cursor. RC: %d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof( oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
sprintf(Results, "%9d", sqlca.sqlcode);
error("declare_cursor()", "declare cursor", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
open_cursor() {
char msg[256], oraclmsg[256];
int buf_len = 0, msg_len = 0;
| Open the cursor. |
EXEC SQL
OPEN sql_cursor;
#ifdef DEBUG
fprintf(fp, " Opened cursor. RC:%d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
sprintf(Results, "%9d", sqlca.sqlcode);
error("open_cursor()", "open cursor", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
describe_select_list() {
char msg[256], oraclmsg[256];
int buf_len = 0, msg_len = 0;
| Get description of columns |
EXEC SQL
DESCRIBE SELECT LIST FOR sql_stmt
INTO Select_da;
#ifdef DEBUG
fprintf(fp, " Described columns. RC %d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
sprintf(Results, "%9d", sqlca.sqlcode);
error("describe_select_list()", "describe select list", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
setup_sqlda() {
char buf[MAX_STRING_LENGTH+4];
int done = FALSE, nullok = 0, i = 0;
#ifdef DEBUG
fprintf(fp, " --> Setting up SQLDA.\n");
fflush(fp);
#endif
if (allocate_sqlda() == FAILURE)
return(FAILURE);
if (prepare_sql() == FAILURE)
return(FAILURE);
if (declare_cursor() == FAILURE)
return(FAILURE);
if (open_cursor() == FAILURE)
return(FAILURE);
if (describe_select_list() == FAILURE)
return(FAILURE);
| Too many columns in select list. |
if (Select_da->F < 0) {
strcpy(Results, "000000001");
error("setup_sqlda()", "check select list count", 0, "Too many values in select list");
return(FAILURE);
| Set the number of columns to the actual |
| number of columns. |
Select_da->N = Select_da->F;
| We are going to convert all fields to a string. |
for (i == 0; i < Select_da->F; i++) {
sqlnul(&(Select_da->T), &(Select_da->T[i]), &nullok);
Select_da->T[i] = EXT_STRING;
Select_da->L[i] = MAX_STRING_LENGTH;
| Allocate the result area to be as big as |
| MAX_STRING_LENGTH. |
if ((Select_da->V[i] = malloc(Select_da->L[i])) == NULL) {
#ifdef DEBUG
fprintf(fp, " Allocation of column values failed.\n");
fflush(fp);
#endif
strcpy(Results, "000000001");
error("setup_sqlda()", "allocate column values", 0, "Memory Error");
return(FAILURE);
if ((Select_da->I[i] = (short *) malloc(sizeof(short))) == NULL) {
#ifdef DEBUG
fprintf(fp, " Allocation of idicator values failed.\n");
fflush(fp);
#endif
strcpy(Results, "000000001");
error("setup_sqlda()", "allocate indicator values", 0, "Memory Error");
return(FAILURE);
#ifdef DEBUG
fprintf(fp, " Allocation of memory for values succeeded.\n");
fflush(fp);
#endif
return(SUCCESS);
| add_eom adds the end of message |
| delimiter (an aditional comma). |
int
add_eom() {
char *result_ptr;
if (strlen(Results) >= sizeof(Results) - 1) {
strcpy(Results, "000000001");
error("add_eom()", "Add eom failed. Size overflow", 0, "Memory Error");
return(FAILURE);
result_ptr = &Results[strlen(Results)-1];
while (*result_ptr && (*result_ptr != ','))
result_ptr--;
if (*result_ptr) {
result_ptr++;
*(result_ptr++) = ',';
*result_ptr = '\0';
return(SUCCESS);
int close_cursor() {
char msg[256], oraclmsg[256];
int buf_len = 0, msg_len = 0;
| Close the cursor. |
EXEC SQL
CLOSE sql_cursor;
#ifdef DEBUG
fprintf(fp, " Closing cursor. RC: %d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
error("generate_sql()", "close cursor", sqlca.sqlcode, oraclmsg);
return(FAILURE);
return(SUCCESS);
int
fetch() {
char msg[256], oraclmsg[256];
char buf[MAX_STRING_LENGTH+4];
int buf_len = 0, msg_len = 0;
EXEC SQL
FETCH sql_cursor
USING DESCRIPTOR Select_da;
#ifdef DEBUG
fprintf(fp, " --> Fetching rows. RC %d\n", sqlca.sqlcode);
fflush(fp);
#endif
if (sqlca.sqlcode != 0) {
if (sqlca.sqlcode != NODATAFOUND) {
buf_len = sizeof(oraclmsg)-1;
sqlglm(oraclmsg, &buf_len, &msg_len);
oraclmsg[msg_len] = '\0';
error("fetch()", "Error fetching row.", sqlca.sqlcode, oraclmsg);
return(sqlca.sqlcode);
return(NODATAFOUND);
return(SUCCESS);
| Free up any memory structures. |
void
free_memory() {
int i = 0;
for (i = 0; i < Select_da->F; i++) {
free(Select_da->V[i]);
free(Select_da->I[i]);
| generate_sql() uses the message we received from the queue |
| (a SQL statement) to query the database. We have to use |
| dynamic Sql Version 4 for this type of Sql. The number of |
| columns we are selecting is unknown. This means we can't |
| use the INTO clause. |
int
generate_sql() {
char buf[MAX_STRING_LENGTH+4];
int rc = SUCCESS, done = FALSE, nullok = 0, i = 0;
#ifdef DEBUG
if ((fp = fopen(SQLLOG, "a")) == NULL)
fp = stderr;
#endif
| Connect to the database |
if (connect_db() == FAILURE)
return(FAILURE);
if (setup_sqlda() == FAILURE)
return(FAILURE);
| Place the answer in a comma delimited buffer. |
memset(Results, NULL, sizeof(Results));
done = FALSE;
while (!done) {
rc = fetch();
if (rc != SUCCESS) {
if (Results[0] == '\0')
sprintf(Results, "%9d,", rc);
done = TRUE;
else {
| Put return code of success in first. |
if (Results[0] == '\0')
strcpy(Results, "000000000,");
for (i = 0; i < Select_da->F; i++) {
Select_da->V[i][Select_da->L[i]] = '\0';
| Check to see if the value is null. |
if (*Select_da->I[i] < 0)
strcpy(buf, " ,");
else
sprintf(buf, "%s,", Select_da->V[i]);
if (strlen(Results) + strlen(buf) > sizeof(Results)) {
strcpy(Results, "000000001");
error("generate_sql()", "String concat failed. Size overflow", 0, "Memory Error");
return(FAILURE);
strcat(Results, buf);
#ifdef DEBUG
fprintf(fp, " --> Results %s\n", Results);
fflush(fp);
#endif
| Close the cursor. |
close_cursor();
| Disconnect from the database |
disconnect_db();
| Remove trailing comma. |
if (add_eom() == FAILURE)
return(FAILURE);
#ifdef DEBUG
fflush(fp);
#endif
free_memory();
#ifdef DEBUG
fclose(fp);
#endif
null -
How can I execute Dynamic SQL statement in Forms?
Hi All,
I have to execute dynamic SQL statement from Forms
Below statement I have to execute
"EXECUTE IMMEDIATE v_stmt INTO v_return;".
Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
Can any one help me..
Thanks,
MadhuSo in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
cheers -
Nested SQL statements for complex, detailed queries.
Is it possible to write nested SQL statements for complex, detailed queries. A nested query
has a WHERE clause that includes a SELECT statement ? Is it true or false ?Hi wahid,
Here are pretty good examples:
http://www.databasejournal.com/features/mssql/article.php/3464481/Using-a-Subquery-in-a-T-SQL-Statement.htm
http://technet.microsoft.com/en-us/library/aa213252(v=sql.80).aspx
Regards Harsh -
Help With SUBSTR in dynamic SQL statement
Following is the dynamic SQL statement.
EXECUTE IMMEDIATE 'UPDATE table_name pml
SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
(SELECT pml1.'||con_fields.field||'
FROM table_name pml1
WHERE pml1.grp_id = '||los_concats.grp_id ||'
AND pml1.row_id = '||los_concats.row_id||'
AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
WHERE pml.grp_id = '||los_concats.grp_id ||'
AND pml.loser_flg IS NULL ';
what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
ORA-00907: missing right parenthesis.
Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
Appreciate it.The other alternative I thought about was to do this first
EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
FROM table_name pml
WHERE pml.grp_id = '||los_concats.grp_id||'
AND pml.row_id = '||los_concats.row_id||'
AND pml.loser_flg = ''Y''
' INTO v_concat_field;
write into the variable v_concat_field and then use it into the previous script.
But on this I get SQL Command not properly terminated, I don't get it Why?
Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
Thanks -
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
Need SQL statement for this logic....
Hi,
I want a SQL statement for updating the following changed last number .
Cuurently its:
SELECT * FROM TEST;
LAST NUMBER CHANGED LAST NUMBER
123518
12355265
123674659
9087648970
After updating with the required SQL statement table should look like
LAST NUMBER CHANGED LAST NUMBER
123518 0000123518
12355265 0012355265
123674659 0123674659
9087648970 9087648970
the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
Appreciate your help.
Thanks in advance
Devenderselect last_number, lpad(to_char(last_number), 10 , '0') FROM test
-
APP-ALR-04106: Please correct the user-defined SQL statement for this alert
Hi All,
I have created an alert for engineering module in R12. It got tested and was working fine. when the user testing it, while trigger the alert getting the error, "APP-ALR-04106: Please correct the user-defined SQL statement for this alert".
when verified the alert, it got verified and ran also. It parsed the query successfully and when run it fetched few records.
Need help in resolving the issue.
Thanks in advance.
Regards,
sri
Edited by: user10939296 on Jan 18, 2010 1:16 AMHi Sri;
I have already gone through the Note: 948037.1. But this note is related to 11i. The solution provided in the Note is for 11i.
I am facing this issue in R12. Is this patch applicable to R12?I belive its not. But u can check Solution part 4 for your instance, at least it can give you idea. The other note in metalink related bug and all for R11 too.
I belive its better way to rise Sr while waiting other forum user response to that thread
Regard
Helios -
SQL statement for calculating performance targets
Hi
I have taken of the admin of a database which stores project goals and scores. I have to develop a way to calculate how well all projects meet these scores. The table concerned is called goal and looks like this:
goal
goal_name
project_code
current_value
good_value
bad_value
This can be for many different goals, for example if a project wants to get up a goal of having no more than 5 bugs in the project. I can also set a bad value, say 20, so if any projects have 20 or more bugs, triggers or alerts can be sent So I can enter into this table. The reason for putting 5 for good not 20 is because these scores are to be realistic.
project_code = foo
goal_name = software bugs
good_value = 5
bad_value = 20
However, some goals may have the values switched and be in a much higher range, or may even be a percentage. For example one for number of sales could be
project_code = foo
goal_name = software sales
good_value = 200
bad_value = 50
or project delay
project_code = foo
goal_name = sproject delay
good_value = 0%
bad_value = 50%
i am trying to develop a SQL statement so I can get a % score of how well a goal is performing, so I can see
What is the goal % for all foo goals
Or what is the goal % for goal 'software sales'
And also more importantly, how well are the goals doing globally.
The requirement for doing this is using a single SQL statement, well, one SQL statement for the requirements I listed above, so for example the semantics are
SELECT average(goal perforance) WHERE .... project = foo .... or goal = software sales... etc
I am having trouble doing this, I have been banging my head against mydesk all day. the biggest thing is thowing me off is that the good value can be higher or lower than the bad value, and I am having trouble visualizing how to but this conditional statement in SQL
One more thing, the percentage returned should never be more than 0% or 100%.
If anyone has any ideas or pointers, please help me out,
Thanks for your time,
Message was edited by:
user473327I am having trouble doing this, I have been banging
my head against mydesk all day. the biggest thing is
thowing me off is that the good value can be higher
or lower than the bad value, and I am having trouble
visualizing how to but this conditional statement in
SQLI haven't looked at your requirements in detail cos I don't have time for such cumbersome tasks. However, you could have two UNION'd select statements, one which caters for the good > bad and one which caters for the good < bad. Also and alternative would be the use of DECODE or CASE statements in your select which are good for switching things around based on conditions.
;) -
Sql statement for network version of JavaDB database
Hi,
Could somebody please tell is it a must to have double quote for field name inside the SQL statement for JavaDB
I am developing the project using netbean 5.5.1 IDE
integrating netwok version of JavaDB.
example
select "field1","field2" from table1
instead of the simple sql like
select field1,field2 from table1
I find that simple select sql query could not work without having the double quotation eclosed for any of the fieldname called by the SQL statement.
I am not sure is it only unique to netbeans IDE environment , in principle simple plain query should work , this is however not for netbeans IDE, wht is the reason behind?
ThanksThe Quotes around the fieldnames are normally only needed if the field is the same as a reserved word, or has a non-standard character in the field. Look at the JavaDB/Derby manual (specifically the one with the SQL reference) to find out what the reserved words and special characters are, then redefine your table.
Maybe you are looking for
-
Complete on Exit not working with publish to SCORM
I am trying to launch a captivate project straight through our LMS, I have published it as a SCORM compliant file, and used the manifest file as well. I am able to launch the project, and the resume on exit works, however I cannot get the last page t
-
.INDD files not showing cs4 icon
...after an hour on the phone with tech support..I'm turning to the masses. I've right clicked the file/prop/to change the program to open the file type with. Indesign CS4 is not on my program list. When I select browse/program/adobe/indesign cs4 an
-
I can't modify the field MARC-LOSGR using the badi BADI_MATERIAL_REF
Hello! I have to force a value in the field "lot size" (MARC-LOSGR) when the system extends automatically a material with the transaction CK40N. I tried to use the badi BADI_MATERIAL_REF, wich seems to be perfect for this purpose, but it doesn't work
-
Iphone keeps asking me for my AppleID password
My iPhone keeps asking me for my AppleID password. This usually happens after I wake the phone and/or start any app. The problem is intermittent (and too consistant that it has become very annoying!) This started happening about 1.5 weeks ago. I ca
-
Acrobat Reader XI crashes in 2nd account (eula)
I installed Acrobat Reader XI on windows 7 on a machine with 2 accounts. It worked as expected in the 1st account, but the 2nd account could not start it. The accept license window did not appear. The event list of Win7 showed, Eula.exe of AcrobatRea