SQL statement inside a SQL statement
Hello,
I'm trying to write a SQL statement to a field in a table ( so that i can store some sql statements in a table) For the most part this code works fine (where string1 is the statement):
updatestring1 = "update [@SQLSTATEMENTS] set [U_statement] = '" & qstring1.ToString & "' where [Code] = " & row
oRecordSet.DoQuery(updatestring1)
but when the statement that i want to save contains a WHERE clause that refernces a string (enclosed by single quotes), the update query fails - because of the quotes i think.
I'm thinking i might be able to use different symbols in the statement to signify that it is a string but i'm not sure...
Is there a better way to write the query to a field in a table ? maybe one that doesn't require an update query ? I'm pretty new to SDK (and SQL), so any advice will help - even if it's something really obvious...
Thanks!
I am not sure why you need to save SQL queries in the table but, you need to follow up a single quote with another single quote. for example look at the following sql string
update customer set custname = 'Customer'' A' where custid = 'CustA'
'IS correct
However the following will fail
update customer set custname = 'Customer' A' where custid = 'CustA'
Message was edited by: Indika Dekumpitiya
Similar Messages
-
Select statements inside a SQL Expression field
Hello
Why cannot we use the Select statements inside a SQL expression field in Crystal Reports ?
Any alternatives for this...
SELECT Top(1) "SomePrivateDatabase"."SPDname" FROM "SomePrivateDatabase"
inner join "Subscriber" on
"Subscriber"."SPDID" = "SomePrivateDatabase"."SPDID"
inner join "UserDetails" on
"UserDetails"."SPDID" = "SubscriberCore"."SPDID"
Regards
Srivatsa
Edited by: Srivatsa Haridas on Dec 3, 2008 12:17 PMHi Srivatsa,
SQL Expressions is something the Database supports. We query the Client engine for a list of functions they make available. If the SQL Statement is not list it's not an option and therefore it won't work.
Your work arounds are to use either a Stored Procedure, this is the most efficient way, all processing is done server side and CR simply waits for the data to format in the report. Another option is to use a
Command Object, use one CO per report so try to get all data within the SQL statement. We simply pass the SQL to the server and wait for the result set, if you get an error it will be the SQL you typed in. Test in a SQL test tool first to confirm you are getting the data correctly.
For more assistance in designing reports please post your report deisgn questions to the Reprot Design forums. I am moving this one to that queue.
Thank you
Don -
Decode Statement Inside the Case statement
Can we use Decode Statement inside a CASE Statement as show below --
It is giving an error -- Is the a better way to write with out any error
create or replace
function test (a varchar2) RETURN VARCHAR2
is
m varchar2(20);
begin
m :=
CASE
WHEN a IN (
'1009' -- (soon obsolete)
,'1010'
,'1019'
,'1051'
,'XGP'
,'XSC')
THEN (SELECT DECODE(v_lef_cd,'NAM','71','GLB','99','01') into m FROM DUAL)
-- ) THEN '01' -- UNITED STATES OF AMERICA
WHEN a IN (
'1069' -- South Africa
,'SAO' -- South Africa
,'SA' -- South Africa
) THEN '26' -- South Africa
ELSE NULL
END;
return m;
end;Hi,
You can only use DECODE in SQL statements.
Your SELECT DECODE (...) INTO statement would work anywhere a PL/SQL statement is allowed; but PL/SQL statements are not allowed within CASE expressions.
Remember, the expression that comes after THEN in a CASE expression must be a single value.
I would write a function like this using IF ... ELSIF statements. It's a little more typing than CASE, but a lot easier to code, test and maintain.
If you want to use CASE, here's one way:
... m := CASE
WHEN a IN ('1069', 'SAO', 'SA')
THEN '26' -- South Africa
WHEN a NOT IN ('1009', '1019', '1051', 'XGP', 'XSC')
OR a IS NULL
THEN NULL
WHEN v_lef_cd = 'NAM'
THEN '71'
WHEN v_lef_cd = 'GLB'
THEN '99'
ELSE '01' -- USA
END;This assumes that you have a variable v_lef_cd defined.
If you want, you can nest CASE expressions, like this:
... m := CASE
WHEN a IN ('1069', 'SAO', 'SA')
THEN '26' -- South Africa
WHEN a IN ('1009', '1019', '1051', 'XGP', 'XSC')
THEN CASE v_lef_cd
WHEN 'NAM'
THEN '71'
WHEN 'GLB'
THEN '99'
ELSE '01' -- USA
END
END;Always format your code, so you can see where the CASE expressions and each of the WHEN clauses begin and end.
When posting formatted text on this site, type these 6 characters:
(all small letters, inside curly brackets) before and after sections of formatted text, to preserve spacing. -
Select Statement inside the insert statement
I need to insert the values into nav_pending by selecting the values from nav table
when i write this code its giving missing expression error
Can i know what is the problem??
can i use select inside insert in oracle????
INSERT INTO NAV_PENDING (ACCOUNT_NUM,PERIOD_DTE)
VALUES
SELECT ACCOUNT_NUM,PERIOD_DTE
FROM NAV where ACCOUNT_NUM=1;
Thanks in advanceLeave the values keyword
INSERT INTO NAV_PENDING (ACCOUNT_NUM,PERIOD_DTE)
SELECT ACCOUNT_NUM,PERIOD_DTE
FROM NAV where ACCOUNT_NUM=1; -
Select statement inside a select statement is not working as thought it would.
Hi all,
I have problem in the following programming code:
SELECT ACCT_FD_NO,ACCT_CUST_CODE, STAUS, FDR_STAUS, AMOUNT,INT_RATE ,MATURITY_DATE,(AMOUNT*(INT_RATE/100)/365)no_of_days,
(AMOUNT*(INT_RATE/100)/365)*((TO_DATE(:X_PRM_ST_DT)-TO_DATE(:X_PRM_YR_END_DT)))tot_int FROM KEC_FDACCT_MSTR
WHERE acct_type NOT IN(1,2,3,4,5,6,13,14,15,16,17,18,25,26,27,28,29,30) AND FDR_STAUS='R' AND STAUS='E'
AND ACCT_OPN_DT>:X_PRM_YR_END_DT
AND ACCT_FD_NO IN(SELECT OLD_FDR_NO FROM KEC_FDACCT_MSTR WHERE FDR_STAUS='R' AND acct_type NOT IN(1,2,3,4,5,6,13,14,15,16,17,18,25,26,27,28,29,30)
AND ACCT_OPN_DT>:X_PRM_YR_END_DT);
The following is the Table KEC_FDACCT_MSTR with the columns shown with data.
ACCT_FD_NO
ACCT_CUST_CODE
ACCT_TYPE
ACCT_OPN_DT
FDR_STAUS
STAUS
AMOUNT
INT_RATE
GROUP_TYPE
OLD_FDR_NO
MATURITY_DATE
250289
3
25
07/12/2012
R
E
140,000.00
11.50
12MNS
60002
06/12/2013
250290
3
25
07/12/2012
R
E
140,000.00
11.50
12MNS
60001
06/12/2013
270968
4
27
14/07/2013
M
E
450,000.00
12.50
36MNS
30227
13/07/2016
330516
9
33
08/12/2012
R
E
50,000.00
12.50
36MNS
90001
07/12/2015
320217
11
32
08/12/2012
R
E
50,000.00
12.00
24MNS
90002
07/12/2014
330513
12
33
08/12/2012
R
E
100,000.00
12.50
36MNS
90003
07/12/2015
360017
13
36
01/12/2012
R
E
50,000.00
12.50
36MSH
120002
30/11/2015
360018
15
36
05/12/2012
R
E
100,000.00
12.50
36MSH
120004
04/12/2015
270743
22
27
09/12/2012
R
E
50,000.00
12.50
36MNS
30004
08/12/2015
270744
22
27
09/01/2013
R
E
200,000.00
12.50
36MNS
30112
08/01/2016
270316
25
27
07/12/2012
R
E
70,000.00
12.50
36MNS
30007
06/12/2015
360019
29
36
05/12/2012
R
E
100,000.00
12.50This is the table on which i'm writing the code:
ACCT_FD_NO
ACCT_CUST_CODE
ACCT_OPN_DT
FDR_STAUS
STAUS
AMOUNT
INT_RATE
OLD_FDR_NO
SAP_CODE
MATURITY_DATE
350001
743
17-Nov-10
M
D
200000
12.00
323055
16-Nov-12
350002
734
18-Nov-10
R
D
300000
12.00
100018
323055
17-Nov-12
350003
736
19-Nov-10
R
D
150000
12.00
100015
323055
18-Nov-12
350004
737
20-Nov-10
R
D
500000
12.00
100016
323055
19-Nov-12
350005
735
19-Nov-10
M
D
150000
12.00
323055
18-Nov-12
350006
738
20-Nov-10
M
D
1500000
12.00
323055
19-Nov-12
350007
734
19-Nov-10
R
D
200000
12.00
100013
323055
18-Nov-12
350008
83
30-Nov-10
M
D
50000
12.00
323055
29-Nov-12
350009
136
12-Dec-10
R
D
200000
12.00
100006
323055
11-Dec-12
350010
716
12-Nov-11
M
D
200000
12.00
323055
11-Nov-13
350011
746
16-Nov-12
R
E
200000
12.00
120054
323055
15-Nov-14
350012
731
13-Nov-12
R
E
400000
12.00
290001
323055
12-Nov-14
350013
3,906
10-Sep-13
N
E
100000
12.00
323055
9-Sep-15
350014
3,907
18-Sep-13
N
E
50000
12.00
323055
17-Sep-15
360001
811
4-Oct-10
M
D
100000
12.50
323056
3-Oct-13
360002
535
7-Oct-10
P
D
10000000
12.50
323056
6-Oct-13
360003
527
7-Oct-10
M
D
4000000
12.50
323056
6-Oct-13
360004
54
19-Oct-10
M
D -
Adding more statements to the sql commands window
Hi, I'm using oracle database express edition10g and I just started using oracle.
And I'm having a problem adding more then one statement inside the sql commands gui window.
I write:
CREATE TABLE "testTable" (
"field1" VARCHAR2(2),
"field2" NUMBER(2,0),
"field3" NUMBER(2,0),
CONSTRAINT "Test_PK" PRIMARY KEY("field1")
Oracle reports: table created
I write
DROP TABLE testTable;
CREATE TABLE "testTable" (
"field1" VARCHAR2(2),
"field2" NUMBER(2,0),
"field3" NUMBER(2,0),
CONSTRAINT "Test_PK" PRIMARY KEY("field1")
Oracle reports: ORA-00911: invalid character
I remove the ; char
ORA-00933: SQL command not properly ended
I look in the help files and it sais that ; / and nothing is allowed to end a operation.
I gues ; is a valid char so it's reporting something else?
I tried pasting my code inside wordpad and even retyping it. Mayby I have a hidden char? =>same error.
When I run drop and create seperatly it works.
When I run both sql statements inside sql+ it works
What m I doing wrong?To run multiple SQL in one shot, you need to save them as SQL batch file,
Save your statements as recreate.sql
DROP TABLE testTable;
CREATE TABLE "testTable" (
"field1" VARCHAR2(2),
"field2" NUMBER(2,0),
"field3" NUMBER(2,0),
CONSTRAINT "Test_PK" PRIMARY KEY("field1")
);Then call it from SQLPlus,
@recreate.sql -
I have a search page that has 3 possible entries. Service,
City, & Keywords.
Service and City are list/menus and cannot be null, but
Keywords is a text
box and can be null.
I need to write a SQL statement to take the 3 possible
parameters and test
them against the database. Since the first 2 are never null,
I can write
them right inside the SQL string, but how can I only check
for the keywords
if there is something inside the box?
Can I use a <cfif> statement inside the sql string to
only check the 3rd
parameter if it is not NULL?
I wrote this:
Select company, name, phone, city, state, username FROM
members WHERE
city = Form.City AND state = Form.state AND keywords LIKE
Form.keywords
ORDER BY company ASC
Also, since I am passing it from a search page to a results
page, would it
be URL.City verses FORM.City, etc.
Also would like to do this in a component and pass the 3
variables as
arguments with the city and service being required and the
keywords not.
However, I have no idea on what the procedure is for this.
I wrote:
<cfcomponent>
<cffunction name="ServiceSearch" access="remote"
returntype="query">
<cfargument name="service" type="numeric"
required="true">
<cfargument name="city" type="numeric"
required="true">
<cfargument name="keywords" type="string"
required="false">
Select company, name, phone, city, state, username FROM
members WHERE
city = Form.City AND state = Form.state AND keywords LIKE
Form.keywords
ORDER BY company ASC
<cfreturn ServiceResults>
</cffunction>
</cfcomponent>
Do I invoke the component from the results page?
Well, I need to solve the first issue before I attempt the
second. Thanks!
Wally Kolcz
Developer / Support
ProjectProofing.comYes you can put <cfif ...> statements inside a
<cfquery...> tag to
modify the SQL string.
WHERE this = that AND
<cfif len(trim(form.something))>
AnotherThing = '#form.something#'
</cfif>
Is valid.
Whether the form variables on the action page are URL or FORM
depends on
the method of your <form ...> tag. method="post"
creates form variables
on the action page, method="get" creates URL variables on the
action page.
You write <cfargument ...> tags for each argument you
want to pass into
a function.
<cfargument name="city" required="true" ...>
OR
<cfargument name="foobar" required="false" default=""
...>
You then use these in the function with the arguments scope.
#arguments.city# and #arguments.foobar#
You then pass these into the function from your calling page.
There are
numerous ways this can be done, here are a few.
<cfinvoke .... city="Sacramento" foobar="george"/>
<finvoke ... >
<cfinvokeArgument name="city" value="Sacramento">
<cfinvokeArgument name="foobar" value="george">
</cfinvoke>
<cfset myComponent =
createObject("component","my.component.path.andName)>
...myComponent.aFunction("Sacramento","george")...
...myComponent.aFunction(city:"Sacrament",foobar:"george")...o
Wally Kolcz wrote:
> I have a search page that has 3 possible entries.
Service, City, & Keywords.
>
> Service and City are list/menus and cannot be null, but
Keywords is a text
> box and can be null.
>
> I need to write a SQL statement to take the 3 possible
parameters and test
> them against the database. Since the first 2 are never
null, I can write
> them right inside the SQL string, but how can I only
check for the keywords
> if there is something inside the box?
>
> Can I use a <cfif> statement inside the sql string
to only check the 3rd
> parameter if it is not NULL?
>
> I wrote this:
>
> Select company, name, phone, city, state, username FROM
members WHERE
> city = Form.City AND state = Form.state AND keywords
LIKE Form.keywords
> ORDER BY company ASC
>
> Also, since I am passing it from a search page to a
results page, would it
> be URL.City verses FORM.City, etc.
>
> Also would like to do this in a component and pass the 3
variables as
> arguments with the city and service being required and
the keywords not.
> However, I have no idea on what the procedure is for
this.
>
> I wrote:
> <cfcomponent>
> <cffunction name="ServiceSearch" access="remote"
returntype="query">
> <cfargument name="service" type="numeric"
required="true">
> <cfargument name="city" type="numeric"
required="true">
> <cfargument name="keywords" type="string"
required="false">
> Select company, name, phone, city, state, username FROM
members WHERE
> city = Form.City AND state = Form.state AND keywords
LIKE Form.keywords
> ORDER BY company ASC
> <cfreturn ServiceResults>
> </cffunction>
> </cfcomponent>
>
> Do I invoke the component from the results page?
>
> Well, I need to solve the first issue before I attempt
the second. Thanks!
> -
Optimization of CURSORS/SQL inside PL/SQL
Hi Friends
I have a query regarding optimization working with CURSOR FOR loops and embedded SQL stmts inside PL/SQL procedure.
I have a code where i am using a Cursor holding multiple rows and than LOOP over it to process individual rows. I am using nested Cursor FOR Loops too.
I want to know what optimizations are possible in this kind of scenario, where i ahve to process each row of a Cursor.
Kindly Guide....
Thanks and RegardsHello Friends.....
Thanks so very much for your reply!!
I am attaching my code for your reference. Will also go through the links u have provided.
Kindly, suggest what can be done in this kind of scenario:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
v_salesorg varchar2(10);
v_sales_district varchar2(10);
v_salesoff varchar2(10);
v_custgrp varchar2(10);
v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
dbms_output.put_line(v_cust_cur.customer_code );
-- BEGIN
SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
dbms_output.put_line(v_partner_code||i.customer_code);
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
WHERE customer_code = i.customer_code and salesorg = i.salesorg;
dbms_output.put_line(v_salesorg||i.salesorg);
dbms_output.put_line('Customer_Code : '|| i.customer_code);
dbms_output.put_line('SalesOrg : '|| i.salesorg);
/* SELECT parent_customer INTO v_parent_cust
from load_cust_hierarchy
WHERE customer_code = '1234'
and salesorg = 'abc'
and hierarchy_type = 'G'; */
SELECT parent_customer
INTO v_parent_cust
FROM load_cust_hierarchy
WHERE lower(customer_code) = lower(trim(i.customer_code))
AND lower(salesorg) = lower(trim(i.salesorg))
AND hierarchy_type = 'G';
/* SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
dbms_output.put_line(v_parent_cust);
dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
exception
WHEN NO_DATA_FOUND THEN
v_parent_cust := 'ACHINSUMAN';*/
-- END;
SELECT credit_block INTO v_credit_blk from load_cust_company_cod
WHERE customer_code = i.customer_code;
dbms_output.put_line(v_credit_blk);
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
LOOP
-- exit when j%NOTFOUND;
dbms_output.put_line(j.account_group);
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
v_nature := '06';
-- EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
-- ********************* Part to be extended**************
END IF;
dbms_output.put_line(v_type||' '||v_nature);
END LOOP;
INSERT INTO sfdc_account
(SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
WHEN NO_DATA_FOUND THEN
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
Thanks and Regards -
How to run a SQL statement which is stored inside an SQL Table
Hello,
If anyone please help me with the following problem I would be forever grateful
I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
Thanks in advance!
This is how it looks like more or less:
Displaying result for:
SELECT TRIM(OBJ_VALU_TXT)
FROM OBJ_VALU_DOC
WHERE OBJECT_TYPE = 'FLD'
AND OBJECT_CODE = 15443
AND OBJ_VALU_CD = 'ACR'
ORDER BYDOC_SEQ_NO
00001
SELECT
VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
FROM RECEIPT
WHERE (RECEIPT_NO BETWEEN
:OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
(RECEIPT_NO > :OUT-COMP-FACTOR AND
:OUT-TO-NUMBER = 0)Here's a demo of your requirement.
create table t ( col1 varchar2(200));
table created
insert into t values('select * from dual');
1 row inserted
declare
v_col varchar2(200);
v_val varchar2(200);
begin
select col1 into v_col from t;
execute immediate v_col into v_val;
dbms_output.put_line(v_val);
end;
X
Using into clause, you can use as many variables as required. But the basic approach reamins the same.
But storing SQL in DB is not an efficient design.
Ishan -
Case statement in advanced sql
how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table
this is the case statement i am using :
case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
and i get the below error
: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000) -
DDL statements and dynamic sql in stored procedure
I created a stored procedure to create and drop tables, using dynamic sql.
When I try to do the inserts using dynamic sql, i.e
v_string := 'INSERT statement';
EXECUTE IMMEDIATE v_string;
I get the following error message:
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at line 63
Line 63 happens to be the line that the EXECUTE IMMEDIATE v_string; statement is in.
I am able to describe the table that the inserts are being made into, so I know that the table exists.
Any idea why I'm getting this error message would be appreciated.Yes I do and I have been able to create other tables using dynamic sql.
The table that I am having problems with SELECTs data from another table to get its column values; within the SELECT statement, the CAST function is used:
ie. CAST(CASE SUBSTR(CAST(E_MOD AS VARCHAR(7)),2,3)
WHEN 'AAA' THEN 'A55'
ELSE ............
I get the following error message:
ERROR at line 18: (this line starts the CAST statement)
ORA-06550: line 18, column 13:
PLS-00103: Encountered the symbol "AAA" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
like between into using || bulk
When I remove the quotes or add another single quote, the same error cascades to 'A55'.
After doing the same for the next error, I get the error message below:
ERROR at line 1: (this line has the EXECUTE IMMEDIATE statement)
ORA-00936: missing expression
ORA-06512: at line 6
Any idea what the problem could be?
Also is there another way to have DDL statements as stored procedures other than using dynamic sql or the DBMS_SQL package? -
Multiple select statements in PL/SQL
Hi All
I am new to PL/SQL and my experience is in writing TSQL. There we can write a SQL statement like this to return 3 result set
SELECT empname FROM Employee
SELECT authname FROM Author
SELECT athname FROM sport
how can we write the same 3 statements in PL/SQL and attain the 3 resultsets.
I tried to implement the same using PL/SQL anonymous blocks. But it didn't worked.
DECLARE
P_RECORDSET OUT SYS_REFCURSOR
BEGIN
OPEN P_RECORDSET FOR
SELECT empname FROM Employee;
SELECT authname FROM Author;
SELECT athname FROM sport;
END;
can anybody show how it can be done.
Thanks in advance
George
Edited by: user6290570 on Sep 16, 2009 11:23 PMgeorge2009 wrote:
No i just want to select 3 result sets from 3 select statements, so that it is helpful to compare the resultsets. Compare? How? This is done using the SQL language. Not PL/SQL. Not Java. Not VB. Not anything else.
You would use these other language for flow control and certain forms of conditional logic - but the actual comparison of data sets is done in SQL.
Of course, that is if you do want to do it the most optimal way, that will perform well, and scale well.
SQL is not an I/O API layer - to be used to read() a record and write() a record as if the RDBMS is an ISAM file. That form of row-by-row and slow-by-slow processing dates back to the 80's when we used Cobol.. (or at least for those old farts like me that can actually remember coding in Cobol in the 80's ;-) ).
You want to design and code database applications that are fast, robust, and can scale? Then learn how to use SQL correctly. -
Logical Standby SQL Apply Using Incorrect Decode Statement
We are seeing statements erroring out on our logical standby that have been rewritten (presumably by sql apply) with decode statements that don't appear to be correct. For example, here is one of the rewritten statements.
update /*+ streams restrict_all_ref_cons */ "CADPROD"."OMS_SQL_STATEMENT" p
set *"APPLICATION"=decode(:1,'N',"APPLICATION",:2)*,
"STATEMENT"=dbms_reputil2.get_final_lob(:3,"STATEMENT",:4)
where (:5='N' or(1=1 and (:6='N' or(dbms_lob.compare(:7,"STATEMENT")=0)or(:7 is null and "STATEMENT" is null)))) and(:8="APPLICATION")
The problem comes in, we believe, with the attempt to write the value "APPLICATION" to the application column which is only a 10 character field. the value for the :1 bind variable is "N" and the value for :2 is null.
We see the following error on the logical standby:
ORA-00600: internal error code, arguments: [kgh_heap_sizes:ds], [0x01FCDBE60], [], [], [], [], [], []
ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [kxtoedu+54] [PC:0x2542308] [ADDR:0xFFFFFFFFFFFFFFFF] [UNABLE_TO_READ] []
ORA-12899: value too large for column "CADPROD"."OMS_SQL_STATEMENT"."APPLICATION" (actual: 19576, maximum: 10)
Is this a configuration issue or is it normal for SQL Apply to convert statements from logminer into decode statements?
We have an Oracle 10.2.0.4 database running on windows 2003 R2 64-bit os. We have 3 physical and 2 logical standby's, no problems on the physical standbys.Hello;
I noticed some of your parameters seem to be wrong.
fal_client - This is Obsolete in 11.2
You have db_name='test' on the Standby, it should be 'asadmin'
fal_server=test is set like this on the standby, it should be 'asadmin'
I might consider changing VALID_FOR to this :
VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES)Would review 4.2 Step-by-Step Instructions for Creating a Logical Standby Database of Oracle Document E10700-02
Document 278371.1 is showing its age in my humble opinion.
-----Wait on this until you fix your parameters----------------------
Try restarting the SQL Apply
ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATEI don't see the parameter MAX_SERVERS, try setting it to 8 times the number of cores.
Use these statements to trouble shoot :
SELECT NAME, VALUE, UNIT FROM V$DATAGUARD_STATS;
SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME LIKE ;TRANSACTIONS%';
SELECT COUNT(1) AS IDLE_PREPARERS FROM V$LOGSTDBY_PROCESS WHERE
TYPE = 'PREPERER' AND STATUS_CODE = 16166;Best Regards
mseberg
Edited by: mseberg on Feb 14, 2012 7:37 AM -
Calling a PL/SQL function in the SQL statement
I have a PL/SQL function which i should call in a SQL statement.
Let's say the function is func1(parameter1,parameter2),
it should be called like this :- SELECT func1() FROM mytable ;
Can any one help me out on this ?
---Thanx in advanceyou can call pl/sql functions from pl/sql using
select fn1('param1','param2') from table;
if you dont want to pass paramters, you have to specify default
value while creating function like below
create function fn1(p1 number default null,p2 varchar2 default
null) return...
now you can call using
select fn1 from table; -
Using sql function in xml sql statement
Hello,
I have following statement:
select field1, field2,....,field10 from table( cast (get_mhdata(:1,:2) as mhdata))
where mhdata is an oracle type with 10 fields.
It works good, but I don't know how can I use this statement in xml sql statement.
Please, can you tell me if it is really possible.
Thanks in regards.Hi
You cant pass the parameters if you are executing writing this select function from the communication channel.
You have 3 options:
1) Use a stored procedure and execute from the communication channel
2) Use a stored procedure and execute via message mapping in the IR - here you can pass parameters
3) Same as above but call the query via SQL select - you can also pass parameters.
sincerely,
--NM
Maybe you are looking for
-
I am having issues with trying to get MP4 files imported into Itunes. After several attempts I did some experimenting. I converted a DVD in to MP4 format and it will not load. The complete DVD movie convetted to MP4 is 2.2gb in size. This movie will
-
OS X mountain lion wont download
I have just purchased the new OS X but it wont download. Is anyone else having problems. i have contacted apple (non)support but they are harder to get hold of than the pope! Do any apple support contact numbers actually work?
-
11g Data guard 建physical standby database配置相关问题
General information OS:red hat Linux 2.6.32-200.13.1.el5uek x86_64(primary,standby) Home version:11.2.0.3(primary,standby) Situation: 实验用库,想学习data guard,在另一个服务器上克隆了一个HOME并按照官方文档http://docs.oracle.com/cd/E11882_01/server.112/e25608/create_ps.htm#i1225
-
Printing the salary certificate in row wise
hi gurus, i have developed a custom report for printing the salary details( basic,pf,hra ) as column wise how to do this as row wise.. like this.. basic --- pf ...... hra ..... how to do this ..
-
My mail accounts not appearing when opening Thunderbird
All has been working great with Thunderbird V31. This morning I opened the app and my various mail boxes are not showing on the left side. The downloading appears to be working fine. I can see the downloading showing up at bottom of interface. But NO