Query specific data from the ORACLE database

Source: Internet
Author: User


Query specific data from an ORACLE database. If you want to query the name and field name of a table with a specific value from an oracle database, you cannot manually view the number of tables in the database one by one, at this time, it is necessary to write plsql to make the database query by itself. Here I wrote a plsql statement to query the name and field of the data table whose value is "57d486c2: 1385142d983:" in the database. Www.2cto.com SQL code -- query the table name and field name declare str varchar2 (100): = '57d486c2: 1385142d983: 'In the user table of the oracle database :'; sqlstr varchar2 (4000); tablename varchar2 (50); columnname varchar2 (50); cursor selectSqlCur is select table_name, column_name from region where data_type = 'varchar2'; begin open selectSqlCur; fetch selectSqlCur into tablename, columnname; while selectSqlCur % found loop sqlstr: = 'declar E '| 'scount number (10);' | 'in in select count (*) into scount from '| tablename | 'where' | columnname |' = ''' | str | '''; '| 'if scount! = 0 then' | 'dbms _ output. put_line (''' | tablename | '. '| columnname | ''');' | 'end if; '| 'end;'; -- print the SQL statement -- dbms_output.put_line (sqlstr ); -- execute the SQL statement execute immediate sqlstr; fetch selectSqlCur into tablename, columnname; end loop; end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.