Programming and learning SQL is divided into three parts, which covers the basics of SQL standards. In the last article we discussed some database terminology and 4 basic data Query types. In addition, we explain the use of WHERE clauses and conditional statements, and we provide specific examples of various types of queries.
In this article, we will explain so
Here's how to implement a Dynamic FAQ (FAQ and Answer) Web site with SQL Server.
First, create a database FAQ, where the table FAQs has a field ID (int, autoincrement, and set as the primary key), subject (VARCHAR,200), Answers (text). This table can contain some common questions and answers about programming knowledge. Then, add system DSN to the ODBC DataSource module in Control Panel, name the FAQ, and p
=spno;End-----3. How to call in Java---1. Create CallableStatement CS =ct.preparecall ([Call Sp_pro9 (?,?)]);----Cs.setint (1,10);----Cs.registeroutparameter (2,oracle.jdbc.oracletypes.cursor);--run--cs.execute ();--Get the result set/*resultset rs= (ResultSet) Cs.getobject (2);while (Rs.next ()) {....}*/---------------------Exception Handling---------Case_not_foundData_not_foundCursor_already_openDup_val_on_index Unique index repeatedInvaild_cursor run operation on an illegal cursor for example
='Java Logic'
the
-
in Select @score=Studentresult fromResultwhereStudentno=@stuno andSubjectno=@subno
the Print 'The 20012java results are:'+Convert(varchar( -),@score)
the Go
About
the
the --If-else
the --Query the account number for Java logic
+ Declare @subno int,@date datetime,@avg decimal(5,2)
- Set @date='2013-2-17' --Time
the Select @subno=Subjectno fromSubjectwhereSubjectname='Java Logic'
Bayi Print @subno
the --check the average score for 2013-2-17java exams
the Sele
later found that it is not at all, and that the error Dup_val_on_index, his book is also wrong.Here is an anonymous blockDate.sqlDECLARE l_date date;BEGIN l_date: = SYSDATE-5; Dbms_output. Put_Line (l_date); end;/I still don't know how to call that process, although I tried it before, but I didn't remember it.I'm going to try to write a call on my own, I write a process for printing time, and then call it in an anonymous block.Get_date.sqlCREATE OR REPLACE PROCEDURE get_date (num_in in number)
SQL must knowLesson two: Retrieving data 1. Paging(1), SQL Server chestnuts: Select top 2 columns from TableName(2), Oracle chestnut: SELECT * from TableName ROWNUM (3), Mysql chestnut: selct * from TableName limit 5Precautions:1, MySQL paging if you want to query No. 0 start Query 10 Chestnut select * FROM tableName limit offset 0 Simplified version is commonly used limit 0,10 where "0" represents the off
', 87);INSERT into xs_kc_543 values (' 061204 ', ' 101 ', 91);INSERT into xs_kc_543 values (' 061210 ', ' 101 ', 76);CommitDeclareV_xh Xs_kc_543.xh%type;V_kch Xs_kc_543.kch%type;V_CJ Xs_kc_543.cj%type;Rank char (2);Beginv_xh:=v_xh;v_kch:=v_kch;Select CJ into V_CJ from xs_kc_543 where Xh=v_xh and kch=v_kch;Case V_CJ/10--The last time this place went wrong.When 9 then rank:= ' a ';When 8 then rank:= ' B ';When 7 then rank:= ' C ';When 6 then rank:= ' d ';When 5 then rank:= ' E ';End case;Dbms_out
of space, greater than 255 bytes required 2 bytes of space. So the maximum amount of space for varchar (10) is 11 bytes, with 1 bytes to hold the character length.7.BINARY and varbinary: similar to char and varchar, binary and varbinary store binary strings, rather than character strings, which do not have the concept of a character set, sorting and comparison by binary values. N in BINARY (n) and varbinary (n) all represent byte lengths. The binary padding character is 0x00, and the char paddi
the value 1, just set the Sql_mode parameter:SET Sql_mode='no_unsigned_subtraction ';Try not to use data that the Unsigned,int type may not hold, and int UNSIGNED may not be able to store it, so it is better to promote the int type to the bigint type in the database design phase.2, ZerofillIs like a displayed property.ALTER TABLE COLUMN int (4) UNSIGNED Zerofill;After the column A has been modified, the data for the T-table is searched, and a different display appears:SELECT from 0001B:2You c
Tags: alt and share date where IMG database PNG linked listFirst, the topic gives the database table Require that SQL statements be written to form the following table Workaround: SELECT t1. RQ,T1, T2. Negative from//T1 and T2 are the names of the new forms of their own lives (Select Rq,count (*) as wins//as means that the output is named "Win"From TestTableWHERE shengfu= ' wins 'GROUP by Rq) T1 INNER JOIN//inner jion ... On linked list query (SELE
Loop structure:1, Loop loop structureGrammar:LOOPThe statement to execute;Exit when END LOOP;Example: An integer that loops out 1-10DECLARE Number: = 1; BEGIN LOOP dbms_output.put_line (v_num); V_num:=+1; EXIT when Ten ; END LOOP; END;The drawback of loop structure: The structure is not clear enough, exit easy to write.2. While loop structureGrammar:While The statement to execute;END LOOP;Example: Displaying an integer of 1-10;DECLARE Number: = 1; B
Label: 1Create or replace procedure Pr_mytest is
2
3
4
5V_test Number (8) :=123;
6V_char VARCHAR2 (Ten):='Database';
7C_CHANGL Constant Number ( A,2) :=3.14;
8V_BM t_hq_ryxx.bum%type; 9Type Ty_ry isRecord--a record type in a composite type that defines a new record typeTen (
OneV_XINGM t_hq_ryxx.xingm%type, AV_XINGB t_hq_ryxx.xingb%type, -V_gongz Number (Ten,2)
- ); the
-V_ry Ty_ry; --variables that declare this type of record -
-V_ryrow T_hq_ryxx%rowtype; --all fields of the table +
Local variable local variables must begin with @ and must be described with the DECLARE command before they can be used. Use the Select or SET command to set the value of the variable. Description form:DECLARE @ variable name variable type [@ variable name variable type]SELECT @ local variable = variable value SET @ local variable = variable value IF ... ELSE ...IF [ELSE IF [conditional expression] BEGIN ... END ...BEGIN END BEGIN ... END is used to set a program block tha
match.Then I wrote an example:CREATE OR REPLACE PROCEDURE give_bonus (emp_no_id in number, bonus in number) AUTHID Current_userisbegin dbms_output.Put_Line (emp_no_id); Dbms_output. Put_Line (bonus); END give_bonus;/This is followed by the use of the case expressiondeclarel_salnumber; beginselectsalintol_salfromemp whereempno=7839;dbms_output. Put_Line (l_sal); give_bonus (7839, CASE whenl_sal>=1000andl_salSo it's actually an expression, and then the expression gets a result.After the introduct
decimal point --String intercept SUBSTRINGSelect substring (' ABCDEFG ', 2, 3);Intercept 3 bits starting from 2nd, index starting from 1 3. Time-Date function: --Get current system time GetDate ()Select GETDATE (); Sysdatetime () Gets the timestamp of the database service --Get Month daySelect year (' 1999-1-1 '); --Determine if the date is correct, isdate return bitSelect IsDate (' 2000-2-31 ') returns the bit type, False is 0,true is 1 --Add Time DateAddSelect DATEADD (year,5, ' 2000-1-1 ');A
numbers for the result rows of a query. You can specify RANK, Dense_rank, and Row_number.The USING clause is equivalent to a joins condition where each column from the left table is compared to a column with the Same name in the right table.? The use of recursive common table expressions and recursive views.If you want to keep duplicates in the result of a Union, specify union all instead of just union.Data Retrieval Errors/sqlcodecan use a select-statement within an INSERT statement to insert
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.