Alternative Filtering in SQL

example:
table A : fields -->
company
order no
check status
total price
amount sell
table B : fields -->
company
store order no
store total price
store amount sell
please help me on how to solve, if system have to check on "check status" before filtering. if "check status" is '1', then retrieve fields from table B, else retrieve from table A. there are many companies, and different company have its "check status" (either '1' or '0'). thanks

Daphne,
you can try this with one query like
select a.company, decode(a.check_status,1,b.store_order_no,a.store_order_no) as ORDERNO,
decode(a.check_status,1,b.store_total_price,a.store_total_price) as TOTALPRICE,
decode(a.check_status,1,b.store_amount_sell,a.amount_sell) as AMOUNTSELL
from a, b
where a.company=b.company
regards
Rainer

Similar Messages

  • Filtered report SQL query in IRR

    Hi guys,
    There is simple IRR "Select * from emp" on my page.
    End user put some filters on the report from Actions Menu. Can i somehow (on any button click, etc) get the new SQL which is saved by user now?
    Thanks
    Sunil Bhatia

    See this:
    http://www.deneskubicek.blogspot.de/2013/05/getting-interactive-report-query.html
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    https://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494

  • Alternative to UNION SQL Oracle 11g

    Hi,
    is any possibility to replace this SQL statement with another one?
    Be aware that this one works and the tables are not identical.
    String statement =" SELECT id, "+
         " sender_id, "+
         " date_created "+
         " FROM DOCUMENT_ARCHIVE da "+
         " where da.SOURCE_FILE_NAME = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' "+
         " union all "+
         " select file_id,"+
         " sender_id,"+
         " date_created "+
         " from DOCUMENT_FILE df "+
         " WHERE df.SOURCE_FILE_NAME = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' ";

    Why do you feel the need to replace it if it gives correct results? If you need to union, then you need to union. Most other structures would not give identical results, that is, one row for each occurrence in each table.
    About the only change that you could make would be to create a view along the lines of:
    CREATE VIEW combined AS
    SELECT id, sender_id, date_created, source_file_name
    FROM document_archive
    UNION ALL
    SELECT id, sender_id, date_created, source_file_name
    FROM document_fileThen query the view like:
    SELECT id, sender_id, date_created
    FROM combined
    WHERE source_file_name = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' As a side note, I hope that your real code uses bind variables instead of string literals.
    John

  • How to use new sequence when one is reached its maxvalue in PL SQL code

    Hi,
    Currently, I am populating a unique product serial number in a table column using a sequence call to generate new number. For different products, I have different sequences and in my PL SQL code usiing IF..Else block I populate serial number for different products. For one most selling product sequence, we are reaching a Max value in production in a month and to make sure that application will continue to work fine for various end users without getting any error on their screens, I want my code to switch to new sequence automatically. I just need to add another if condition but my problem is how to find accurately when max value is reached for old sequence.
    As call to old sequence can happen in different sessions there could be inconsistency and can end up at error. My new sequence value has to start with AV1000. Please suggest.
    My old sequence look like this :
    SEQUENCE Prd
    INCREMENT BY 1
    START WITH AS1000
    MAXVALUE AS9999
    MINVALUE AS1000
    CYCLE NOCYCLE
    CACHE 2
    Order Yes;
    Edited by: user11695088 on Jul 15, 2009 12:14 AM

    Catch the exception and use your new sequence. But somehow, I'm not liking your alternative approach.
    SQL> set line 300
    SQL> set pages 50000
    SQL> set serveroutput on
    SQL> create sequence testing_seq increment by 1 start with 1 maxvalue 3
      2  /
    Sequence created.
    SQL>
    SQL> create or replace procedure test_seq_proc(p_seq out number)
      2  is
      3  begin
      4     select testing_seq.nextval
      5     into p_seq
      6     from dual;
      7  --
      8     dbms_output.put_line(p_seq);
      9  --
    10  end;
    11  /
    Procedure created.
    SQL> declare v_out number;
      2  begin
      3     test_seq_proc(v_out);
      4  end;
      5  /
    1
    PL/SQL procedure successfully completed.
    SQL> /
    2
    PL/SQL procedure successfully completed.
    SQL> /
    3
    PL/SQL procedure successfully completed.
    SQL> /
    declare v_out number;
    ERROR at line 1:
    ORA-08004: sequence TESTING_SEQ.NEXTVAL exceeds MAXVALUE and cannot be instantiated
    ORA-06512: at "ETL_ADMIN.TEST_SEQ_PROC", line 4
    ORA-06512: at line 3
    SQL>Cheers
    Sarma.

  • Oracle Express SQL scripts is displaying in Red not Green

    The SQL script display is very hard to read in red. Noramlly it is light Green and easy to read, I belive it is using JAVA to render.

    This is a [long standing problem in some browsers/configurations|http://forums.oracle.com/forums/search.jspa?threadID=&q=%22Script+editor%22+AND+RED&objID=f137&dateRange=all&userID=&numResults=15&rankBy=10001]. There's nothing you can do about it except switch to a supported browser, or use an alternative tool like [SQL Developer|http://www.oracle.com/technology/products/database/sql_developer/index.html] when working with PL/SQL.

  • SQL agent proxy account for Powershell

    I am trying to use a sql agent proxy account for PowerShell. Created the ad account, credential and the proxy but because the PowerShell accesses a bunch o sql servers it errors out.Even when I created a login for all the sql servers the powershell is trying
    to access it still failed so next I'd need to look at what permissions the powershell ad account needs to the objects it accesses. Is this the correct approach?
    What is the best way to go here and avoid using a sysadmin account to run the sql agent powershell job? Thanks!
    Paula

    Hi,
    Please check the error message in job history for details of job failed.
    Sysadmin is required or not depends on what you want to achieve on the SQL Server. For example, to execute sp_readerrorlog, the login must be a member of the securityadmin role and it is not required sysadmin.
    It does need to create the login(proxy account) on the all the SQL Server instances.
    A SQL Server Agent Proxy defines the security context under which different job steps run. The proxy contains the credentials of a Windows user account that does have access to the resources needed by the job. If you have a proxy specified in a job step, SQL
    Server Agent will impersonate the proxy account and run the job step while impersonating that user account.
    In order to find out the required permission, you may log in with this Windows user account(proxy credential) and run the PowerShell on the local machine and see the result. Alternately, connect in SQL Server Management Studio with this login and see what
    permission is required to execute the script.
    Thanks.
    Tracy Cai
    TechNet Community Support

  • SQL Workshop Script editor in RED..not able to see any code

    Hi,
    I have created a Package in the apex.oracle.com SQL workspace. package got created successfully.
    But when I navigate to Home>SQL Workshop>Object Browser and try to see the package spec/body content..the editor/notepad is completly RED in color.
    any idea what may be the reason??.
    Thanks,
    Deepak

    This is a [long standing problem in some browsers/configurations|http://forums.oracle.com/forums/search.jspa?threadID=&q=%22Script+editor%22+AND+RED&objID=f137&dateRange=all&userID=&numResults=15&rankBy=10001]. There's nothing you can do about it except switch to a supported browser, or use an alternative tool like [SQL Developer|http://www.oracle.com/technology/products/database/sql_developer/index.html] when working with PL/SQL.

  • Alternative function to WM_CONCAT

    Hi,
    I am using eBusiness Suite 11g containing an Oracle financials 10 database. The schema WMSYS is missing and I am unable to use WM_CONCAT function. Are there any other alternative functions or SQL that can help with cross-tabbing comma seperated values to avoid queries returning multiple lines.
    For example:
    JE_HEADER_ID SOURCE INVOICE_NUM DESC PO_NO AMOUNT
    14055 Payables 38761 Paperchase 10145 461.55
    14055 Payables 38761 Paperchase 10148 461.55
    I would like the PO_NO to be concatenated on one line so that the query returns only one line as below:
    JE_HEADER_ID SOURCE INVOICE_NUM DESC PO_NO AMOUNT
    14055 Payables 38761 Paperchase 10145, 10148 461.55
    Your feedback will be appreciated.
    Thanks

    Hi,
    Thanks for your help, rtrim(xmlagg(xmlelement(e,ph.segment1,',').extract('//text()')),',') segment1 seems to work best in eBusiness suite with database version 10. The function LISTAGG works from 11g onwards and STRAGG requires a functions to be created and called within a SQL query.
    All of the above were useful to know.
    Thanks again

  • SetAdditionalJoinExpression and Named Queries...

    Hi, is it possible to use DescriptorQueryManager.setAdditionalJoinExpression() to append additional filters to sql statement named queries?
    I've tried this but it doesn't seem to have any effect. If this is not possible, do you know of any alternative methods?
    Thanks for you help!
    -Tim Watson

    Yes, if you set the DescriptorQueryManager additionalJoinExpression the expression will be anded will all queries for that descriptor.
    Ensure that you set the additionalJoinExpression before you login.

  • Best combination of technologies for Java db-supported web application?

    Hi everyone!
    I was given the task to develop a Java database-supported web application and am now wondering what combination of technologies would best fit my requirements.
    Basically, I am supposed to transform an "Excel-based" application into a Java-based web application that can be run in a browser in our intranet (I know, that's what a web application is supposed to do).
    The Excel application consist of an Excel sheet that holds all the data and a VBA form, that shows and lets you edit all the details/fields of a row and lets you navigate through the rows. Furthermore there are certain macros to filter the data table.
    Now, to transform the application, all data from Excel will be moved to an Oracle relational database and I want to rebuild the functionality with Java.
    Consequently, the Java application is intended to...
    - output the table as is in the browser
    - easily let you filter the data of the table
    - let you create (and save) custom filters
    - show detail view of a row
    - navigate through the rows of the (filtered) table
    - save the data that is entered/edited/deleted in the detail view back to the table in the database
    So, what are the best (and easiest to use) tools and technologies to develop such an application?
    Currently my reasearch has led me to the following conclusions:
    *1.* Architecture: I need a three-tier client-server application, which lead us to using the J2EE platform, right?
    *2.* For the persistence layer I somehow have to map the database table to a Java object,
    - either doing it completely manually (coding) using JDBC
    - or using EJB3 / Java Persistence API / Hibernate to get at least the getters and setters auto-generated, right?
    Please, correct me whenever i got something wrong!
    Oracle JDeveloper supports the mapping process with a wizard when using EJB3 and JPA
    (http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm)
    Is there something comparable available for Eclipse?
    *3.* I'd like to use Java Server Faces for the UI. Besides the reference implementation there are several other implementations with additional components for e.g. displaying tables. There are:
    - Apache MyFaces Trinidad (former ADF Faces, although ADF Faces looks different/has different style sheet than Trinidad?)
    - NetBeans Visual Web tools (which look quite nice in the tutorial, but require the NetBeans IDE, I guess?! Tutorial: http://www.netbeans.org/kb/60/web/web-jpa.html
    *4.* What IDE would you recommend? Should have a WYSIWYG editor for the JSF files and should support me as much as possible as a Java Learner!
    - JDeveloper
    - Eclipse (+Plugins?)
    - NetBeans
    - MyEclipse (only if there is a free version out there, I have read about an Eclipse plug-in, but don't know if that was free...)
    *5.* Do you know some good and easy-to-understand tutorials covering this problem?
    *6.* What other aspects should I think of? Are there certain technologies for the business logic or just normal JavaBeans? What about SessionBeans and ManagedBeans?
    Any help, answers, ideas, explanations, comments, recommendations, will be highly appreciated!
    Cheers,
    Chris

    Thanks paulcw, for your quick reply and helpful comments!
    The whole thing is getting bigger than I thought...
    Actually this is a 1-man-project, that I am supposed to realise for small department during my internship in a big company.
    Maybe a more detailed description of the structure may help you to understand what I actually need.
    The table of concern, is an overview of certain projects inside the company and read-only, as it is a view on another database uniting data relevant for the department.
    Then there is a second table for additional data (specific for the department) for each project. This data has to be entered, modified, deleted with the new application, while the data from the first table is only displayed.
    1) In this case, is AJAX / JavaScript still necessarily needed?
    2) EJB and Hibernate sound like overkill to me as well, but what would be the alternatives? JDBC, SQL queries and rowSets? And are the first mentioned really so hard to use?
    3) Do you have any recommendations on how to solve the multiple access problem (I'm sure, I'm not the only one with this kind of problem...)?
    Thanks to everyone in advance!
    Chris

  • Replication of Prospects from crm to r\3

    hello Experts
    is there any way to stop the replication of prospects from crm to r/3.....
    we are facing a problem with out validating the prospect the prospects are replicating in r/3...
    can u please help me out in this
    thanks in advance
    regards
    sreeram

    Shweta is right about the PIDE setting in R/3, but this does stop only the update in R/3, not the sending of prospects towards R/3.
    To do it correctly, you need to create new subscriptions for the R/3:
    1. Delete the subscription, publication and replication object on BUPA_MAIN in SMOEAC
    2. Create a new intelligent replication object with filter on IS_CUSTOMER with option EQ (which means you want only customers to be replicated). Alternatively you can create a filter on IS_PROSPECT and option NE
    3. You create the appropriate publication and subscription and assign it to the R/3 site
    Now only BP's with the customer flag will get replicated (or those without the prospect flag). The customer flag will get set usually automatically with the customer role or can be manually set in the classification tab of role customer (field BPISCUST), but the prospect flag will stay if you turn the prospect into a customer.
    So you need to make sure that when setting the BPISCUST flag that the BPISPROS flag is unset, when you do the alternative filtering on IS_PROSPECT (manually or in a BADI on customer save).
    Regards, Kai

  • Request: compare and propagate user objects

    After making changes to table definitions, views, program units, and so on, it may be useful to propagate these changes to another database user. This maybe another development environment, or a testing environment in same or another database. Like "Compare user objects" option in PLSQL/Developer.
    /* BEGIN: cut and paste from PLSQL Developer Help */
    Compare User Objects
    After making changes to table definitions, views, program units, and so on, it may be useful to propagate these changes to another database user. This maybe another development environment, or a testing environment. To compare the objects of your development user with another user, you can use the Compare User Objects function in the Tools menu. This will bring up the following dialog:
    On the Selection tab page you can select the objects you wish to compare. After making this selection, you can press the Target Session button, to select the user and database that you want to compare. This will enable the Compare button, which you can press to start the compare operation. You can select the Include storage... option to include the storage information such as tablespace names and initial sizes for new objects. These may differ across databases, so this may not always be appropriate.
    When the compare operation is finished, the dialog will switch to the Differences tab page, which will show a list of all objects that are different:
    This list is sorted in order of dependency. Below the list of different objects of the target user, you see the SQL that needs to be executed to make these objects equal to the corresponding objects of the current user. If no object is selected, the SQL of all objects is displayed. If one or more objects are selected, only the SQL for the selected object(s) is displayed. In the example above, a missing EMP_MGR_EMPNO check constraint was added to the EMP table.
    The Show Differences button will show a visual line-by-line difference of the old and new source file of an object. This can be useful to view the changes made in Program Units, or can help you determine why a specific DDL statement was generated for other object types. The Configure External Difference Tool allows you to configure the difference tool should be used. By default the ExamDiff utility will be used, for which a Pro version is available (See the About item of ExamDiff’s Info menu). See also Tools - Differences.
    You can now press the Apply SQL button to execute this SQL in the target session. You can alternatively save the SQL in a file by pressing the Save SQL button, or you can copy it to the clipboard by pressing the Copy SQL button.
    When objects are compared, the following properties are ignored:
    ·     Storage – Properties such as the next extent and pct free of tables and indexes are not considered relevant for comparison.
    ·     Constraints with system generated names – These constraints will have different names for the 2 users, so they cannot be compared. If a table is new in the target session, these constraints will be generated though.
    ·     Table creation properties – Properties that would require the recreation of the table are ignored.
    ·     Table data – To export table data, use the Export Table function (see Export Tables).
    ·     Sequence values – The current value of a sequence is considered data.
    /* END: cut and paste from PLSQL Developer Help */

    This is on the list but not for 1.0.
    -kris

  • Backup/Recovery from web application

    Hello guys,
    I am using Oracle 9i as DB and Oracle 9iAS for web application server. I want to provide Backup and Recovery functionality to the user via web. I don't know any thing in this regard.
    Is it possible that we can take backup and recovery from web application?
    Is there any alternative for this function.
    any other comments will be appreciated.
    Thank you,
    Jawed Nazar Ali

    Read this article in order to get an idea about Java Stored Procedures.
    Oracle Developer JAVA STORED PROCEDURES
    Simplify with Java Stored Procedures
    By Kuassi Mensah
    Use Java stored procedures to bridge SQL, XML, Java, and J2EE and Web Services.
    Stored procedures allow a clean separation of persistence logic that runs in the database tier from business logic that runs in the middle tier. This separation reduces overall application complexity and increases reuse, security, performance, and scalability.
    A major obstacle, however, for widespread adoption of stored procedures is the set of various proprietary, database-dependent implementation languages that different database vendors use. The use of Java-based stored procedures fixes this concern. Oracle has implemented ANSI standards that specify the ability to invoke static Java methods from SQL as procedures or functions. This implementation is called simply "Java stored procedures."
    In this article, you will learn how Java stored procedures help simplify and increase the performance of your business logic and extend database functionality. I'll show how Oracle enables the use of Java stored procedures within the database. I'll also look at how Java stored procedures access data, and show how to create a basic Java stored procedure.
    PL/SQL or Java
    When you think of Oracle stored procedures, you probably think of PL/SQL. Oracle, however, has provided Java support in the database since Oracle8i, to offer an open and portable alternative to PL/SQL for stored procedures. I can hear the $64,000 question: "How do I choose between PL/SQL and Java? Should I forget all the things I've been told about PL/SQL and move on to the greener Java pastures?"
    Both languages are suitable for database programming, and each has its strengths and weaknesses. In deciding which language to use, here's a general rule of thumb:
    Use PL/SQL for database-centric logic that requires seamless integration with SQL and therefore complete access to database objects, types, and features.
    Use Java as an open alternative to PL/SQL for database independence, but also for integrating and bridging the worlds of SQL, XML, J2EE, and Web services.
    OracleJVM Lets You Run Java within the Database
    Since Oracle8i, Release 1 (Oracle 8.1.5), Oracle has offered a tightly integrated Java virtual machine (JVM) that supports Oracle's database session architecture. Any database session may activate a virtually dedicated JVM during the first Java code invocation; subsequent users then benefit from this already Java-enabled session. In reality, all sessions share the same JVM code and statics—only private states are kept and garbage collected in an individual session space, to provide Java sessions the same session isolation and data integrity capabilities as SQL operations. There is no need for a separate Java-enabled process for data integrity. This session-based architecture provides a small memory footprint and gives OracleJVM the same linear SMP scalability as the Oracle database.
    Creating Java Stored Procedures
    There are a few steps involved in turning a Java method into a Java stored procedure. These include loading the Java class into the database using the loadjava utility, and publishing the Java methods using a call specification (Call Spec) to map Java methods, parameter types, and return types to their SQL counterparts. The following section shows how to do this.
    I'll use a simple Hello class, with one method, Hello.world(), that returns the string "Hello world":
    public class Hello
    public static String world ()
    return "Hello world";
    The Loadjava Utility
    Loadjava is a utility for loading Java source files, Java class files, and Java resource files; verifying bytecodes; and deploying Java classes and JAR files into the database. It is invoked either from the command line or through the loadjava() method contained within the DBMS_JAVA class. To load our Hello.class example, type:
    loadjava -user scott/tiger Hello.class
    As of Oracle9i Release 2, loadjava allows you to automatically publish Java classes as stored procedures by creating the corresponding Call Specs for methods contained in the processed classes. Oracle provides Oracle9i JDeveloper for developing, testing, debugging, and deploying Java stored procedures.
    The Resolver Spec
    The JDK-based JVM looks for and resolves class references within the directories listed in the CLASSPATH. Because Oracle database classes live in the database schema, the OracleJVM uses a database resolver to look for and resolve class references through the schemas listed in the Resolver Spec. Unlike the CLASSPATH, which applies to all classes, the Resolver Spec is applied on a per-class basis. The default resolver looks for classes first in the schema in which the class is loaded and then for classes with public synonyms.
    loadjava -resolve <myclass>
    You may need to specify different resolvers, and you can force resolution to occur when you use loadjava, to determine at deployment time any problems that may occur later at runtime.
    loadjava -resolve -resolver "((* SCOTT) (foo/bar/* OTHERS)
    (* PUBLIC))"
    Call Spec and Stored Procedures Invocation
    To invoke a Java method from SQL (as well as from PL/SQL and JDBC), you must first publish the public static method through a Call Spec, which defines for SQL the arguments the method takes and the SQL types it returns.
    In our example, we'll use SQL*Plus to connect to the database and define a top-level Call Spec for Hello.world():
    SQL> connect scott/tiger
    SQL> create or replace function helloworld return
    VARCHAR2 as language java name 'Hello.world () return
    java.lang.String';
    Function created.
    You can then invoke the Java stored procedure as shown below:
    SQL> variable myString varchar2[20];
    SQL> call helloworld() into :myString;
    Call completed.
    SQL> print myString;
    MYSTRING
    Hello world
    Java stored procedures are callable, through their Call Spec, from SQL DML statements (INSERT, UPDATE, DELETE, SELECT, CALL, EXPLAIN PLAN, LOCK TABLE, and MERGE), PL/SQL blocks, subprograms, and packages, as well as database triggers. The beauty of Call Spec is that stored procedure implementations can change over time from PL/SQL to Java or vice versa, transparently to the requesters.
    Call Spec abstracts the call interface from the implementation language (PL/SQL or Java) and therefore enables sharing business logic between legacy applications and newer Java/J2EE-based applications. At times, however, when invoking a database-resident Java class from a Java client, you may not want to go through the PL/SQL wrapper. In a future release, Oracle plans to provide a mechanism that will allow developers to bypass the Call Spec.
    Advanced Data-Access Control
    Java stored procedures can be used to control and restrict access to Oracle data by allowing users to manipulate the data only through stored procedures that execute under their invoker's privileges while denying access to the table itself. For example, you can disable updates during certain hours or give managers the ability to query salary data but not update it, or log all access and notify a security service.
    Sharing Data Logic Between Legacy and J2EE Applications
    Because legacy applications and J2EE applications both invoke stored procedures through the Call Spec, the same data logic can be shared between J2EE and non-J2EE worlds. Thanks to Call Spec, this data logic can be shared regardless of the implementation language used (whether PL/SQL or Java).
    Autogeneration of Primary Keys for BMP Entity Beans
    When using BMP for EJB entity beans, a bean instance can be uniquely identified by the auto-generated primary key associated with the newly inserted data as a return value for ejbCreate(). You can retrieve this value within ejbCreate() in one database operation by using a stored procedure that inserts the corresponding data and retrieves or computes the primary key. Alternatively, you could insert the data and retrieve the corresponding key (or ROWID) in one SQL statement, using the RETURN_GENERATED_KEYS feature in JDBC 3.0. However, the stored procedure approach is more portable across JDBC driver versions and databases.
    You can implement this pattern with these three steps:
    Create the Java stored procedure, defining a public static Java method insertAccount() within a public GenPK class. This method will insert data, compute a unique key (by passing out a sequence number), and return the computed key as primary key.
    Define the Call Spec.
    CREATE OR REPLACE PROCEDURE insertAccount(owner IN
    varchar, bal IN number, newid OUT number)
    AS LANGUAGE JAVA NAME 'GenPK.insertAccount(
    java.lang.String [])';
    Invoke the stored procedure within ejbCreate().
    Public AccountPK ejbCreate(String ownerName, int balance) throws CreateException
    try {
    CallableStatement call = conn.prepareCall{
    "{call insertAccount(?, ?, ?)}"};          
    return new AccountPK(accountID);
    Custom Primary Key Finders for CMP Entity Beans
    Finder methods are used for retrieving existing EJB entity bean instances. Primary key finders allow you to retrieve a uniquely identified EJB instance. For CMP entity beans, the EJB container automatically generates the primary key finder findByPrimaryKey() method, based on declarative description. In some situations, however, you might need more control; for example, you may need a specialized finder such as findByStoredProcKey(). In these situations, you can use Java stored procedures in conjunction with an object relational framework (such as Oracle9i Application Server [Oracle9iAS] TopLink) to implement a custom primary key finder method. After you define the EJB finder as a REDIRECT or NAMED finder, TopLink will generate the SQL query for retrieving the bean instance.
    Data-Driven EJB Invocation
    In a data-driven architecture, business logic invocation can be triggered as a result of database operations (such as inserts, updates, or deletes). A Java stored procedure implementing the data logic can be declared as a database trigger to invoke EJBs running in a middle-tier J2EE application server. You can make EJB calls by using either standard remote method invocation (RMI) over Interoperable Inter-ORB Protocol (IIOP), using a J2EE 1.3 compatible server, or RMI over a vendor-specific transport protocol (such as ORMI with Oracle9iAS/OC4J or RMI over T3 with BEA WebLogic). Each application server vendor has its own optimized protocol while providing RMI over IIOP for interoperability. Oracle9iAS supports both RMI calls over IIOP and ORMI protocols.
    Data-Driven Messaging
    Oracle9i Database embeds Advanced Queuing (AQ), which is an integrated, persistent, reliable, secure, scalable, and transactional message-queuing framework. Oracle exposes AQ features to Java developers through the standard Java Messaging System (JMS) API. Java stored procedures can invoke AQ operations through the JMS interface to allow fast, intra-session, scalable, data-driven messaging.
    Java stored procedures can use JMS to invoke AQ operations. You can implement this pattern in four steps:
    Create and start the JMS Queue (to do so, embed the following operations within a SQL script):
    execute dbms_aqadm.create_queue_table(queue_table =>
    'queue1', queue_payload_type =>
    'SYS.AQ$_JMS_TEXT_MESSAGE', comment => 'a test queue',
    multiple_consumers => false, compatible => '8.1.0');
    execute dbms_aqadm.create_queue( queue_name => 'queue1',
    queue_table => 'queue1' );
    execute dbms_aqadm.start_queue(queue_name => 'queue1');
    Create the Java stored procedure (a code snippet is shown):
    public static void runTest(String msgBody)
    try
    // get database connection
    ora_drv = new OracleDriver();
    db_conn = ora_drv.defaultConnection();
    // setup sender (cf online code sample)
    // create message
    s_msg = s_session.createTextMessage(msgBody);
    // send message
    sender.send(s_msg);
    s_session.commit();
    // receive message
    r_msg = (TextMessage) receiver.receive();
    r_session.commit();
    // output message text
    String body = r_msg.getText();
    System.out.println("message was '"+body+"'");
    Create the Call Spec:
    create or replace procedure jmsproc (t1 IN VARCHAR)
    as language java name 'jmsSample.main (java.lang.String[])';
    Invoke the stored procedure:
    call jmsproc('hello');
    Database-Assisted Web Publishing (Cache Invalidation)
    One of the common issues application architects must face is how to cache database information reliably to increase overall system performance. JCACHE is an upcoming standard specification (JSR 107) that addresses this problem. It specifies an approach for temporary, in-memory caching of Java objects, including object creation, shared access, spooling, invalidation, and consistency across JVMs. It can be used to cache read-mostly data such as product catalogs and price lists within JSP. Using JCACHE, most queries will have response times an order of magnitude faster because of cached data (in-house testing showed response times about 15 times faster).
    In order to track all the changes to the origin data and refresh the cached data, a Java stored procedure is attached to a table as a trigger. Any change to this table will result in the automatic invocation of this stored procedure, which in turn will call out a defined JSP to invalidate the JCACHE object that maps its state to the database table. Upon invalidation, the very next query will force the cache to be refreshed from the database. Next Steps
    READ MORE about Java Stored Procedures
    This article is adapted from the white paper "Unleash the Power of Java Stored Procedures." You can find the white paper at:
    /tech/java/java_db/pdf/
    OW_30820_JAVA_STORED_PROC_paper.PDF
    New PL/SQL features in Oracle9i Database, Release 2
    /tech/pl_sql/pdf/
    Paper_30720_Doc.pdf
    Resolver Spec
    /docs/products/oracle9i/
    doc_library/release2/java.920/a96659.pdf
    OracleJVM and Java 2 Security
    /docs/products/oracle9i/
    doc_library/release2/java.920/a96656.pdf
    DOWNLOAD Code
    Exercise code examples from this article:
    /sample_code/tech/
    java/jsp/Oracle9iJSPSamples.html
    LEARN about stored procedures as Web services
    /tech/webservices
    Extending Database Functionality
    One of the great things about running Java code directly in the database is the ability to implement new functionality by simply loading the code or library and using the Call Spec to make the entry points (public static methods) available to SQL, PL/SQL, Java, J2EE, and non-Java APIs. Oracle9i Database customers can easily extend database functionality. Oracle itself leverages this capability for new utilities and packages such as the XML Developer Kits (XDKs).
    Bridging SQL, PL/SQL, Java, J2EE, .NET, and XML
    The Oracle XDK is written in Java and exposes its public methods as Java stored procedures, extending the database's XML programmability. SQL, PL/SQL, Java, J2EE, and non-Java (.NET) business logic all have access to the XML parser, the XSLT processor, the XPath engine, and XML SQL Utility (XSU).
    The XML parser is accessible through the xmlparser and xmldom packages. XSU is a Java utility that generates an XML document from SQL queries or a JDBC ResultSet, and writes data from an XML document into a database table or view. Using XSU, XML output can be produced as Text, DOM trees, or DTDs. XSU is exposed to PL/SQL through the dbms_xmlquery and dbms_xmlsave packages.
    Conclusion
    The integration of the Oracle database with a Java VM enables the creation of portable, powerful, database-independent data logic and persistence logic. The loose coupling of business logic that runs in the middle tier with data logic that runs in the database tier improves application scalability, performance, flexibility, and maintenance.
    Kuassi Mensah ([email protected]) is a product manager in the Server Technologies division at Oracle.
    http://otn.oracle.com/oramag/oracle/03-jan/o13java.html
    Joel Pérez

  • Best approach to join multiple statistics tables into one

    I have read different approaches to join multiple statistics tables into one, they all have a column "productobjectid".
    I want to get all data for each product and put it to excel and output a jpg statistic with cfchart.
    How would you do this, the sql part?
    Thanks.

    A couple suggestions:
    1) when joining tables, its best to list both table/fields that you are joining in the FROM clause:
    FROM shopproductbehaviour_views INNER JOIN shopproductbehaviour_sails ON shopproductbehaviour_views.productobjectid = shopproductbehaviour_sails.productobjectid
    2) You add tables to a SQL join by placing another join statement after the SQL above:
    SELECT *
    FROM TableA INNER JOIN TableB on TableA.myField = TableB.myField
    INNER JOIN TableC on TableA.anotherField = TableC.anotherField
    3) If you have columns in the tables that are named the same, you can use column aliases to change the way they appear in your record set:
    SELECT TableA.datetimecreated 'tablea_create_date', TableB.datetimecreated 'tableb_create_date'
    4) Certainly not a requirement, but you might want to look into using <cfqueryparam> in your where clause:
    WHERE shopproductbehaviour_sails.productobjectid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#all.productobjectid#">
     You might want to consider checking out one of the many tutorials on SQL available online.  Many of the questions you posed in your post are covered in pretty much every basic SQL tutorial.  Alternately, a good SQL book is worth its weight in gold for a beginning web applications developer.

  • Different output XMLTRANSFORM and XMLTYPE.TRANSFORM

    Hi,
    we upgrade from 10gR2 to 11gR2 and still have problems with XML transformation. Under unknown circumstances the XMLTRANSFORM function
    fails with "LPX-00660: Not a well-formed document or external entity" when the count of Page elements is greater then one.
    It seems, this bug isnt fixed in 11gR2...
    SET SCAN OFF
    DECLARE
      xml     XMLTYPE := XMLTYPE('<?xml version="1.0" encoding="iso-8859-1"?>
    <FILE>
      <DOCUMENT>
        <PAGE>
          <b101f>Hello</b101f>
          <b101>World</b101>
          <f101/>
          <REGARDS/>
        </PAGE>
      </DOCUMENT>
      <DOCUMENT>
        <PAGE>
          <list_layout xpos="10" lsign="+"/>
          <le>May</le>
          <le>the</le>
          <le stil="f">force</le>
          <le>be</le>
          <le>with</le>
          <le>you</le>
          <f101/>
          <REGARDS/>
        </PAGE>
      </DOCUMENT>
    </FILE>
      xsl     XMLTYPE := XMLTYPE('<?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="FILE">
        <FILE>
          <xsl:apply-templates/>
        </FILE>
      </xsl:template>
      <xsl:template match="DOCUMENT">
        <DOCUMENT>
          <xsl:apply-templates/>
        </DOCUMENT>
      </xsl:template>
      <xsl:template match="PAGE">
        <PAGE>
          <CONTENT>
            <xsl:apply-templates/>
          </CONTENT>
        </PAGE>
      </xsl:template>
      <xsl:template match="REGARDS">
        <xsl:text disable-output-escaping="yes">&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</xsl:text>
      </xsl:template>
    </xsl:stylesheet>
      buf   VARCHAR2(32767 CHAR);
    BEGIN
      DBMS_OUTPUT.PUT_LINE(xml.transform(xsl).getClobVal());
      SELECT  xmltransform(xml, xsl).getStringVal()
      INTO    buf
      FROM    dual;
      DBMS_OUTPUT.PUT_LINE(buf);
    END;
    /Oracle Docu: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb08tra.htm
    XMLType instance can be transformed in the following ways:
    Using Oracle SQL function XMLtransform or XMLType method transform() in the database.
    Using Oracle XML Developer's Kit transformation options in the middle tier, such as XSLT Processor for Java.
    You can alternatively use XMLType method transform() as an alternative to Oracle SQL function XMLtransform. It has the same functionality.
    Output:
    <FILE>
    <DOCUMENT>
    <PAGE>
    <CONTENT>
    <b101f>Hello</b101f>
    <b101>World</b101>
    <f101/>&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</CONTENT>
    </PAGE>
    </DOCUMENT>
    <DOCUMENT>
    <PAGE>
    <CONTENT>
    <list_layout xpos="10" lsign="+"/>
    <le>May</le>
    <le>the</le>
    <le stil="f">force</le>
    <le>be</le>
    <le>with</le>
    <le>you</le>
    <f101/>&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</CONTENT>
    </PAGE>
    </DOCUMENT>
    </FILE>
    <FILE><DOCUMENT><PAGE><CONTENT><b101f>Hello</b101f><b101>World</b101><f101></f101><b101>Best regards</b101></CONTENT></PAGE></DOCUMENT><DOCUMENT><PAGE><CONTENT><list_layout xpos="10" lsign="+"></list_layout><le>May</le><le>the</le><le stil="f">force</le><le>be</le><le>with</le><le>you</le><f101></f101><b101>Best regards</b101></CONTENT></PAGE></DOCUMENT></FILE>

    Hi,
    we upgrade from 10gR2 to 11gR2 and still have problems with XML transformation. Under unknown circumstances the XMLTRANSFORM function
    fails with "LPX-00660: Not a well-formed document or external entity" when the count of Page elements is greater then one.
    It seems, this bug isnt fixed in 11gR2...
    SET SCAN OFF
    DECLARE
      xml     XMLTYPE := XMLTYPE('<?xml version="1.0" encoding="iso-8859-1"?>
    <FILE>
      <DOCUMENT>
        <PAGE>
          <b101f>Hello</b101f>
          <b101>World</b101>
          <f101/>
          <REGARDS/>
        </PAGE>
      </DOCUMENT>
      <DOCUMENT>
        <PAGE>
          <list_layout xpos="10" lsign="+"/>
          <le>May</le>
          <le>the</le>
          <le stil="f">force</le>
          <le>be</le>
          <le>with</le>
          <le>you</le>
          <f101/>
          <REGARDS/>
        </PAGE>
      </DOCUMENT>
    </FILE>
      xsl     XMLTYPE := XMLTYPE('<?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="FILE">
        <FILE>
          <xsl:apply-templates/>
        </FILE>
      </xsl:template>
      <xsl:template match="DOCUMENT">
        <DOCUMENT>
          <xsl:apply-templates/>
        </DOCUMENT>
      </xsl:template>
      <xsl:template match="PAGE">
        <PAGE>
          <CONTENT>
            <xsl:apply-templates/>
          </CONTENT>
        </PAGE>
      </xsl:template>
      <xsl:template match="REGARDS">
        <xsl:text disable-output-escaping="yes">&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</xsl:text>
      </xsl:template>
    </xsl:stylesheet>
      buf   VARCHAR2(32767 CHAR);
    BEGIN
      DBMS_OUTPUT.PUT_LINE(xml.transform(xsl).getClobVal());
      SELECT  xmltransform(xml, xsl).getStringVal()
      INTO    buf
      FROM    dual;
      DBMS_OUTPUT.PUT_LINE(buf);
    END;
    /Oracle Docu: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb08tra.htm
    XMLType instance can be transformed in the following ways:
    Using Oracle SQL function XMLtransform or XMLType method transform() in the database.
    Using Oracle XML Developer's Kit transformation options in the middle tier, such as XSLT Processor for Java.
    You can alternatively use XMLType method transform() as an alternative to Oracle SQL function XMLtransform. It has the same functionality.
    Output:
    <FILE>
    <DOCUMENT>
    <PAGE>
    <CONTENT>
    <b101f>Hello</b101f>
    <b101>World</b101>
    <f101/>&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</CONTENT>
    </PAGE>
    </DOCUMENT>
    <DOCUMENT>
    <PAGE>
    <CONTENT>
    <list_layout xpos="10" lsign="+"/>
    <le>May</le>
    <le>the</le>
    <le stil="f">force</le>
    <le>be</le>
    <le>with</le>
    <le>you</le>
    <f101/>&#38;lt;lt;b101&#38;lt;gt;Best regards&#38;lt;lt;/b101&#38;lt;gt;</CONTENT>
    </PAGE>
    </DOCUMENT>
    </FILE>
    <FILE><DOCUMENT><PAGE><CONTENT><b101f>Hello</b101f><b101>World</b101><f101></f101><b101>Best regards</b101></CONTENT></PAGE></DOCUMENT><DOCUMENT><PAGE><CONTENT><list_layout xpos="10" lsign="+"></list_layout><le>May</le><le>the</le><le stil="f">force</le><le>be</le><le>with</le><le>you</le><f101></f101><b101>Best regards</b101></CONTENT></PAGE></DOCUMENT></FILE>

Maybe you are looking for

  • ALV Report Prob with Sys Status & Totl Planned Costs

    Hi, Ive dev the report. now ive a few chages on report. I need to add this three frields in my report. For the getting the system status. For Each works Order find the recors in the table JEST. JEST-OBJNR = AUFK-OBJNR AND JEST-STAT <> 'X' AND CHARG =

  • How to resolve a windows authenticated orphaned user in Sql Server 2008 R2?

    Hi,  We have some orphaned windows authenticated  users(domain) in the database while it had been migrated from Sql Server 2005 to Sql Server 2008 R2, because there are no corresponding logins for the users. Will just adding the logins would be suffi

  • Error codes 3014, 14, 11 while updating to iOS 5

    Ok, I realize that the apple servers are down for updating to iOS 5.  My problem is the fact that I cant even restore my iphone without getting at least 1 error code.  The error codes are  3014,14 and 11.  I have googled all 3 of these to find any ty

  • Cannot browse through bookstore by title

    I cannot browse through the bookstore by book title. I only see an author list, which is not really usefull. Untl now, I haven't found a function how to switch between author and title view. I own a iPhone 4S with the latest iOS version. On my iPad I

  • Dynamic selection screen for FDK43

    HI All, I need to add a field (accounting clerk - BUSAB)in the dynamic selection-screen  of transaction FDK43. I used se36 to view the current selection-screen view and it does show me the field accouting clerk under functional group  - 04  (Company