Iterate through dates using PL/SQL
Hi,
I want to run a loop that take's today's date and iterate from today to the past 2 months dates in PL/SQL. Any tips?
Thanks.
Hi,
Jacky411 wrote:
I want to run a loop that take's today's date and iterate from today to the past 2 months dates in PL/SQL. Any tips?You can do that in SQL, too:
SELECT SYSDATE + 1 - LEVEL AS dt
FROM dual
CONNECT BY LEVEL <= 1 + SYSDATE - ADD_MONTHS (SYSDATE, -2)
ORDER BY dt DESC;
Similar Messages
-
Can we use Data Pump to export data, using a SQL query, doing a join
Folks,
I have a quick question.
Using Oracle 10g R2 on Solaris 10.
Can Data Pump be used to export data, using a SQL query which is doing a join between 3 tables ?
Thanks,
AshishHello,
No , this is from expdp help=Y
QUERY Predicate clause used to export a subset of a table.
Regards -
Write / store xml data in Xe and retrieve stored data using pl/sql
Hi to all,
i'm searching a tutorial on:
A - how to write / store xml data in Xe and retrieve stored data using pl/sql
I don't want to use other technologies, because i use htmldb and my best practice is with pl/sql.
I was reading an ebook (quite old maybe) however it's about oracle 9 and it's talking about xmltype:
1 - I don't understand if this is a user type (clob/varchar) or it's integrated in Oracle 9 however i will read it (it's chapter 3 titled Using Oracle xmldb).
Please dont'reply here: i would be glad if someone can suggest me a good tutorial / pdf to achieve task A in Oracle XE.
ThanxThank you very much Carl,
However my fault is that i've not tried to create the table via sql plus.
Infact i was wrong thinking that oracle sql developer allows me to create an xmltype column via the create table tool.
however with a ddl script like the following the table was created successfully.
create table example1
keyvalue varchar2(10) primary key,
xmlcolumn xmltype
Thank you very much for your link.
Message was edited by:
Marcello Nocito -
Replace ' with ' in my data using pl/sql
I want to replace all occurrence of special characters like ' with ' in my data using pl/sql.
How can I achieve this?Thank you for your quick reply. My code is:
DECLARE
firstname varchar2(200) := 'cccc&a p o s;dddd'; ---> Please remove spaces between a p o s. Combine them as apos
lastname varchar2(200) := 'eeee';
BEGIN
dbms_output.put_line('Before changing : firstname :' || firstname);
dbms_output.put_line('After changing: firstname :' || replace(LastName, "'" , "'") );
END;
When I run this in sqlplus, I see:
SQL> @EscapeCharTesting.sql
Enter value for apos:
So I want to change all occurences of "&a p o s;" to CHR(39) -
Urgent HELP required on forming the Matrix of data using PL/SQL
Hi All,
I'm new to this thread and require your urgent help in this regard.
I've got a requirement for building a 5000 X 5000 matrix using PL/SQL. My original data tables have 5000 rows each and I need to do a correlation analysis using this data and need to store in a physical table and not in-memory. Is this feat achievable using mere PL/SQL? I understand that Oracle DB has a limitation of 1000 columns(but not sure) and hence I'd like to know whether there is any work-around for such scenarios. If not, what are the other alternative method(s) to achieve this feat? Do I need to use any 3rd party tools to get this done? An early reply from the experts is highly appreciated.
Thanking you all Gurus in advance.
Rgds
SaiWelcome to OTN!
I'll get to your quesiton in a moment, but first some welcome information. Many OTN posters consider it impolite to mark threads as "urgent". We are volunteers and have jobs of our own to do without people we don't know making demands. You are brand new and deserve some patience but please understand this. It is very likely before I finish this post someone will complain about the word "urgent" in your subject.
On to more interesting things :)
You can do the matrix, but are out of luck with a 5000 x 5000 table because Oracle only allows 1000 columns per table. There are ways to work around this.
How do do the matrix depends on what you want to do. You can do this different ways. You can create a table beforehand and use PL/SQL or simple SQL to populate it, or use the CREATE TABLE AS syntax to create and populate it in one step if you can get the underlying SQL to work the way you want, something like
create table my_table as
select a.*, b.*
from table1 a, table2 bcan populate a matrix from 2 tables with an intentional cartesian join (the WHERE clause was left out intentionally, provided your data is already in the data base.
If not you can use a PL/SQL routine to populate the data.
There are a couple of ways to solve the 1000 column limit. The easiest way might be to have 5 collections of 1000 columns each. A more complicated but more elegant soltion would be to have nested collections, allowing 2 colliections that you can loop through - a collection of collections. Nested collections can be hard to work with. A third way would be to use nested tables in the database but I personally do not like them and the insert, update, and delete statements for nested tables are hard to use.
I'm not going to give a code example because I am not sure which solution is best for you. If you have further questions post them. -
Item data using PL/SQL block region
hello community,
I have searched the whole forum using Pl/SQL but couldn't find an answer for this.
I have a PL/SQL Anonymous block region, containing database items fetched by a process and custom items getting set by the Pl/SQL source.
based on the ID I am getting the records i.e.
Region Source (PL/SQL Anonymous block)
declare
CURSOR cpc_cur is SELECT "PRODUCT", "APPCODE", "COMCODE", "DESCRIPTION" from cp2 where "ID" = :P4_ID;
begin
for cpc_rec in cpc_cur
loop
:P4_P_NAME := cpc_rec.product;
end loop;
end;
The custom item is text field with source Item.
The item value is not filled in for the first time after login, but it shows the value in the session state as with status 'I', but from then onwards it works fine.
Why is the value not fetched the first time?
even I tried the postcalculation using nvl and it sets it to null.
Also set_session state doesn't work.
If I make the custom Item as Pl/SQL function, and write the query then it works fine, but gives problem as while inserting a new record the query has no ID to refer.
Thanks in advance.
PiyushThanks Scott!!
1) I am using PL/SQL region to get the data for few items on the form region which is based on a table, all table attributes are database items and additional Items whose data I am fetching from the PL/SQL are Custom items.
2) Yes the loop executes only once per page view, Is their a better query?
3) Well its very dumb to have a item source as item pointing to itself, but since the values are in session with status 'I' I thought this could do the trick!
4) As the item source type used is [only..], the first time user logs in it doesn't displays the value, need to refresh the page, but the second time its gets the values form the session.
5) If I make the Item source as PL/SQL function, I just fetch the records individually, same as in the query which works fine, but the items are also used for insertion (add new) and I clear the cache, so it gives error as it cannot execute the pl/sql function(no ID while addition)
I hope I have answered your questions! If you have patience you can read the detail description.
test application on oracle server
http://apex.oracle.com/pls/otn/f?p=24296:1:3544773135949858:::::
login/password test/test
Application name :Test
The page has 2 regions. when clicking on SN the values are transfered to form, except for 'Appcode'.
Detail Description:
I have a page with 2 regions.
One region is a report region showing fewer details from a view. The other region is a PL/SQL(form region), which shows all the details and is linked to the report region.
While linking I pass the ID from report and autofetch the data in form region.
But some Items are not related to that database, so I created few items on form region (Custom Items). To fill in these values I did these things.
1) Pass them through script (but passing 7 parameters through script is not good)
2) Made another autofetch process to fetch the remaining Items, but it seems that its not possible to have 2 autofetch process on one form region.
3) Changed the form type from HTML to PL/SQL, to assign the custom items values through code.
for cpc_rec in cpc_cur
loop
:P_custom_item := cpc_rec.data;
end loop;
Either make source type static or Item (the same item P_custom_item).
This pl/sql code do assign them the values, In the session state their status is 'I', but are not displayed on the page for the first login, need to refresh the page, as the source used is (only when..) it gets the value the second time.
4) Made the item source as PL/SQL function and assign them the value. It works fine, but the same item is also used displaying description while insertion(gives error while insertion), so made a conditional process, even that gives the same error.
I have a questions.
If an Item status is 'I' in the session state, why is it not displaying the value on page.
Thanking you in anticipation
Piyush
Message was edited by:
user523112 -
Appending the Destination File through FTP using PL/SQL
One of my requirement is I have to do the ftp using PL/SQL (My database is 10g on LINUX) ,
What I know is i can do the FTP using the UTL_TCP and UTL_FILE packages that oracle provides, but inthis case requirent is ftp and append "APPEND" to the destination file.
this is the command I use to FTP mannualy ....
cd C:\Temp\Source\
ftp
open 999.99.99.99.99
loginID
ThePasWord
ascii
append CSOURCE.DAT M:\Temp\Destination\CDESTINATION.DAT
close
quit
What I want to know is how to do this through PL/SQL
I will appreciat this ...I got It...
At
http://www.oracle-base.com/articles/9i/FTPFromPLSQL9i.php
Only Replace
send_command(p_conn, 'STOR ' || p_file, TRUE);
With
send_command(p_conn, 'APPE ' || p_file, TRUE); -
Restful service unable to insert data using PL/SQL.
Hi all,
Am running: AL 2.01 standalone mode on OEL 4.8 in VM box A.
Oracle database 10.2.0.4 with Apex 4.2.0.00.27 on OEL4.8 in VM box B.
Able to performed oracle.example.hr Restful services with no problem.
Unable to insert data using AL 2.0.1 but works on AL 1.1.4.
which uses the following table (under schema: scott):
create table json_demo ( title varchar2(20), description varchar2(1000) );
grant all on json_demo to apex_public_user; and below procedure ( scott's schema ):
CREATE OR REPLACE
PROCEDURE post(
p_url IN VARCHAR2,
p_message IN VARCHAR2,
p_response OUT VARCHAR2)
IS
l_end_loop BOOLEAN := false;
l_http_req utl_http.req;
l_http_resp utl_http.resp;
l_buffer CLOB;
l_data VARCHAR2(20000);
C_USER_AGENT CONSTANT VARCHAR2(4000) := 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
BEGIN
-- source: http://awads.net/wp/2005/11/30/http-post-from-inside-oracle/
-- Ask UTL_HTTP not to raise an exception for 4xx and 5xx status codes,
-- rather than just returning the text of the error page.
utl_http.set_response_error_check(false);
-- Begin the post request
l_http_req := utl_http.begin_request (p_url, 'POST', utl_http.HTTP_VERSION_1_1);
-- Set the HTTP request headers
utl_http.set_header(l_http_req, 'User-Agent', C_USER_AGENT);
utl_http.set_header(l_http_req, 'content-type', 'application/json;charset=UTF-8');
utl_http.set_header(l_http_req, 'content-length', LENGTH(p_message));
-- Write the data to the body of the HTTP request
utl_http.write_text(l_http_req, p_message);
-- Process the request and get the response.
l_http_resp := utl_http.get_response (l_http_req);
dbms_output.put_line ('status code: ' || l_http_resp.status_code);
dbms_output.put_line ('reason phrase: ' || l_http_resp.reason_phrase);
LOOP
EXIT
WHEN l_end_loop;
BEGIN
utl_http.read_line(l_http_resp, l_buffer, true);
IF(l_buffer IS NOT NULL AND (LENGTH(l_buffer)>0)) THEN
l_data := l_data||l_buffer;
END IF;
EXCEPTION
WHEN utl_http.end_of_body THEN
l_end_loop := true;
END;
END LOOP;
dbms_output.put_line(l_data);
p_response:= l_data;
-- Look for client-side error and report it.
IF (l_http_resp.status_code >= 400) AND (l_http_resp.status_code <= 499) THEN
dbms_output.put_line('Check the URL.');
utl_http.end_response(l_http_resp);
-- Look for server-side error and report it.
elsif (l_http_resp.status_code >= 500) AND (l_http_resp.status_code <= 599) THEN
dbms_output.put_line('Check if the Web site is up.');
utl_http.end_response(l_http_resp);
RETURN;
END IF;
utl_http.end_response (l_http_resp);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line (sqlerrm);
raise;
END; and executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
SET serveroutput ON
DECLARE
l_url VARCHAR2(200) :='http://MY_IP:8585/apex/demo';
l_json VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
l_response VARCHAR2(30000);
BEGIN
post( p_url => l_url, p_message =>l_json, p_response => l_response);
END;which resulted in :
anonymous block completed
status code: 200
reason phrase: OK
with data inserted. Setup using 2.0.1
Workspace : wsdemo
RESTful Service Module: demo/
URI Template: test
Method: POST
Source Type: PL/SQLand executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
SET serveroutput ON
DECLARE
l_url VARCHAR2(200) :='http://MY_IP:8585//apex/wsdemo/demo/test';
l_json VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
l_response VARCHAR2(30000);
BEGIN
post( p_url => l_url, p_message =>l_json, p_response => l_response);
END;which resulted in :
status code: 500
reason phrase: Internal Server Error
Listener's log:
Request Path passes syntax validation
Mapping request to database pool: PoolMap [_poolName=apex, _regex=null, _workspaceIdentifier=WSDEMO, _failed=false, _lastUpdate=1364313600000, _template=/wsdemo/, _type=BASE_PATH]
Applied database connection info
Attempting to process with PL/SQL Gateway
Not processed as PL/SQL Gateway request
Attempting to process as a RESTful Service
demo/test matches: demo/test score: 0
Choosing: oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as current candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true]
Determining if request can be dispatched as a Tenanted RESTful Service
Request path has one path segment, continuing processing
Tenant Principal already established, cannot dispatch
Chose oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as the final candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true] for: POST demo/test
demo/test is a public resource
Using generator: oracle.dbtools.rt.plsql.AnonymousBlockGenerator
Performing JDBC request as: SCOTT
Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
INFO: Error occurred during execution of: [CALL, begin
insert into scott.json_demo values(/*in:title*/?,/*in:description*/?);
end;, [title, in, class oracle.dbtools.common.stmt.UnknownParameterType], [description, in, class oracle.dbtools.common.stmt.UnknownParameterType]]with values: [thetitle, thedescription]
Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
INFO: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
java.sql.SQLException: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:505)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:223)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:205)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1043)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3612)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3713)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4755)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at oracle.ucp.jdbc.proxy.StatementProxyFactory.invoke(StatementProxyFactory.java:242)
at oracle.ucp.jdbc.proxy.PreparedStatementProxyFactory.invoke(PreparedStatementProxyFactory.java:124)
at oracle.ucp.jdbc.proxy.CallableStatementProxyFactory.invoke(CallableStatementProxyFactory.java:101)
at $Proxy46.execute(Unknown Source)
at oracle.dbtools.common.jdbc.JDBCCallImpl.execute(JDBCCallImpl.java:44)
at oracle.dbtools.rt.plsql.AnonymousBlockGenerator.generate(AnonymousBlockGenerator.java:176)
at oracle.dbtools.rt.resource.templates.v2.ResourceTemplatesDispatcher$HttpResourceGenerator.response(ResourceTemplatesDispatcher.java:309)
at oracle.dbtools.rt.web.RequestDispatchers.dispatch(RequestDispatchers.java:88)
at oracle.dbtools.rt.web.HttpEndpointBase.restfulServices(HttpEndpointBase.java:412)
at oracle.dbtools.rt.web.HttpEndpointBase.service(HttpEndpointBase.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
at oracle.dbtools.standalone.SecureServletAdapter.doService(SecureServletAdapter.java:65)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:379)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:196)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Error during evaluation of resource template: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-idPlease advise.
Regards
ZackZack.L wrote:
Hi Andy,
Sorry, forgot to post the Source that's use by both AL1.1.4 and AL2.0.1.
Source
begin
insert into scott.json_demo values(:title,:description);
end;
it's failing during the insert?
Yes, it failed during insert using AL2.0.1.
So the above statement produces the following error message:
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-idThis suggests to me that an unprintable character (notice how there is nothing between the double quotes - "") has worked its way into your PL/SQL Handler. Note how the error is reported to be a column 74 on line 2, yet line 2 of the above block should only have 58 characters, so at a pure guess somehow there's extra whitespace on line 2, that is confusing the PL/SQL compiler, I suggest re-typing the PL/SQL handler manually and seeing if that cures the problem. -
Displaying diff dates using PL/SQL expression for 'display only' item ?
Hi ,
I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
E.g: Today is Friday and the last Monday was on 18th .
So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
I tried it doing under 'Source ' of item using PL/SQL expression and PL/SQL function body. Not working
Can someone help ?
Thanks & Regards
UmerNice1 wrote:
declare
lv_date number;
begin
select to_char(sysdate,'D') into lv_date from dual;
if lv_date=2 then
:P2_FROM_DATE := to_char(sysdate-1);
end if;
end;I tried this under " PL/SQL function body " in "Source " tab of the item P2_FROM_DATE
When I run this , nothing is displayed corresponding to the item P2_FROM_DATEExactly as expected. This code will only set a value for <tt>P2_FROM_DATE</tt> when run on Mondays in territories where the first day of the week is Sunday, and when run on Tuesdays where Monday is the first day of of the week:
SQL> var P2_FROM_DATE varchar2(30)
SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
Session altered.
SQL> select sysdate from dual
SYSDATE
Mon 25-JUN-2012
SQL> alter session set nls_territory='AMERICA';
Session altered.
SQL> declare
2 lv_date number;
3 begin
4 select to_char(sysdate,'D') into lv_date from dual;
5 if lv_date=2 then
6 :P2_FROM_DATE := to_char(sysdate-1);
7 end if;
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> print p2_from_date
P2_FROM_DATE
Sun 24-JUN-2012
SQL> alter session set nls_territory='UNITED KINGDOM';
Session altered.
SQL> exec :p2_from_date := null
SQL> declare
2 lv_date number;
3 begin
4 select to_char(sysdate,'D') into lv_date from dual;
5 if lv_date=2 then
6 :P2_FROM_DATE := to_char(sysdate-1);
7 end if;
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> print p2_from_date
P2_FROM_DATE
SQL>Hence the questions about language above.
>
I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
E.g: Today is Friday and the last Monday was on 18th .
So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
>
The coming Monday is 25-JUN-2012.
Aren't these rules equivalent to "Monday this week, where Monday is the first day of the week"? In which case the PL/SQL Expression you require is:
trunc(sysdate, 'iw')For example:
SQL> with t as (
2 select date '2012-06-21' + level d from dual connect by level <= 17)
3 select
4 d
5 , trunc(d, 'iw') monday
6 from
7 t;
D MONDAY
Fri 22-JUN-2012 Mon 18-JUN-2012
Sat 23-JUN-2012 Mon 18-JUN-2012
Sun 24-JUN-2012 Mon 18-JUN-2012
Mon 25-JUN-2012 Mon 25-JUN-2012
Tue 26-JUN-2012 Mon 25-JUN-2012
Wed 27-JUN-2012 Mon 25-JUN-2012
Thu 28-JUN-2012 Mon 25-JUN-2012
Fri 29-JUN-2012 Mon 25-JUN-2012
Sat 30-JUN-2012 Mon 25-JUN-2012
Sun 01-JUL-2012 Mon 25-JUN-2012
Mon 02-JUL-2012 Mon 02-JUL-2012
Tue 03-JUL-2012 Mon 02-JUL-2012
Wed 04-JUL-2012 Mon 02-JUL-2012
Thu 05-JUL-2012 Mon 02-JUL-2012
Fri 06-JUL-2012 Mon 02-JUL-2012
Sat 07-JUL-2012 Mon 02-JUL-2012
Sun 08-JUL-2012 Mon 02-JUL-2012
17 rows selected.
SQL> alter session set nls_territory='AMERICA';
Session altered.
SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
Session altered.
SQL> with t as (
2 select date '2012-06-21' + level d from dual connect by level <= 17)
3 select
4 d
5 , trunc(d, 'iw') monday
6 from
7 t;
D MONDAY
Fri 22-JUN-2012 Mon 18-JUN-2012
Sat 23-JUN-2012 Mon 18-JUN-2012
Sun 24-JUN-2012 Mon 18-JUN-2012
Mon 25-JUN-2012 Mon 25-JUN-2012
Tue 26-JUN-2012 Mon 25-JUN-2012
Wed 27-JUN-2012 Mon 25-JUN-2012
Thu 28-JUN-2012 Mon 25-JUN-2012
Fri 29-JUN-2012 Mon 25-JUN-2012
Sat 30-JUN-2012 Mon 25-JUN-2012
Sun 01-JUL-2012 Mon 25-JUN-2012
Mon 02-JUL-2012 Mon 02-JUL-2012
Tue 03-JUL-2012 Mon 02-JUL-2012
Wed 04-JUL-2012 Mon 02-JUL-2012
Thu 05-JUL-2012 Mon 02-JUL-2012
Fri 06-JUL-2012 Mon 02-JUL-2012
Sat 07-JUL-2012 Mon 02-JUL-2012
Sun 08-JUL-2012 Mon 02-JUL-2012
17 rows selected.Also note that using the item source properties will only set the <tt>P2_FROM_DATE</tt> in the rendered page, not in session state. -
How to iterate xml elements using PL/SQL
Hello,
Let's say I have the following xml:
<A>
<B name="b1">
</B>
<B name="b2">
</B>
</A>
I would like to iterate over the B and sub-B elements using PL/SQL?
Any help will be appreciated.Hi,
You can use 'PL/SQL DOM API for XMLType (DBMS_XMLDOM)'
to work with XML. You can check the example present at
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96620/xdb08pls.htm#1041419
to check how it does.
The API for the package DBMS_XMLDOM is given on the same page(http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96620/xdb08pls.htm#1040676)
You can use them for your requirement.
Regards,
Anupama -
Sending Mail through Outlook using PL/SQL
I have installed Oracle 9i (9.2.0.1) on Windows Xp with SP 2 platform. My MS Outlook has been configured.
How could i send mail through Microsoft outlook by using PL/SQL Program.How could i send mail through Microsoft outlook by using PL/SQL Program.Nonsensical question. MS Outlook is a mail client. A PL/SQL program is also a mail client.
Both these need to talk to a mail server. It does not make sense for one mail client to "+talk+" to another client for passing it e-mails that need to be send.
The mail client talks to a mail server using the SMTP ( Simple Mail Transfer Protocol ). There are also other protocols such as IMAP (open standard) and MAPI (Microsoft proprietary).
Oracle's PL/SQL environment by default supports SMTP via the UTL_SMTP, and UTL_MAIL packages - these provide the PL/SQL developer with an interface to use to send e-mails.
MS Outlook (client) does not feature anywhere in this regard, whereas MS Exchange as a mail server will (assuming it is being used on your network). -
Dynamically Iterate through data a deliver a seperate report for each
How would I configure my Crystal Report Server to dynamically iterate through a batch of check numbers, generate & deliver a report for each check number?
Jaggy like this
-
Whats the best practice to simply manage data using php sql?
Hi
I'm trying to follow some tutorials but there is too much old material and I'm getting confused.
This is basic. I have a db and I want to movement data from flex.
So, this is how I'm trying to do so. As a newbie, I will try to be clear.
I have created a simple table called "teste" using myphpadmin with only 2 fields for testing. (id, name).
I have created the services automaticly using flex to generate a php code.
This code is a simple exercise with buttons to add, update, and delete a Item.
Although there is a lot of auto-generated code, I had a lot of work (due to my ignorance) to make it work.
It fairly works, but I know veteran users would make it better, smarter, shorter, and ALL I WANT is a better (and simple) example to follow
Please.
Thanks in advance
ps. I have set my table field "name" to the 'utf8_unicode_ci' while creating it and I it seems the adobe's generated php can't handle latin chars.
THE CODE AS FOLLOWS:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
xmlns:valueObjects="valueObjects.*"
xmlns:testeservice="services.testeservice.*"
creationComplete="application1_creationCompleteHandler()" >
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import spark.events.IndexChangeEvent;
import spark.events.TextOperationEvent;
//selected item
public var selId:int;
//------GET ITEM (init)------------------------------------------------------
protected function application1_creationCompleteHandler():void
tx_edit.addEventListener(KeyboardEvent.KEY_UP,parallelEdit)
getAllTesteResult.token = testeService.getAllTeste();
//------SELECTED ITEM ID------------------------------------------------------
protected function list_changeHandler(event:IndexChangeEvent):void
selId = event.currentTarget.selectedItem.id;
lb_selectedId.text = "sel id: "+ selId;
if(tb_edit.selected) tx_edit.text = event.currentTarget.selectedItem.name;
//------ADD ITEM-----------------------------------------------------
protected function button_clickHandler(event:MouseEvent):void
var teste2:Teste = new Teste();
teste2.name = nameTextInput.text;
createTesteResult.token = testeService.createTeste(teste2);
application1_creationCompleteHandler();
//------UPDATE ITEM (in parallel)-----------------------------------------------------
private function parallelEdit(e:KeyboardEvent):void
if(!isNaN(selId) && selId > 0){
if(tb_edit.selected){
//uptadating
teste2.id = selId;
teste2.name = tx_edit.text;
updateTesteResult.token = testeService.updateTeste(teste2);
//------UPDATE ITEM (button click)-----------------------------------------------------
protected function button3_clickHandler(event:MouseEvent):void
teste2.id = parseInt(idTextInput2.text);
teste2.name = nameTextInput2.text;
updateTesteResult.token = testeService.updateTeste(teste2);
//------DELETE ITEM------------------------------------------------------
protected function button2_clickHandler(event:MouseEvent):void
if(!isNaN(selId) && selId > 0) deleteTesteResult.token = testeService.deleteTeste(selId);
]]>
</fx:Script>
<fx:Declarations>
<!-- this part was mostly auto generated -->
<valueObjects:Teste id="teste"/>
<testeservice:TesteService id="testeService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="createTesteResult"/>
<s:CallResponder id="getAllTesteResult"/>
<s:CallResponder id="deleteTesteResult"/>
<s:CallResponder id="updateTesteResult"/>
<valueObjects:Teste id="teste2"/>
</fx:Declarations>
<!-- this are just visual objects. Renamed only necessary for this example
most lines were auto-generated-->
<!--Create form -->
<mx:Form defaultButton="{button}">
<mx:FormItem label="Name">
<s:TextInput id="nameTextInput" text="{teste.name}"/>
</mx:FormItem>
<s:Button label="CreateTeste" id="button" click="button_clickHandler(event)"/>
</mx:Form>
<!--Create Result -->
<mx:Form x="10" y="117">
<mx:FormItem label="CreateTeste">
<s:TextInput id="createTesteTextInput" text="{createTesteResult.lastResult as int}" />
</mx:FormItem>
</mx:Form>
<!--List -->
<s:List x="10" y="179" id="list" labelField="name" change="list_changeHandler(event)">
<s:AsyncListView id="anta" list="{getAllTesteResult.lastResult}" />
</s:List>
<!--Update in parallel -->
<s:Label x="147" y="179" id="lb_selectedId"/>
<s:Button x="147" y="222" label="Remove" id="button2" click="button2_clickHandler(event)"/>
<s:TextInput x="225" y="257" id="tx_edit"/>
<s:ToggleButton x="147" y="257" label="Edit" id="tb_edit" />
<!--Update with button click -->
<mx:Form defaultButton="{button3}" x="220" y="0">
<mx:FormItem label="Id">
<s:TextInput id="idTextInput2" text="{teste2.id}"/>
</mx:FormItem>
<mx:FormItem label="Name">
<s:TextInput id="nameTextInput2" text="{teste2.name}"/>
</mx:FormItem>
<s:Button label="UpdateTeste" id="button3" click="button3_clickHandler(event)"/>
</mx:Form>
</s:Application>Sorry - I had to read up on what a base table block was.
I think I am. In this particular form I have one block - a customer block which has its items pulled in from the customer table, no problems there, it works fine.
My problem is I need to make it as user friendly as possible, if the user inputs the wrong customer ID (or does not know their name) I want them to be able to scroll through the customer list using an up or down button.
When do you have the commit_form statement run, (the OK button) after every change or after a block of changes ? Commit writes the changes to the database giving other users access to that data right ?! How often should it be used ? -
I am using the "fetch all" vi to do this, but it is retrieving one record at a time, (if you examine the block diagram) How can i retrieve all records in a faster more efficient manner?
If this isn't faster than your previous method, then I think you found the wrong example. If you have the Database Connectivity Toolkit installed, then go to the LabVIEW Help menu and select "Find Examples". It defaults to searching for tasks, so open the "Communicating with External Applications" and "Databases" and open the Read All Data. The List Column names just gives the correct header to the resulting table and is a fast operation. That's not what you are supposed to be looking at ... it's the DBTools Select All Data subVI that is the important one. If you open it and look at its diagram, you'll see that it uses a completely different set of ADO methods and properties to retrieve all the data.
-
How do I pull SharePoint 2013 list data using a SQL Query
I have been asked to write a sql query to pull data from a SharePoint 2013 List.it needs to return all the columns
Basically a Select all from the specific SharePoint list Database
I do have the list GUID ID. But not sure which SQL Table or Database to look in for list data.. the site and the list is in our main SharePoint site collection.
the query only needs to be saved in SQL serverI know it isn't support but sometimes you have to share data with other programs....
I'm stuck.. I was able to get this far...
SELECT * FROM dbo.Lists
where tp_Title ='List Name'
how do I pull the columns of the list?
I think I still need the specific list not just the master list dbo....
those two links do not work for SQL server and SharePoint 2013
Maybe you are looking for
-
How do I delete an old device off my iTunes account to all ow for a new one?
I'm wanting to delete the 2 iPod touches off my account
-
BufferedReader reader = new BufferedReader(new FileReader(new File(filie))); String line; while ((line = reader.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, "/"); // System.out.println("st"+st); String path = st.nextToken();
-
I need to know the reason Why Macbook Pro Mid 2012 have yellow tint screen?
I am confusing about the reason Why Macbook Pro screen have yellow tint color? There are few reason that I got from some apple shop saleman(In Thai) and someone in discussion experience. First (1), The reason is IPS or PSL Technology made the screen
-
Is Adobe Air 3.5 compatible with 7 starter ?
Hello, We recently developped a Webbapp in our company using adobe air. But, customers using Windows 7 starter are not able to open it. Could it be link to a compatibility issue between Windows 7 starter and Adobe Air 3.5? Thanks a lot for your help,
-
How can I enlarge the window for writing descriptions for pictures in iphoto 11?
How can I enlarge the window for writing descriptions for pictures in iPhoto 11?